在 tikzcd arrows 中使用带有可选参数的命令

在 tikzcd arrows 中使用带有可选参数的命令

我已经定义了一个雅可比矩阵的命令,例如以下

\newcommand{\Jacobian}[2][]{\operatorname{J}_{#1}{#2}}

如果我尝试在箭头内使用它,就会出现问题tikzcd,可能是因为括号的解释存在问题。我想写这样的东西:

\begin{tikzcd}
    \mathbb{R}^{2} \arrow[r,"\Jacobian[p]{f}"] &
    \mathbb{R}^{2}
\end{tikzcd}

并得到输出,就像我输入的一样

\begin{tikzcd}
    \mathbb{R}^{2} \ar[r, "\operatorname{J}_{p}{f}"] &
    \mathbb{R}^{2}
\end{tikzcd}

但如果我尝试这样做,编译会失败

ERROR: Argument of \tikz@quote@@parser has an extra }.

--- TeX said ---
<inserted text> 
\par 
l.152     \end{tikzcd}

--- HELP ---
From the .log file...

I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.

我尝试在一些合理的位置放置牙套,但没有成功。

答案1

您必须将整个命令括在括号中里面引號。

\begin{tikzcd}
    \mathbb{R}^{2} \arrow[r,"{\Jacobian[p]{f}}"] &
    \mathbb{R}^{2}
\end{tikzcd}

相关内容