1

TeX Modes are still fuzzy to me. Here's a question to clarify the issue: If a function is passed an integer, say m, as parameter #1, how to create a macro parameter ##m from #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: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
  • 1
    you can do this, as shown below, but it's a rather unusual thing to do, what's the use case here? It's worth noting that tex doesn't really have integers just tokens 12 is the two tokens 1 and 2, and #1 are two tokens that get replaced by the 1st argument, and ## are two tokens that get replaced by # May 26, 2018 at 0:11

1 Answer 1

1

You were nearly there, just one letter changed:

enter image description here

\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}
1
  • Y doesn't \cs_set accept other signatures (No, Nf)?
    – Erwann
    May 28, 2018 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .