[OS X TeX] Concatinating backslash and id

Frank STENGEL fstengel at mac.com
Wed May 10 18:57:40 EDT 2006


Le 10 mai 06 à 21:09, Peder Axensten a écrit :

> I need to define a macro, but I have the macro name without a  
> backslash.
> How can I concatenate them (\ and #1, below)?
>
> \newcommand{\mynewcommand}[2]{%
>     \newcommand{\#1}{#2}%
> }

Try:

\newcommand{\mynewcommand}[2]{%
	\expandafter\newcommand\csname #1\endcsname{#2}
}

It should do the trick. The \csname ...\endcsname does the  
concatenation you desire. The \expandafter is there so that the name  
"\#1" is built first and then passed to \newcommand. I'm sure Morten  
H. could be more precise on this and give a more robust way of doing  
it...
-- 
Frank STENGEL (fstengel<at>mac.com)

------------------------- Info --------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
          & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/




More information about the MacOSX-TeX mailing list