2

Possible Duplicate:
What is the meaning of double pound symbol (##1) in an argument?

I'm quite sure this question has been asked many times but I can't find the answer.

I'd like to make a macro defining a new macro but I can't get the arguments working. How do I escape the parameter place-holders e.g. #1 for the inner command? Here is an absolutely senseless minimal example:

\documentclass{article}
\newcommand{\defprint}[1]{%
    \newcommand{\print}[1]{#1\#1}
}
\begin{document}

\defprint{foo}
\print{bar}
\print{boo}

\end{document}

Gives "foo#1 foo#1" but I want it to be "foobar fooboo".

Additionally I'd like to know how to do the same in plain Tex using \def. I'd expect something like the following, but the backslash seems to be the wrong kind of escape character too.

\documentclass{article}
\def\defprint#1{%
    \def\print\#1{#1\#1}
}
\begin{document}

\defprint{foo}
\print{bar}
\print{boo}

\end{document}
5
  • Tricky one to search for! I think your question will be answered by reading this one: tex.stackexchange.com/q/42463/86 If so, we'll probably close this as a duplicate of that. If not, please comment (or edit your question) to specify to what still confuses you. – Andrew Stacey Oct 12 '12 at 8:31
  • Following links also led me to tex.stackexchange.com/q/51819/86 which looks useful as well. – Andrew Stacey Oct 12 '12 at 8:33
  • I added the nesting tag to the presumable original question. – lockstep Oct 12 '12 at 8:33
  • Ok thanks Andrew, it's that simple when one knows what to search for. Thanks a lot, the question can be closed. Hopefully it helps others to find the answer as well. – buergi Oct 12 '12 at 8:38
  • Great! That's the good thing about duplicates: each makes it easier to find the original question and answer as it adds more search terms. – Andrew Stacey Oct 12 '12 at 8:41