1

Somehow it is not possible to combine tikzcd and newcommand, as shown in the following MWE:

\documentclass{paper}
\usepackage{tikz-cd}

\begin{document}

\newcommand{\dotheobvious}[1]{#1}
\dotheobvious{\[\begin{tikzcd}X\ar[r] & Y\end{tikzcd}\]}

\end{document}

I get the following error:

! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options 

l.7 ...{\[\begin{tikzcd}X\ar[r] & Y\end{tikzcd}\]}

The output looks like this, the Y is missing:

enter image description here

What's wrong here?

  • Can I understand what you want to achieve? Could you please to add a figure? Thanks. – Sebastiano Jan 25 '18 at 21:07
  • I just want the code of a tikzcd diagram to be part of the input of a macro (of course, a less trivial one) defined via \newcommand, but somehow this fails. – FKranhold Jan 25 '18 at 21:15
3
\documentclass{paper}
\usepackage{tikz-cd}

\begin{document}

\newcommand{\dotheobvious}[1]{#1}
\dotheobvious{\[\begin{tikzcd}[ampersand replacement=\&]X\ar[r] \& Y\end{tikzcd}\]}

\end{document}

tikzcd is a tikzmatrix which by default uses an active character & and like all catcode change commands does not work in the argument of another command, however it has an option to use a command form instead of & it seems conventional to use \& for this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.