General/Documents #
Debugging #
In system shell #
Find out the current version of LaTeX: (credit)
pdflatex --version
When \xdef\@fontenc@load@list{\@fontenc@load@list undefined control sequence
happens: (credit)
fmtutil-sys --all
Pass options to already loaded packages #
When ! LaTeX Error: Option clash for package ...
(credit)
\PassOptionsToPackage{dvipsnames}{xcolor}
% before
\documentclass{...}
Find mirrors #
In CTAN list of mirrors, adding
systems/texlive/tlnet/
after the https
links will get you the link that TeX Live Utility needs.
Outdated TeX Live #
Ref: texlive - Historic TeX Live distributions: HTTPS/SFTP mirror - TeX - LaTeX Stack Exchange
If you are on, for example, TeX Live 2022, and all the available mirrors have already upgraded to 2023 (marked by a 0-byte TEXLIVE_2023
file in the tlnet root), then you need the historic repository. A list of the mirrors is available at Historic archive - TeX Users Group, and adding
systems/texlive/2022/tlnet-final/
(or with any other year that you need) after the https://ftp.
links will get you to the TeX Live Utility link.
Build & file structures #
Compile two versions at one pass #
pdftex - 2 PDF Outputs at once with 2 different styles - TeX - LaTeX Stack Exchange
Or: Arara (?)
File control/subfiles #
Also see: Management in a large project - Overleaf, Online LaTeX Editor
At least in TeXstudio, as long as
%!TEX root
is set properly, build can be triggered in any sub-file.However, after updating any BibLaTeX file, only rebuilding the root file will trigger the
This is an extensive example with both custom class, separate preamble file and bibstyle. There is no need to use everything.
.
├── main.tex
├── myclass.cls
├── mypreamble.tex
├── slides.tex
├── ref.bib
├── chapters
│ ├── intro.tex
│ ├── sections.tex
│ ├── model.tex
│ └── appendix.tex
└── styles
├── aernobold.bst
└── aernobold.sty
In main.tex
:
\documentclass{myclass}
\input{mypreamble}
\begin{document}
\include{chapters/intro}
\include{chapters/sections}
\include{chapters/model}
\bibliography{ref}
\appendix
\include{chapters/appendix}
\end{document}
In mypreamble.tex
:
\bibliographystyle{styles/aernobold}
In chapters/**.tex
(first line of file):
%!TEX root = ../main.tex
Prevent page breaks around subfiles #
Way 1: use \input
(credit)
\input{file1}
\input{file2}
Way 2: use \include
(credit)
This method breaks all cleveref references pointing to labels inside the subfiles. Don’t know about normal references.
\begingroup
\let\clearpage\relax
\include{file1}
\include{file2}
\endgroup
Citation in section title #
\section[Section title for running heading]{Section title with citation \cite{key}}
Cross-referencing #
Bookmarks #
Section numbers in PDF bookmarks: (one of them will work depending on your styles, bookmark
is better)
\usepackage[bookmarksnumbered]{hyperref}
\usepackage[numbered]{bookmark}
Manually add bookmarks: (ref)
% if using numbered bookmarks
\usepackage[numbered]{bookmark}
\bookmarksetup{startatroot}
\currentpdfbookmark{Bibliography}{bibliography}
\bibliography{ref}
% note: don't use, will mess with appendix bookmark levels:
% \bookmark[level=0,named=Bibliography]{Bibliography}
% if using unnumbered bookmarks
\pdfbookmark[section]{Bibliography}{bibliography}
\bibliography{ref}
Equations & sections #
Ref: Cross-reference packages: which to use, which conflict? - TeX - LaTeX Stack Exchange
TL;DR: use cleveref
.
Links #
LaTeX/Labels and Cross-referencing - Wikibooks, open books for an open world
Code display #
listings
package #
\usepackage{listings}
\lstset{
basicstyle=\ttfamily\small,
breaklines=true
}
\lstMakeShortInline[columns=fixed]|
\begin{document}
\lstinline|hello, world|
\begin{lstlisting}[language=Python]
# help i'm in latex hell
\end{lstlisting}
\end{document}
minting
package #
TBE!!
Colour #
Coloured links #
Ref: better default colors for hyperref links - TeX - LaTeX Stack Exchange
% by default markdown introduces hyperref
\PassOptionsToPackage{colorlinks}{hyperref}
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\hypersetup{
linkcolor=BrickRed
,citecolor=Green
,filecolor=Mulberry
,urlcolor=NavyBlue
,menucolor=BrickRed
,runcolor=Mulberry
,linkbordercolor=BrickRed
,citebordercolor=Green
,filebordercolor=Mulberry
,urlbordercolor=NavyBlue
,menubordercolor=BrickRed
,runbordercolor=Mulberry
}
Formatting text #
Highlight #
\usepackage{soul}
% or
\usepackage{soulutf8}
% can be used with various colours
\usepackage[dvipsnames]{xcolor}
\sethlcolor{GreenYellow}
% or even custom colours (also with xcolor)
\definecolor{highlight}{HTML}{FFFF81}
\sethlcolor{highlight}
\begin{document}
\hl{Good words.}
% Cleveref requires a warping mbox
% https://tex.stackexchange.com/a/270904/206709
\hl{Not so good words with \mbox{\cref{tab:a-table}}.}
\end{document}
Strike through #
With package soul:
\usepackage{soul}
% or
\usepackage{soulutf8}
\begin{document}
\st{overstriking}
\end{document}
With package ulem:
\usepackage[normalem]{ulem}
\begin{document}
\sout{Bad words.}
\end{document}
Lists #
Unordered #
\begin{itemize}
\item ...
\item ...
\item ...
\end{itemize}
Ordered with numbers #
\begin{enumerate}
\item ...
\item ...
\item ...
\end{enumerate}
Ordered with alphabet #
\usepackage[shortlabels]{enumitem}
\begin{enumerate}[label=\alph*)] % \Alph* for upper case
\item ...
\item ...
\item ...
\end{enumerate}
Quick pseudo list #
Ref: spacing - How can I force a \hspace at the beginning of a line? - TeX - LaTeX Stack Exchange
\hspace*{0.5ex}\hspace{3ex}a) ...
\hspace*{0.5ex}\hspace{3ex}b) ...
\hspace*{0.5ex}\hspace{3ex}c) ...
Checklist #
Ref: enumerate - How to create checkbox todo list? - TeX - LaTeX Stack Exchange

\usepackage{enumitem,amssymb}
\newlist{todolist}{itemize}{2}
\setlist[todolist]{label=$\square$}
\usepackage{pifont}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\newcommand{\done}{\rlap{$\square$}{\raisebox{2pt}{\large\hspace{1pt}\cmark}}%
\hspace{-2.5pt}}
\newcommand{\wontfix}{\rlap{$\square$}{\large\hspace{1pt}\xmark}}
\begin{document}
My ToDo list
\begin{todolist}
\item[\done] Frame the problem
\item Write solution
\item[\wontfix] profit
\end{todolist}
\end{document}
Maths #
Too much space around display math #
Ref: line spacing - Spaces around display math when using setspace - TeX - LaTeX Stack Exchange
\usepackage[nodisplayskipstretch]{setspace}
\begin{document}
…
\end{document}
Page number #
Reset page number at appendix #
Ref: Restart page numbering for memoir appendix - TeX - LaTeX Stack Exchange
\begin{document}
% Words.
\clearpage
\pagenumbering{arabic}
% \setcounter{page}{0}
\appendix
% Less important words.
\end{document}
Page margin #
Change margin for a few pages #
Ref: Latex - Change margins of only a few pages - Stack Overflow
\usepackage{geometry}
\begin{document}
% words
\newgeometry{top=0.5cm, bottom=0.5cm}
\input{a-very-big-figure}
\restoregeometry
\end{document}
Plots/Images #
Full image #
If want to control width:
\begin{figure}
\centering
\includegraphics[width=\linewidth,keepaspectratio]{figure/great-pic-1.png}
\caption{A good picture.}
\label{fig:great-pic-1}
\end{figure}
Horizontal subplots #
For alignment inside subcaption figures, see this answer.
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}[t|c|b]{0.45\textwidth}
\centering
\includegraphics[width=\linewidth,height=\textheight,keepaspectratio]{images/great-picture-1.png}
\caption{A good picture.}
\end{subfigure}% no empty line here!!
\begin{subfigure}[t|c|b]{0.45\textwidth}
\centering
\includegraphics[width=\linewidth,height=\textheight,keepaspectratio]{images/great-picture-2.png}
\caption{A splendid picture.}
\end{subfigure}
\caption{Two great pictures.}
\end{figure}
\end{document}
Vertical subplots #
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}{\textwidth}
\centering
\includegraphics[width=\linewidth,height=0.8\textheight,keepaspectratio]{images/great-picture-1.png}
\caption{A good picture.}
\end{subfigure}
\begin{subfigure}{\textwidth}
\centering
\includegraphics[width=\linewidth,height=0.8\textheight,keepaspectratio]{images/great-picture-2.png}
\caption{A splendid picture.}
\end{subfigure}
\caption{Two great pictures.}
\end{figure}
\end{document}
Better environments/defaults #
List with larger line height #
Ref: How to adjust list spacing | The TeX FAQ
Note: works in Beamer, but does not work with [<+->]
overlay (see Beamer #Bugs & quirks)
\newenvironment{itemize*}%
{\begin{itemize}%
\setlength{\parskip}{0.5em}}%
{\end{itemize}}
More permissible slash and hyphen #
Make LaTeX more willing to break line (Ref)
\makeatletter
\renewcommand{\slash}{/\penalty\z@\hskip\z@skip }
\newcommand{\hyphen}{-\penalty\z@\hskip\z@skip }
\makeatother
Packages #
Cleveref #
\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}
% use abbreviation everywhere
% https://tex.stackexchange.com/a/386310
\Crefname{equation}{Eq.}{Eqs.}
\Crefname{figure}{Fig.}{Figs.}
\Crefname{table}{Tab.}{Tabs.}
\Crefname{tabular}{Tab.}{Tabs.}
\Crefname{section}{Sect.}{Sects.}
\begin{document}
\Cref{fig:1} is capitalised, and \cref{fig:1} is not capitalised.
\end{document}
siunitx #
Thousands separator:
\usepackage{siunitx}
\sisetup{
group-separator = {,},
group-minimum-digits = 4,
}
\begin{document}
\SI{15663}{} % The empty braces are necessary for correct spacing
% Gives: 15,663
\end{document}