[texhax] Macros that define other macros

Pablo Mayckon pmsf at alu.dc.ufc.br
Mon Dec 3 01:04:45 CET 2012


Dear mates,

I would like to define macros that in their turns define other macros, in the
spirit of the following erroneous TeX code:

---------------------
\def\macromaker#1{%
  \def\submacro#1{I am submacro #1}%
  \def\anothersubmacro#1{I am another submacro #1}}

\macromaker{test}
\submacrotest
\anothersubmacrotest
---------------------

With the code above I expected to define macros "\submacrotest", which would
print "I am submacro test", and "\anothersubmacrotest", printing "I am another
submacro test", but apparently none gets even defined.

Could someone please explain "what's going on" here? My background: I've been
using LaTeX for years, I am a computer scientist and C/C++ programmer, and
read parts of the TeXbook, but have not found the opportunity to master it to
the level where I could do the TeX programming that I have always wanted to
do.

One last thing, so that I can understand it better: what if I wanted
"\submacrotest" to have two parameters and to print them, say, "I am submacro
test and received #1 and #2"?

Thanks in advance, --Pablo.

------------------------
Pablo M. S. Farias
http://lia.ufc.br/~pmsf/



More information about the texhax mailing list