Two things here. First, \newcommand is a LaTeX command, whereas \csname is a TeX primitive command. So the syntax is different. Second, \csname does not define anything: you need to use the TeX primitive \def. This also requires the \expandafter primitive.
To create a macro with arguments using \def, you give the arguments as #1, #2, and so on:
and so with \csname:
Code: Select all
\expandafter\def\csname MyMacro\endcsname#1{Some code #1}
What happens here is that TeX sees the \expandafter, and moves on to \csname (constructing the name)
before using \def to create the new macro. If you try this without the \expandafter things go wrong.
LaTeX provides and internal macro which covers up some of the messy detail:
Code: Select all
\makeatletter
\@namedef{MyMacro}#1{Some code #1}
\makeatother
has exactly the same effect as the primitive version above.