# I can't find the error in a tikzcd diagram

The code is

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

\begin{document}
\begin{tikzcd}
\hom(A, A) \arrow[d, "\hom(A, f)"] \arrow[r, "\hom(h, B)"] & \hom(A', B) \arrow[d, "\hom(A', f)"] \\
\hom(A, B') \arrow[r, "\hom(h, B')"] & \hom(A', B')
\end{tikzcd}
\end{document}


and it gives a lot of errors, the first one being

Package pgfkeys Error: I do not know the key '/tikz/f)"' and I am going to ignore it. Perhaps you misspelled it.

What am I doing wrong?

• Welcome to TeX.SE! Try adding braces, e.g. "{\hom(A, f)}". – marmot Feb 20 at 20:01
• I confirm that @marmot suggestion solves the problem. But insert braces in all arrow labels. – Sigur Feb 20 at 20:03
• @marmot Thanks, that fixed it! So why is that necessary here? In the other diagrams I've made it was not, even if I used \times or something like that. – user388557 Feb 20 at 20:04
• Also, you could want to use \begin{tikzcd}[column sep=2cm] to change the columns space. – Sigur Feb 20 at 20:05

The problem comes from the commas inside \hom, which interfere with the commas separating the arguments of \arrow . Just add a pair of braces:

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

\begin{document}

\begin{tikzcd}[row sep=large, column sep=huge]%[column sep=3em]
\hom(A, A) \arrow[d, "{\hom(A, f)}"] \arrow[r, "{\hom(h, B)}"] & \hom(A', B) \arrow[d, "{\hom(A', f)}"] \\%
\hom(A, B') \arrow[r, "{\hom(h, B')}"] & \hom(A', B')%
\end{tikzcd}

\end{document}