The original question is below (it was a bad simplification of the problem I had and also before being edited, it also contained major syntax errors). The problem that originated the question is why \test
and \ttest
work but \tttest
gives ! Package pgfbasematrix Error: Single ampersand used with wrong catcode.
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\def\test #1.{#1}
\def\ttest #1.{\node{#1}}
\def\tttest #1, #2.{\node{#1}; & \node{#2};}
\begin{document}
\begin{tikzpicture}
\matrix [draw,row sep=1cm,nodes=draw]
{\node {10}; & \node {5}; \\
\node {5}; & \node {\test 10.}; \\};
\end{tikzpicture}
\newpage
\begin{tikzpicture}
\matrix [draw,row sep=1cm,nodes=draw]
{\node {10}; & \ttest 5. ; \\
\node {5}; & \node {\test 10.}; \\};
\end{tikzpicture}
\newpage
\begin{tikzpicture}
\matrix [draw,row sep=1cm,nodes=draw]
{\tttest 10, 5. \\
\node {5}; & \node {\test 10.}; \\};
\end{tikzpicture}
\end{document}
Original question:
Say Bob (our fictitious character) has to type long systems of equations using AMS-TeX all day long. Poor Bob is very tired but one day he has a revelation: The TeX Book! Bob reads chapters 7 and 20 and thinks he solved his problem.
Instead of typing:
\begin{align*}
& 2x + & 10y =& 20 \\
& x - & y =& 10 \\
\end{align*}
Bob creates a macro and thinks the problem has been solved:
\def\bobmacro #1, #2, #3{ & #1 & #2 & #3 \\}
\begin{align*}
\bobmacro{ 2x+, 10y=, 20}
\bobmacro{ x-, y, 10}
\end{align*}
But alas! The macro does not compile, Bob suspects the problem is with the cat code &
and perhaps also //
. He knows he can neutralize them by using \string
and doing that the code compiles but the outcome is again not the one desired.
Bob goes to TeX.SE and reads questions about \csname
and \scantokens
. The last one looks promising but he can't find a simple example on Google.
Bob seems more confused then when he started. He wonders if: Is there a TeX/LaTeX or e-TeX way of implementing the idea behind his macro?
\bobmacro
is not called according to its definition. There is nothing problematic about catcodes (which usually only cause problems if you want to change them somewhere), and&
comes out of the macro exactly as if you typed it explicitly. Note however that usingalign
one should have&=
rather than=&
to get the correct alignment (again independent of defining macros), so the=
should be in the third argument, not the second. – Marc van Leeuwen May 13 '14 at 13:54