# Define macro for tikz-cd environment [closed]

I'd like to have a shorthand for

\begin{center}
\begin{tikzcd}
% ..diagram code...
\end{tikzcd}
\end{center}


I tried with

\tikzset{ampersand replacement=\&}
\def\bcd#1\ecd{\begin{center}\begin{tikzcd}#1\end{tikzcd}\end{center}}


Where the first command should fix problems with ampersands. Without it, I get errors about them but even with it, pdflatex doesn't seem to be able to produce a right output (I get the error Package tikz: Sorry, the system call 'pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "figures/cache/main-figure1" "\def\tikzexternalrealjob{main}\input{main}"' did NOT result in a usable output file 'figures/cache/main-figure1' (expected one of .pdf:.jpg:.jpeg:.png:)...)

The error seems to occur on regular images, so maybe it's a problem of interoperability with the \tikzset command? If I disable tikz-external, the only error remaining is Float(s) lost.

• Are you adding captions to those diagrams? If not, the figure environment is rather pointless. I'd remove it and \centering, and use a center environment instead. – Torbjørn T. Mar 11 '18 at 14:39
• @TorbjørnT. You're right! – mattecapu Mar 11 '18 at 14:42

• making such shorthands is usually in the end not a good idea, it makes it much harder for your editor to offer context sensitive syntax highlighting or help and given reasonable editor setup it does not save any typing as you should be able to add \begin{..} \end{...} in just a few keystrokes. – David Carlisle Mar 11 '18 at 15:00