- #1
robbins
- 7
- 0
How can I increment or decrement a parameter in LaTeX?
For example, suppose I create an environment foo as follows:
\newenvironment{foo}[2]{\begin{tabular}{*{#1}c*{#2}r}}{\end{tabular}}
I can write
\begin{foo}{4}{3}
<tabular data in seven columns>
\end{foo}
But in my application, if the first parameter is n, then second is always n-1. Is there a way to write this that passes only one parameter (in this case n), but which will produce the table with n + (n - 1) columns as in the environment foo?
Decrementing the parameter #1 inside the newenvironment -- if it is possible -- would surely work, but I don't know how to do it.
Note: The snippet
\let\temp#1
\advance\temp by -1
doesn't work because if I pass the parameter 4, \temp takes the value 'the character 4', which can't follow the \advance command.
I'm stuck. Any help?
For example, suppose I create an environment foo as follows:
\newenvironment{foo}[2]{\begin{tabular}{*{#1}c*{#2}r}}{\end{tabular}}
I can write
\begin{foo}{4}{3}
<tabular data in seven columns>
\end{foo}
But in my application, if the first parameter is n, then second is always n-1. Is there a way to write this that passes only one parameter (in this case n), but which will produce the table with n + (n - 1) columns as in the environment foo?
Decrementing the parameter #1 inside the newenvironment -- if it is possible -- would surely work, but I don't know how to do it.
Note: The snippet
\let\temp#1
\advance\temp by -1
doesn't work because if I pass the parameter 4, \temp takes the value 'the character 4', which can't follow the \advance command.
I'm stuck. Any help?