3

Leaving a line empty in a bare tikzcd environment (as below) produces a "Missing $ inserted" error.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
A

B
\end{tikzcd}
\end{document}

But when I wrap the tikzcd environment in a center environment (as below), there is no compilation error.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{center}
\begin{tikzcd}
A

B
\end{tikzcd}
\end{center}
\end{document}

What's going on?

1 Answers1

2

Adding some detail to David's comment.

The center environment and other similar "display" environments use the \trivlist construction internally. (I'm using David Carlisle's terminology from Use of \trivlist and \list in defining environments).

So \center is defined as:

\trivlist \centering \item \relax

And within the definition of \trivlist (actually \@trivlist) is a redefinition of \par to:

\if@newlist \advance \par@deathcycles \@ne \ifnum \par@deathcycles >\@m
  \@noitemerr {\@@par }\fi \else {\@@par }\fi 

This effectively means that \par (or a blank line) doesn't behave like regular \par inside the center environment, and therefore doesn't produce the error you see when the tikzcd environment is inside the center environment.

Alan Munn
  • 218,180