LaTeX notes

Table of Contents

This is an excellent reference:


Some editors for LaTeX (there are many others):

Many of them have spell checkers but not grammar checkers. TexStudio [1] [2], VSCode [1], and Emacs [1] can integrate Language Tool, the grammar checker for LibreOffice.


Option for setting margins:




Example of adding header/footer:

\topmargin -25pt
\headsep 15pt
\fancyhead[L]{\emph{Running title}}
\fancyhead[R]{Author name}

For \onehalfspacing command, use setspace package.

To turn off automatic indentation, use parskip package. To indent all paragraphs, use indentfirst package.


Sans serif

Sans-serif text and math:

% \usepackage{helvet} % optional


Bold Greek letters: use bm package, which invokes \boldmath or \boldsymbol as necessary. Example usage: \bm{\beta}.

Many engineering equations use multi-character variable names. E.g., instead of x, y, etc., people might name their variables to reflect the physical phenomenon being modeled. E.g., RH (relative humidity), MW (molecular weight), OA (organic aerosol). In this case, use $\mathit{RH}$ instead of just $RH$.

Functions typically have their corresponding LaTeX commands: e.g., \exp, \ln, \sin.

Multiplication operators such as \times and \cdot is preferred to *.

Parentheses, brackets can be automatically scaled with contents (e.g., fractions and subscripts): \left( \ldots \right), \left[ \ldots \right], \left\{ \ldots \right\}, \left\langle \ldots \right\rangle.

Use amssymb and upgreek packages for some symbols.


For consistent subscript size:


Conventionally, math expressions were used for subscripts/superscripts even in text. E.g., PM$_{2.5}$. Now there is \textsubscript{} and \textsuperscript{} , as well as other options.


Use the mhchem package with explicit specification of version number:


Example usage: \ce{NO2}, \ce{O3}, \ce{NO_x}.

Copernicus has a \chem{} macro but operates differently. Example usage: \chem{NO_2}, \chem{O_3}, \chem{NO_x}.



Defining macros

Usage of \newcommand{} and \renewcommand{}.

Optional space after the command

When defining a macro with no arguments, an empty space should be created using {}. For instance, \newcommand{\pmfine}{PM\textsubscript{2.5}} should be invoked as \pmfine{}. Alternatively, the xspace package can be used with the command \xspace. Example: \newcommand{\pmfine}{PM\textsubscript{2.5}\xspace}. See section on units for another example.

Number in variable names

You cannot use numbers in macros. Rather than \newcommand{\x1}{variable1}, use \newcommand{\x}[1]{variable#1}. In your latex file, you would then invoke using \x{1}.


Use siunitx package. \si for units (e.g., \si{\meter.\second^{-2}}) and \SI for both numbers and units (e.g., \SI{9.8}{\meter.\second^{-2}}). More examples below. Common prefixed units have their own abbreviated command - e.g., \cm can be used in place of \centi\meter - enable these abbreviations with load=abbr:


Define macros:


Mathematical expressions

Enclose expressions in \ensuremath{} so that they can be used inline in also within mathematical expressions without using $. Also use xspace. Example — if you have a variable typically written $\mathit{MW}$, you can recode it as \MW:


This can be used as \MW = 18.01 \si{\gram.\mole} in text, or $\MW = 18.01 \si{\gram.\mole}$.

Line numbers


AMS math environments conflict with line numbers:

  \expandafter\let\csname old#1\expandafter\endcsname\csname #1\endcsname
  \expandafter\let\csname oldend#1\expandafter\endcsname\csname end#1\endcsname
  {\linenomath\csname old#1\endcsname}%
  {\csname oldend#1\endcsname\endlinenomath}}%

The code above is included in the preamble file here. Example usage:


Local environments

For simple tasks:

\appendix % or \renewcommand{} etc.

OR, for more complex tasks:


Placing custom .sty and .bst files

Check where TEXMFHOME is

kpsewhich -var-value=TEXMFHOME

Then check out this table to place the file in the appropriate location. See also this reference.

On MacOS, they are typically:


Handling file names

Using the tilde:


Spaces in graphics file name:

[ ... ]
\includegraphics{A file with spaces}

Period/dot in graphics file name:


Spaces in input file name:

\input{"File\space Of\space Mine"}


For journal articles, use bibtex template provided by publisher (not biblatex). Biblatex is helpful in the drafting stage, in that missing references are indicated by their .bib key rather than "??" in citations as with bibtex. It is simple to change out biblatex with bibtex for publication.


The code below is included in the preamble file here. Example usage:



Loading the package:

    natbib                      % for citation
    citestyle=authoryear,       % for citation
    maxcitenames=2,             % for citation
    uniquelist=false,           % for citation
    uniquename=false,           % for citation
    sorting=nyt,                % for bibliography
    date=year,                  % for bibliography
    bibstyle=ieee,              % for bibliography
    maxbibnames=99,             % for bibliography

Last names first:


Use hanging indentation:


Create doi links in bibliography:


Also in the preamble, specify location of .bib file:


Main document

Change bibliography title:


No bibliography title:


Multiple bibliographies:

\section*{Section 1}

Natbib and bibtex

natbib and bibtex (instead of biblatex) still required for journal submissions.

Don't print reference section title


Don't print reference section title at all (with natbib)


Don't show reference section title on TOC


Reference section title as section head


Extracting subset of bibliographies

E.g., for distribution with tex file. Use bibtool.

To build, download and unpack

make --file=makefile.unx
sudo make --file=makefile.unx install
sudo make --file=makefile.unx
make --file=makefile.unx clean

To build docs:

cd doc

To use:

bibtool -x file.aux -o refs.bib

Unicode characters in .bib file

First, try importing:


If this is insufficient, try substituting each problematic unicode character:

\DeclareUnicodeCharacter{2202}{ }

To find which specific characters are causing problems, a great macro that can be placed in the preamble is introduced here:


      % Remove prefix "\u8:"
      % Extract Unicode char from command name
      % (utf8.def does not support surrogates)
      \StringEncodingConvert\x\x{utf8}{utf16be}% convert to UTF-16BE
      % Hexadecimal representation
      % Enhanced error message
      \PackageError{inputenc}{Unicode\space char\space \string#1\space
                              not\space set\space up\space
                              for\space use\space with\space LaTeX}\@eha

Download this preamble file here. Example usage:


Then monitor the .log file to check the offending character(s).

Cross referencing with xr

If you have two files, master.tex and supportinginfo.tex, you would include these in your respective preambles:





Deleting .aux and extra files (for both .tex files) prior to compiling may be necessary when there are errors.

Spell/grammar check

Apart from spell checking or grammar checking (using Language Tool), another option is to export an ASCII file using detex and opening the file in MS Word. In a shell command line:

detex master.tex intro.tex methods.tex results.tex conclusions.tex > alltext.txt

Alternatively, you can export to a Rich Text Format (.rtf) file to open in MS Word using pandoc:

pandoc master.tex -o output.rtf --bibliography references_1.bib -s

These methods can also provide an (very) approximate character or word count. (?)


Put \batchmode at the top of your .tex file (or \nonstopmode for more verbose output) to avoid stopping when there is an error.

To avoid having to repeat pdflatex, bibtex, pdflatex, and pdflatex, use latexmk:

latexmk -pdf texfile

On Max OS X, latexmk can be installed with texlive.

Generated by Org-mode 9.2.3 with Emacs 26