I like LaTeX. A lot.
Here’s some little bits of wisdom I’ve collected, and some pet peeves that I just cannot stop annoying my friends with.
It’s not that many for now, but I’ll keep this post as a sort of living document and add stuff from time to time.
For some further reading, check out Tips on Writing a Thesis in LaTeX by Siarhei Khirevich. There’s a lot of cool typesetting knowledge in there that really came in handy during the final critical days of writing my Bachelor’s Thesis :p
Contents
Adding TODOs
I like using this macro to add clearly visible TODOs to my documents:
% preamble:
\usepackage{color,soul}
\newcommand{\TODO}[1]{%
\hl{\textbf{TODO}: #1}%
}
% document:
Ok, here's how the system works: Basically, it's just\dots
\TODO{Actually explain what's going on!}
When time runs out, and I have to submit the document
I want to preview the document without these, I just add the following
to my preamble:
\renewcommand{\TODO}[1]{} % disable TODOs
Beware of Whitespace after Periods
LaTeX inserts a slight little of extra space after a period, to make
reading easier. When a period does not end a sentence, use .\
to
keep the space short:
% oh no...
I would like to thank Prof. Dr. Jane Doe for their helpful advice!
% better:
I would like to thank Prof.\ Dr.\ Jane Doe for their helpful advice!
Also, nerd read: History of sentence spacing
Units of Measurement
For units of measurement, we’ll want a small space between the number
and the unit, and would like to have a small space separating thousands
places. This can be done either with the siunitx
package, or
manually:
% preamble:
\usepackage{siunitx}
% document:
This egg weighs \qty{12300.0}{kg}, perfect! % perfect
This egg weighs $12300.0$kg, oh no! % too little space
This egg weighs $12300.0$ kg, oh no! % too much space
This egg weighs 12\,300.0\,kg, neat! % alternative w/o math mode
Custom Word-Commands
I like defining some reoccurring words using macros, especially if
they’re names that I always want formatted the same way, or that I might
even want to change later. It’s important to use them with {}
at the
end – this way there’ll be a space if the command is followed by a
word.
\newcommand{\projectname}{\emph{Project}}
\newcommand{\vk}{\textsc{Vulkan}}
We've ported \projectname{} to the \vk{} graphics API!
Pet Peeve: Overfull hboxes
Gahh! Sometimes words will stick out juuuuust slightly to the right of the document. The example below is extra subtle because it’s a hyphen sticking out:
\lipsum[1][1-6]
Here’s how I make them impossible to miss:
\overfullrule=1cm % clearly show overfull hboxes
\lipsum[1][1-6]
Having a lot of overfull hboxes could point to an issue with hyphenation, like not having the correct language configured. But sometimes, the only thing that really helps is sliiiightly rewording a sentence to make it fit :^)
Pet Peeve: Paragraphs
I’ve seen people break paragraphs with \\
or \\\\
, like this:
\subsection*{Lorem Ipsum}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
commodo consequat. \\\\
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
And get a lot of these errors:
Underfull \hbox (badness 10000) in paragraph
What’s happening here is LaTeX trying to stretch the line, so the period at the end is all the way to the right. It generally won’t be able to do that without exceeding its limit for h o r i z o n t a l s t r e t c h though.
It’s better to make paragraphs by inserting blank lines:
\subsection*{Lorem Ipsum}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
If you really do still want that same look as above, you could set the following:
\setlength\parindent{0pt} % disable indenting
\setlength{\parskip}{1em} % blank line between paragraphs
But a more moderate parskip
might be better suited, and for longer
articles, having parindent
really does help with readability.