Register to reply

Increment (or decrement) a parameter in LaTeX

by robbins
Tags: decrement, increment, latex, parameter
Share this thread:
Nov14-09, 11:51 PM
P: 7
How can I increment or decrement a parameter in LaTeX?

For example, suppose I create an environment foo as follows:


I can write

<tabular data in seven columns>

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
\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?
Phys.Org News Partner Science news on
Final pieces to the circadian clock puzzle found
A spray-on light show on four wheels: Darkside Scientific
How an ancient vertebrate uses familiar tools to build a strange-looking head
Nov16-09, 04:44 PM
P: 7
This solution was posted by Joseph Wright on LaTeX Community:

"You don't want \let, you want to do things with numbers proper. The thing is that they then [need] to be assigned to TeX counters. You seem to want something like

\mycount #1\relax
\advance\mycount -1\relax

Here, I'm using a TeX count register to do the maths. You can do the same with a LaTeX counter, but I find this route a bit easier for going downward. TeX assigns count registers locally, so the above should work in most cases."

Thanks, Joseph.

Register to reply

Related Discussions
The smallest increment of time a human can percieve? Medical Sciences 19
Torsional pendulum, logarithmic decrement Engineering, Comp Sci, & Technology Homework 1
Torsional Pendulum, Logarithmic Decrement Introductory Physics Homework 1
Increment value of equvalent resistance when the resistances are parallel Introductory Physics Homework 2
Why does my post count not increment? General Discussion 2