[texhax] recursive \defs

Neal H. Walfield neal at walfield.org
Thu Aug 16 13:07:23 CEST 2012


Hi,

I have a large \def that takes some parameters.  I want to define a
convenience macro, which I use from my outer definition, and which
also takes parameters.  Consider:

  \documentclass{article}
  
  \begin{document}
  
  \def\foo#1{%
    \def\bar#1{%
      xxx #1 yyy%
    }%
    \bar{aaa #1 bbb}%
  }
  
  \foo{!}
  
  \end{document}

When I compile this, I get:

  ! Use of \bar doesn't match its definition.
  \foo #1->\def \bar #1{xxx #1 yyy}\bar {
                                         aaa #1 bbb}
  l.12 \foo{!}
            
This is because the #1 in the \bar definition is expanded to the value
of the argument passed to \foo.  How do I escape the #1 in bar's
definition?  What are good approaches to do this type of thing?

Thanks,

Neal



More information about the texhax mailing list