I defined a simple diagram environment with
\usepackage{tikz-cd}
\newenvironment{diagram}
{ \begin{equation}\begin{tikzcd} }
{ \end{tikzcd}\end{equation} }
and it worked fine. In particular this compiled:
\documentclass{article}
\usepackage{tikz-cd}
\newenvironment{diagram}
{ \begin{equation}\begin{tikzcd} }
{ \end{tikzcd}\end{equation} }
\begin{document}
\begin{diagram}
&
\end{diagram}
\end{document}
Later on I realized I need to call tikzcd with different arguments in a number of places, so I changed the environment definition to include an optional argument, but now
\documentclass{article}
\usepackage{tikz-cd}
\newenvironment{diagram}[1][]
{ \begin{equation}\begin{tikzcd}[#1] }
{ \end{tikzcd}\end{equation} }
\begin{document}
\begin{diagram}
&
\end{diagram}
\end{document}
fails to compile, and the diagram code above needs to be changed to {}&
to work again. So presumably applying this change whenever a diagram starts with an ampersand would solve my problem, but I'd like to know
- why does this happen in the first place, so that I can avoid similar problems in the future
and, seeing that
\begin{tikzcd}
&
\end{tikzcd}
works just fine and tikzcd takes optional arguments too,
- is there a better way to solve this than adding superfluous braces in a large number of diagrams?