My LaTeX document looks like this:
\documentclass{article}
\usepackage{tikz-cd}
\newcommand{\commSq}[8]
{
\begin{tikzcd}
#1 \ar[r, "#2"] \ar[d, "#6"] & #3 \ar[d,"#4"] \\
#7 \ar[r, "#8"] & #5
\end{tikzcd}
}
\begin{document}
%1
\begin{tikzcd}
A \ar[r, "f"] \ar[d, "g"] & B \ar[d,"h"] \\
C \ar[r, "i"] & D
\end{tikzcd}
%2
\commSq{A}{f}{B}{h}{D}{g}{C}{i}
\end{document}
I figured that the part the code below %1 and the code below %2 do the same thing. However, using the command \commSq instead yields the error "Package pgf Error: Single ampersand used with wrong catcode. [...]" and I get this output:
What am I doing wrong here?

\pgfmatrixnextcellinstead of&might work, and so it does. Hence, your question pretty much seems to be a duplicate of Problem with defining shortcuts for TikZ matrices.. – moewe Aug 14 '15 at 09:30\newcommandcontaining TikZ code. They did not use thetikz-cdpackage, buttikz-cduses TikZ, so the issue is inherited, if you will. – moewe Aug 14 '15 at 09:58