[texhax] Macros that define other macros

Philip TAYLOR P.Taylor at Rhul.Ac.Uk
Mon Dec 3 01:24:21 CET 2012


Short answer : you cannot achieve what you are trying
to achieve without using \csname ... \endcsname.  This
is the nearest you will get without those :

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

\macromaker {test}
\submacro test
\anothersubmacro test
\end

Fuller answer (maybe) when I am less busy.
Philip Taylor
--------
Pablo Mayckon wrote:
> 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/
>
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
>
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org
>

-- 
MIL-05991/237/2012-B : Any loss of data or other computer 
malfunction resulting directly or indirectly from the use of 
Linux will be regarded as a self-inflicted injury and treated 
accordingly.  Users of Mac OS/X will be assumed to be insane. 
You have been warned ...


More information about the texhax mailing list