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.

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:

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

Compiler options. OK, with that out of the way, let us go now the actual options that the compile script actually accepts.

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

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, …