LaTeX templates
The set of templates on which I base most of my LaTeX writings. Includes compilation script, plus some nice to have tips :-) #latex #template #cv #letter #article #report #tikz #standalone [Source code]
Currently, there exist eight templates, briefly described below. For each, there is a compilation script. Each comes in its own folder, wherein you can also find its .tex
source code, and sample .pdf
file.
For customising styles and whatnot, some of the templates come with some packages pre-loaded; they should all be included in a (relatively) recent installation of TeXLive. However, they can be safely commented out—the aspect of the document (fonts, etc.) will change, but that should be it.
Article: for writing papers. Example PDF.
Bare: for writing small documents (think loose notes or remarks on something…). Example PDF.
Curriculum Vitæ: for writing your résumé. Here is a sample.
Essay: for writing, well, essays (mine come in English and Portuguese). If you visit either of those links, you will see that some of the texts are not PDFs, but rather HTML pages. However, for some things I prefer to write using LaTeX—and hence this template. It actually uses LaTeX’s
article
class, but with some modifications, such as centred (and numberless) titles, modified table of contents’ template, etc. Do checkout the example PDF, or this essay on the philosophy of science, which I transcribed using this template.Letter: for good old “snail mail” (a.k.a. letters that you print on actual paper). However, should you have, say, a digital image of your handwritten signature, the template for you to place it in the letter, below the “Yours sincerely,” line: just replace the
\theend
command with\theendcs
. Now how cool is that? :-) Example PDF.Presentation: for making slides. I tend to focus on simplicity, because I want my audience’s attention on what I am saying, rather than on the slides they are watching. Here is the example PDF.
Report: based on LaTeX’s
report
class, this is what I use to keep my own notes on whatever the issue that requires taking notes. For example documents, take a look at some of the documents listed here. Or check out the example PDF.Standalone: for things like TikZ images. Example PDF.
A note on fonts. All of these templates assume you have installed the font that I use, Charis SIL. A simple way to do that, is to dump these four files into folder $TEXMFHOME/fonts/truetype
(create any folders that don’t already exist).1 See this for more information. A simpler alternative to just get you going, is simply to comment out the code that deals with the font setup: the documents should compile just fine, albeit with an uglier look…
A note on bibliography. The article
, essay
and report
templates use the citation engine bibulous
, together with a custom reference style, that I placed in a file named sane.bst
. Again you have two choices. The simplest—and ugliest—one, is to replace bibulous
with bibtex
in the compile script, and replace \bibliographystyle{sane}
with \bibliographystyle{plainnat}
or whatever.
The not so simple—but prettier—option, is to download the bibulous
Python script, place it somewhere on your path, then download the sane.bst
file, and place it in $TEXMFHOME/bibtex/bst/
(create any folders that don’t already exist).2 Again, see this for more information.
A note on notes. All templates except cv
and standalone
, offer the \nn
command—the purpose of which, is to produce an annotation. For bare
, letter
and presentation
, this will always be a (non-hyperlinked) footnote. For article
, essay
and reports
, the \nn
command will, by default, produce a hyperlinked endnote, using Arabic numbering. In addition, a \fn
command is also provided, to create (Roman numbered, non-hyperlinked) footnotes. The reason for this, is that although mixing footnotes and endnotes in the same document is very poor style, there is a compelling reason to do so (temporarily) for report
s (see the relevant section below for more details). And since I was providing footnotes for one template that uses endnotes, I decided to provide it also for the other two templates that also use endnotes, viz., article
and essay
.
Furthermore, all three templates also provided an easy way to convert all \nn
notes to footnotes. The rationale is as follows:
On the one hand, footnotes, even when hyperlinked, may not fit entirely into one page bottom, which will force the user to manually scroll onto the bottom of the next page—defeating the purpose of hyperlinking. Endnotes do not suffer of this predicament, which is why I prefer them—for reading stuff on screens.
On the other hand, when reading documents printed on paper, footnotes are way better, because endnotes force the reader to move back and forth, from the Notes chapter/section (usually at the end of the document) to the location the user is currently reading. Hence, these three templates allow you to make
\nn
yield footnotes instead of endnotes: instyle.tex
, comment the\footnotesonlyfalse
line, and uncomment the\footnotesonlytrue
. Thus you will obtain a document containing only footnotes.
Doing the reverse of what is stated in the last bullet point above—i.e., uncommenting the \footnotesonlyfalse
line, and commenting the \footnotesonlytrue
line—gets back the original scheme: \nn
yields an endnote, and \fn
a footnote.
Compiler script
Each of the templates comes with its own compile script (always named CompileTeX.sh
). When invoked without any arguments, they just compile the LaTeX source once. But they all take options to do other things. The one with most options is the compile script for reports, for which all the options described below are implemented.
Variables that the user can set. Before that, though, one more thing needs to be explained, viz. the variables that are user-settable—and that affect the work of some of the options below. (Note that not all the compilation scripts contain all variables. For example, the folders_to_be_rsyncd
exists only in the compilation script for the reports template.)
do_bib
: if set totrue
, build bibliography. If set tofalse
, bibliography is skipped.do_idx
: exactly the same, but for building the index.finalname
: the name of the document produced when compiling with thefinal
option. Must not include extension (i.e, it must not end with.pdf
).folders_to_be_rsyncd
: if you have.tex
files in their own folders, such as chapters or images, then those folders need to be listed here. This is because the folder structure must be replicated inside thebuild/
directory, so the script needs to know which folders to replicate.verbose
: If set tofalse
, suppresses the output of bibliography and index building commands. Set to any other value – e.g.true
– to show said commands’ output.
Compiler options. OK, with that out of the way, let us go now the actual options that the compile script actually accepts.
big
: do a “big compile”, which consists of LaTeX compile, bibliography compile, followed by two further LaTeX compiles. After that, it may do another compilation run, if it detects things like undefined references or something similar.clean
: wipe out the contents of thebuild/
directory, except any.pdf
files. Also rebuilds the subfolder structure, if any. Finally, rebuild symlinks.debug
: do a simple compile, but showing debug output. Needless to say, very helpful in tracking down errors…double
: do a simple compile, twice. Useful to update things like endnotes, or the table of contents, etc.final
: build a “final” version of the document, using the name set in thefinalname
variable above. It is a basically a full version where nothing is skipped, and things like\includeonly
are ignored, just like what you would expect in a final version.subdirs
: update (i.e., redo) the folder structure inside thebuild/
folder, so as to reflect the current value of variablefolders_to_be_rsyncd
.symlinks
: both the*.pdf
and.synctex.gz
(used to click a place in the.pdf
document and go to the corresponding place in the.tex
file, or vice-versa) are created in thebuild/
directory, but it is convenient to have them in the same location of the main.tex
file. Also, the.bib
is in this latter location, but BiBTeX requires it in thebuild/
directory. Both things are accomplished with symbolic links—and invoking the compile script with thesymlinks
option takes care it.warnings
: while thedebug
option dumps any and all output of the LaTeX compiler, running the compile script (CompileTeX.sh
) without any option, yields no output, except whether the compile process succeeded or failed. Running said script with thewarnings
option shows any warning produced by the LaTeX compiler.
As mentioned before, the compile script for reports accepts all of the above options. For the compile scripts of the other templates, the list below says which of the above options are available for which templates. (Remember that for all templates, running CompileTeX.sh
without arguments compiles the .tex
source just once).
Article:
big
,clean
,debug
,final
,symlinks
,warnings
.Bare:
clean
,debug
,final
,symlinks
,warnings
.Curriculum Vitæ:
clean
,debug
,final
,symlinks
,warnings
.Essay: big,
clean
,debug
,double
,final
,symlinks
,warnings
.Letter:
clean
,debug
,final
,symlinks
,warnings
.Presentation:
clean
,debug
,final
,symlinks
,warnings
.
If this seems too much to memorise (and if you use bash
) see below for a way to ease the burden.
Reports only: mixing footnotes and endnotes
In line with was discussed above, the \nn
command for report
produces an endnote. However, as I explain in more detail here, I recommend, for starred (unnumbered) chapters only, to use footnotes, and only convert them to endnotes once a final draft is obtained (i.e., once one is reasonably sure that no more notes will be added or removed). This is the reason why the reports
template defines an \fn
command (cf. first link in current paragraph). Again in line with what was stated above, these footnotes will use Roman numerals, and will not be hyperlinked (ibid.). Once one has a final draft, and has added the code to deal with endnotes in starred chapters (cf. the second link in the current paragraph), then the command \endnotesStarredFinaltrue
will ensure that all those footnotes in the starred chapters are converted to endnotes (see the comments in the style.tex
file).
Optional: bash
completion
If you use the bash
shell, then you get the compilation script to autocomplete the options, by taking the following snippet, placing in a script with the .sh
extension, and source
’ng it in ~/.bashrc
:
_CompileTeX()
{
if [[ $COMP_CWORD -eq 1 ]]; then
WORDS="big clean debug double final subdirs symlinks warnings"
fi
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$WORDS" -- $cur) )
}
complete -F _CompileTeX CompileTeX ./CompileTeX.sh
Optional: helper script
To start a new document, you copy the folder that contains the template you want, and then proceed to edit the files in that copy. To avoid that copying process becoming cumbersome, here’s a little helper (change the template location accordingly):
#! /bin/bash
if [[ -z "$1" ]]; then
echo "Missing source directory name..."
exit 1
fi
if [[ -z "$2" ]]; then
echo "Missing target directory name..."
exit 1
fi
cp -r ~/path/to/your/LaTeX/templates/"$1" "$2"
I usually place this in a file named cptex.sh
, and add an alias to it in ~/.bashrc
(don’t forget to source the latter file afterwards):
alias cptex="sh ~/path/to/script/cptex.sh"
It is also very useful to have bash
completion for this. Fear not: use the same trick above, i.e., put the following in some script, and then source it in ~/.bashrc
:
_cptex()
{
if [[ $COMP_CWORD -eq 1 ]]; then
WORDS="article bare cv essay letter presentation report standalone"
fi
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$WORDS" -- $cur) )
}
complete -F _cptex cptex ./cptex.sh
That’s it. Hopefully the tasks involving LaTeX can now become a little bit less annoying.
October 3, 2022.
Changelog
November 25, 2022. article
, essays
, and reports
now have both an \fn
command, for footnotes, and an \nn
command, that produces endnotes, but that can be swiftly changed to produce footnotes as well (yielding a document that uses only footnotes).
April 6, 2023. reports
no longer maintain an unabridged copy. Too much stuff gets stale (i.e., out-of-date): endnotes, bib entries, ToC, …