Code: Select all
\begin{python}
print r"\begin{tabular}{r@{) }l}"
Qlist=range(11)
for i in Qlist:
print r"%i & \ref{%i} \\" % (i+1,i+1)
print r"\end{tabular}"
\end{python}
The code works fine on its own and there is no problem. My objective is to wrap this code in a latex command. I tried the following:
Code: Select all
\def\PrintAnswers{
\begin{python}
print r"\begin{tabular}{r@{) }l}"
Qlist=range(11)
for i in Qlist:
print r"%i & \ref{%i} \\" % (i+1,i+1)
print r"\end{tabular}"
\end{python}}
I am not sure why. In python the spacing matters. Is it possible that this could be because the command \PrintAnswers does not expand exactly to the desired code? Is there a way I can define a command \PrintAnswers such that when the latex encounters it, it expands it to! Use of \@python doesn't match its definition.
<argument> \def \reserved@a {
\def \@currenvir {tabular}\edef \@currenvline {...
l.212 %\end{python}
Code: Select all
\begin{python}
print r"\begin{tabular}{r@{) }l}"
Qlist=range(11)
for i in Qlist:
print r"%i & \ref{%i} \\" % (i+1,i+1)
print r"\end{tabular}"
\end{python}