0

I have seen some examples that you can pass parameters to build a template such as \int_step_inline: you can write #1 to represent the current value of the loop. I wonder how it works and have some try.

As I know from TeXbyTopic, in every expansion, #1 is replaced by <parameter token1> and ## is replaced by # (here is a question, how is ### and #### replaced?).

But I do not sure what happens when #1 is passed as a parameter of a macro. It seems that #1 just replaces #n of the macro.

I have following example.

\def\a#1{\def\b##1{#1}}

If I have the right idea. \a{*#1*} is expande to \def\b#1{*#1*}, then \b{test} will get *test*. From the output, it seems that I'm right, but I want to know if I really get the right idea or there is some extra information that I ignored.

2

1 Answer 1

2

This might not be complete:

  • In <parameter text> like the #1#2 in \def\x#1#2{...}, # followed by a digit 1--9 denotes a parameter. And any other use cases of # raise error.
    • A special case is a <parameter text> ends with #. For example, \def\x#1#{...}. This means #1 is delimited by {.
  • In <replacement text>, #1 to #9 is treated corresponding parameter token and ## is treated as single #. Any other use cases of # raise error.
  • In other cases, for example as macro argument (\a{#1}), nothing special happens on #.

So you may use \def\a#1{\def\b##1{\def\c####1####{...}}}.

You must log in to answer this question.

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