Techniques and packages to keep up with good practices
General tips
- Use as few packages as possible,
- Call the packages in particular order,
- Use many small documents instead of one big one,
- Comment your code,
- Write readable code,
- Concentrate on the content, not on the appearance.
General tips somewhat explained
- That's because packages tend to conflict and go obsolete. (See How to keep up with packages and know which ones are obsolete?)
- Some packages require (or are recommended) to be called before/after other packages. Some must be called among the last, some among the first. (See Packages that need to be included in a specific order)
This means using
\include{}
and/or\input{}
commands to compose all the small pieces (chapters, sections, etc.) into one continuous document. (See When should I use \input vs. \include?). [The rationale in this point is to keep the code clean and short (rule 5) in your master document. Then you can focus on content of each piece of the document (rule 6).] A benefit of this point is that you can get to set shortcut commands to use in all documents in a .tex file in your path, and then\input
it in the preamble of any/all documents. This can make for a very large document to keep short at the eye at an initial stage of reading the master document pretty much like a shortmwe
.If one forgets what particular block of code does, reading the comments will help by the fastest possible way.
- This means short lines, appropriate line indentation, using
\newcommand
to define (mnemonic) commands for repetitive math expressions, etc. - Hack little, think more, write on the subject. Appearance without content is nothing.
And probably other things ...
- Programing
fixltx2e
is essentialetoolbox
provides some functionality that one can only get from hacking LaTeX kernel or using the internal macros otherwise. Also it provides some useful document and environment hooksxspace
is a tiny but useful macro for defining text oriented macrosgeometry
,typearea
, etc, use one and only one of them. The same principle apply fortitlesec
,fancyhdr
, etc. In principle, avoid using packages provide similar functionality at the same time, especially when one of them hack the LaTeX kernel. Use the best of them only ("best" for you anyway).
- Typography
booktabs
is essential for professional look tables. Also avoid using vertical lines. In fact you should never use vertical lines and limit the use of horizontal lines- for typographical consideration, consistency is far more important than details. For example if you use
\begin{tabularx}{\textwidth}{...}...
, use it everywhere. Make all tales have the same feel. - figures, either from external software of using packages like
tikz
, produce them with the size they are meant to be. Try to avoid using\includegraphics[scale=...]
, etc - use
\DeclareMathOperator
, don't use\mathrm
whenever suitable - use colors carefully, again, consistency is better than fancy. Define a few colors and stick with them only.
- Use different weight, different size, different shapes, different font families, to present different things. But use one and only one of them. For example, don't use a bold large sans serif for heading, just bold, or just large, or just sans serif, or simple capitals of the body fonts.
- Last not least, "every typographical rules can be broken, as long as you know the rule".
Loading the
strict
package prevents using LaTeX's declarations as environments.Loading the
fixltx2e
package fixes some LaTeX2e errors.fixmath
changes LaTeX's default math style to comply with some international standards, specifically regarding Greek letters, see package description.There are many packages improving LaTeX's standard behavior, for example
setspace
andbooktabs
, and packages supporting typographic requirements/ styles and quality, such assiunitx
andmicrotype
, so preferring them over LaTeX standard features would be best practice. Recommended packages can be found here: What packages do people load by default in LaTeX.