Jun 11

More LaTeX Tips for Your Thesis – Aliases and the xspace Package

This is a follow-up post of this one

Consistency and speed are two major issues in writing your thesis. First, you want important and particularly technical terms to appear typeset in a consistent manner throughout the whole thesis. Everything else would just look unprofessional, and given that you chose LaTeX you seem to be serious about that point. Secondly, these kinds of names tend to be quite long and also appear frequently. So instead of typing your fingers bloody, you should make use of Latex being essentially a programming language and define variables, a.k.a. aliases or new commands. This is usually done using \newcommand. You can do that anywhere in the document, but I would recommend grouping all aliases together in the preamble. Let’s look at an example (sorry for the logic domain, but this is where all my current LaTeX texts are set in …):

\newcommand{\fol}{First-Order Logic\xspace}
\newcommand{\oversim}[1]{\,{\buildrel #1 \over \sim }\,}

% usage in normal text mode
\item It is good that when writing about \fol, I don't have to write \fol twice!
% works in math mode as well
\item Greek letter: $\sig$
% useful for consistency, if you want to change the notation later (see above)
\item Let $N=\{1,2,3\}$ and regard the elements of $\powerset{N}$ \dots
% hides complicated TeX stuff behind a simple command
\item They agree on everything but $x$: $g \oversim{x} g'$
% custom fine-grained spacing, consistent across your whole thesis
\item That's a hybrid language: \lEdownarrow

The output looks like this:

So what is going on? The first two examples do not have any parameters, but show that aliasing works both in text and math mode. Normally, these aliases bring up problems with spaces directly after them. You always need to have a space to delimit the command use from the normal text following it, so usually Latex does not print this space. This would lead to the first example ending like this:aliases-output2
The \xspace command provided by equally named package “just does the right thing”, so no trailing space in the first case, but in the second one. The next two examples show how to use parameters. The number in brackets gives the number of parameters, and you can subsequently access them with #index. This is useful e.g. when you don’t want to fix the notation yet (as in the power set example), or when building shortcuts for complex operators.

This is pretty much all that is important about aliases in LaTeX, xspace mostly works out of the box, so for once no need to RTFM.

More LaTeX tips for your thesis are coming up soon. If you have any wishes of packages I should write about (or even a guest article), please tell me about it. So long, happy writing…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>