# 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 reports (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: in style.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 tmp_build_dir exists only in the compilation script for the reports template.)

• do_bib: if set to true, build bibliography. If set to false, bibliography is skipped.

• do_idx: exactly the same, but for building the index.

• finalname: the name of the document produced when compiling with the final 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 the build/ directory, so the script needs to know which folders to replicate.

• verbose: If set to false, suppresses the output of bibliography and index building commands. Set to any other value – e.g. true – to show said commands’ output.

• tmp_build_dir: temporary directory, ideally in RAM-based temporary file system. The place where the unabridged copy (reports only) is compiled. See below.

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. (For reports only, running CompileTeX.sh with this option also causes for the unabridged copy to be compiled in the same manner; see the section unabridged copy, below).

• clean: wipe out the contents of the build/ 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 the finalname 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 the build/ folder, so as to reflect the current value of variable folders_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 the build/ 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 the build/ directory. Both things are accomplished with symbolic links—and invoking the compile script with the symlinks option takes care it.

• warnings: while the debug 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 the warnings 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).

## Reports only: unabridged copy

The documents I write using the reports’ template can sometimes become quite large, and so, like many LaTeX users, when editing them, I shorten the compilation time by compiling only a partial version, using the command \includeonly{}. However, it also happens (quite frequently, actually) that I want to look up in the PDF something… that is on the part not being compiled! Because of this, the compile script for this template maintains an unabridged copy, by keeping a file named Unabridged.tex—which is equal to report.tex, except that it is stripped of any \includeonly commands—that is compiled into the Unabridged.pdf file. This happens in the background: the main file can be edited and compiled normally, and on the background, the script will, first compile the regular (abridged) file, and then, if the compilation was successful, update Unabridged.tex and compile it. So chances are that, when the need arises to consult the full unabridged version of your document, one will be there for you, fully updated! This works transparently even for big compiles, with bibliography and index building.

## 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).

1. You can also do an internet search to see if there is a more recent version of the font files.↩︎

2. Kindly keep in mind, though, that this style file does accommodate all possible types of documents. Currently supported are article, book, inproceedinds and misc; further development is an ongoing effort…↩︎