TeX 模式对我来说仍然很模糊。这里有一个问题可以澄清这个问题:如果一个函数传递了一个整数,比如 m,作为参数 #1,那么如何从 #1 创建宏参数 ##m?
\documentclass{minimal}
\usepackage{expl3}
\ExplSyntaxOn
% Naive approach to create macro parameters:
\cs_set:Npn \__foo_code:n #1{(## #1)} % Wanted: concac ## and #1<-int, (an integer) to yiel
\cs_set:Npn \__bar_code:n #1{[## #1]}
\cs_set:Npn \__baz:nn #1 #2
{
\__foo_code:n{1}
\__bar_code:n{2}
}
\begin{document}
\__baz:nn{x}{y} % Wanted: (x)[y]
% Getting: ! You can't use `macro parameter character #' in horizontal mode.
\ExplSyntaxOff
\end{document}
答案1
您几乎已经完成了,只需改变一个字母:
\documentclass{minimal}
\usepackage{expl3}
\ExplSyntaxOn
% Naive approach to create macro parameters:
\cs_set:Npn \__foo_code:n #1{(## #1)} % Wanted: concac ## and #1<-int, (an integer) to yiel
\cs_set:Npn \__bar_code:n #1{[## #1]}
\cs_set:Npx \__baz:nn #1 #2
{
\__foo_code:n{1}
\__bar_code:n{2}
}
\begin{document}
\__baz:nn{x}{y} % Wanted: (x)[y]
% Getting: ! You can't use `macro parameter character #' in horizontal mode.
\ExplSyntaxOff
\end{document}