latex-advice
repository·master·Indexed 23 days ago
https://github.com/dspinellis/latex-adviceA collection of best practices and advice for writing high-quality, maintainable, and professional scientific documents using LaTeX. The guide focuses on technical workflows, version control, build automation, and maintainability for researchers in fields such as computer science, engineering, mathematics, and physics.
What's inside latex-advice
- This project provides a collection of best practices for writing scientific documents (books, papers, theses) using LaTeX. It focuses on technical workflows, maintainability, and automation rather than English writing style or TeX programming itself. The advice is intended for researchers in fields like computer science, engineering, mathematics, and physics.
Automate the LaTeX document build
masterEnsure your document can be built with a single command to avoid using outdated files and to facilitate teamwork. Recommended tools include:
- latexmk: A standard tool bundled with most LaTeX distributions. Highly recommended for handling multiple passes.
- BSD Owl: A set of scripts for build automation.
- SCons: A build system using Python scripts (typically named
SConstruct). - Unix make: The standard
makecommand, though expressing complex multi-pass requirements can be difficult.
Use style files for document formatting
masterUse style files provided by publishers or conference organizers to ensure your document meets their specific formatting and reference requirements. Using the official template helps minimize rework and ensures your document looks as it will in its published form.Avoid explicit formatting and use semantic commands
masterInstead of using explicit font commands (like
\textbfor\textit) for general text styling, use semantic commands that describe the purpose of the text. This allows you to change the styling globally by modifying a single definition.Example: Defining a custom command for findings
\newcommand{\finding}[1]{\textbf{#1}}Example: Defining a custom environment for licenses
\newenvironment{license}{\verbatim\scriptsize}{\normalsize\endverbatim}\newcommand{\finding}[1]{\textbf{#1}} \newenvironment{license}{\verbatim\scriptsize}{\normalsize\endverbatim}Typography and Text Formatting
masterFollow these rules for professional typography:
- Dashes: Use
---for an em-dash (no spaces around it) and--for an en-dash (used for number ranges like2009--2015). - Emphasis: Avoid underlining. Use bold or italics instead. For abbreviations, use
\textsc{...}(small caps). - Lists: For describing elements, use the
descriptionenvironment instead ofitemize. - Ellipsis: Use
\dotsfor the ellipsis symbol. - Footnotes: Place footnotes after punctuation symbols.
- Code/Algorithms:
- Use
algorithmicxfor pseudo-code. - Use
listings(simple) orminted(advanced/nicer) for source code snippets. Ensure code does not exceed paragraph width.
- Use
- Dashes: Use
Apply LaTeX typesetting best practices
masterFollow these rules to ensure high-quality typography and maintainable LaTeX source code:
- Prevent line breaks before references: Use a tilde (
~) before\cite,\ref, etc.- Example:
Some also use logging statements~\cite{Spi06e}.
- Example:
- Handle non-sentence ending periods: Place a backslash (
\) after a period that does not end a sentence to prevent incorrect spacing.- Example:
In 1962 Watson et al.\ famously found ….
- Example:
- Avoid math mode for plain text effects: Use
\textsubscript{}and\textsuperscript{}instead of math mode\( ... \)for subscripts and superscripts in text.- Example:
RQ\textsubscript{2}instead of\(RQ_2\).
- Example:
- Manage quotation marks:
- Use matching single-opening (
‘or‘‘) and single-closing (’or’’) characters instead of the keyboard double quote ("). - Alternatively, use the
\enquote{}macro from thecsquotespackage to handle language-specific quotes and nesting automatically.
- Use matching single-opening (
- Use modern font style commands: Prefer local font style commands like
\texttt{},\textsc{}, or\textbf{}over old switches like{\tt },{\sc }, or{\bf }.
- Prevent line breaks before references: Use a tilde (
Best practices for Figures and Floats
masterFigures
- Format: Prefer vector graphics (PDF) over bitmaps (JPEG/PNG) to ensure scalability.
- Consistency: Use the same font across all figures and scale them to match the document's font size.
- Captions: Do not include a separate figure title; the caption serves this purpose. Label all axes.
Floats
- Environments: Use
figureortableenvironments to allow large elements to float. - Centering: Use
\centeringinside the environment instead of thecenterenvironment to avoid extra vertical space. - Placement: Reference all floats in the text and place the float in the document before its first reference.
- Caption Position: Generally, place table captions above the table and figure captions below the figure.
Best practices for writing Mathematics in LaTeX
masterTo ensure high-quality mathematical typesetting, follow these rules:
- Math Mode: Always use LaTeX's math mode for all formulas and symbols. For inline math, prefer
\(and\)delimiters over the TeX$style. - Bracketing: Use balanced
\leftand\rightcommands so that brackets (parentheses, braces, etc.) automatically scale to the height of the content. - Operators:
- Use built-in commands for supported operators (e.g.,
\mod,\max,\sin). - For unsupported operators, use
\DeclareMathOperatorfrom theamsmathpackage. - For multi-character variable names, use
\mathit{...}or\mathrm{...}to avoid incorrect spacing. - Use roman type for non-index descriptive subscripts (e.g.,
x_{\mathrm{max}}).
- Use built-in commands for supported operators (e.g.,
- Structure: Indent elements and break lines to express logical structure, keeping operators as the first character on a new line.
- Punctuation: Equations are part of sentences. End them with a period or comma as appropriate, and use a thin space
\,before the punctuation to prevent it from looking cramped.
- Math Mode: Always use LaTeX's math mode for all formulas and symbols. For inline math, prefer
Manage bibliographic references in LaTeX
masterAutomate your bibliography by using BibTeX or Biber. Create centrally-managed
.bibfiles and include them in your document using the\bibliographycommand.Best Practices for Citations:
- Use
\cite{key1,key2}to group multiple references in a single command. - To reference specific pages or chapters, use square brackets:
\cite[p.~8]{LR89}. - For author-year citations, use the
natbiborBibLaTeXpackages with commands like\citet,\citep, and\citeauthor.
Best Practices for BibTeX Entries:
- Title Capitalization: Use title case (e.g.,
The Elements of Programming Style). To preserve specific capitalization (like acronyms), wrap the character in braces:The {C} Programming Language. - DOI over URL: Prefer using the
doifield over aurlfield. When usingdoi, do not include the resolution prefix (e.g., usedoi = {10.1371/journal.pone.0294946}instead ofhttps://doi.org/...). - Consistent Keys: Use short, derivable keys. A recommended scheme is:
- Single author: First three letters of surname + last two digits of year (e.g.,
Ker08). - Multi-author: Up to four initials of surnames + last two digits of year (e.g.,
DMG07). - Clashes: Append
a,b,c, etc.
- Single author: First three letters of surname + last two digits of year (e.g.,
- Special Characters: Use LaTeX escapes for non-ASCII characters in author names (e.g.,
\'{e}) if not using Biber with Unicode support.
- Use
Format numbers and units with siunitx
masterTo comply with NIST and SI standards (e.g., placing a thin non-breaking space between a number and its unit), use the
siunitxpackage. This package also handles long numbers with thin-space decimal separators and proper negative signs.Key commands:
\qty{value}{unit}: For quantities with units.\num{value}: For formatting numbers.\SI{value}{unit}: Alternative for SI units.\SIrange{low}{high}{unit}: For ranges.\SIlist{v1; v2; ...}{unit}: For lists of values.
It took \qty{7146}{s} to load a \qty{134}{\gibi\byte} file over a \qty{200}{\mebi\bit} connection over a distance of \qty{9500}{\km}. During the transfer \num{12345} packets were dropped. The ambient temperature was \qty{-35}{\degreeCelsius}. % Other siunitx examples \SI{90}{\percent}, \SI{45}{\degreeCelsius}, \SIlist{5; 10; 15}{\milli\metre}, \SIrange{512}{1024}{\mebi\byte}Create professional Tables
masterAvoid using vertical rules (
|) or excessive horizontal rules (\hline). Instead:- Alignment: Align numbers to the right, text to the left, and single symbols to the center. Use
siunitxto align decimals. - Source Formatting: Use hard tabs before each column's
&separator so columns align visually in the.texsource file. - Long Labels: If column labels are long, place them on separate lines, keeping them aligned with the data.
- Horizontal Rules: Use the
booktabspackage for professional-looking rules:\toprule,\midrule, and\bottomrule.
% Using booktabs for professional rules \toprule Header \\ \midrule Table row 1 \\ Table row 2 \\ \bottomrule % Aligning columns in source for readability tr -cs & 1 & \X & -- & \V & 1 \\ sort w & 0 & & -- & \X & 0 \\- Alignment: Align numbers to the right, text to the left, and single symbols to the center. Use
Use LaTeX linters to find typesetting errors
masterRun the following linters on your document to identify and fix LaTeX anti-patterns (such as using
...instead of\dots):- LaCheck: Run using the
lacheckcommand. - ChkTeX: Run using the
chktexcommand.
Users can define custom rules for these linters to enforce specific project guidelines or spelling consistency.
- LaCheck: Run using the