Thursday, June 19, 2008

 

DEFINING YOUR OWN COUNTERS AND LABELS in Latex

From my latex notes at http://rasmusen.org/a/latex-rasmusen.txt

This is tricky in Latex, because while you can define new counters, I can't see how you would attach their values to labels. The \label command can only be used in environments that have their own counters (such as \begin{equation}), and you can't fool those environments into adding to a counter without having them print the value on the printed page somewhere. So I used Tex programming, like this. I create a new counter named \fignum and then attach it to a label called \1f, \2f, and so forth, advancing the counter in between. I used \edef rather than \def because \edef inserts the value at the particular time, while \def would repeat the command \number\fignum each time \1f was written.

\newcount\fignum\fignum=1

\edef\1f{\number\fignum}

\advance\fignum by 1

\edef\2f{\number\fignum}

Example: Figure \1f says this. The second part of it, Figure \1fa, says something different. Figures \2f and \2f-a say something still different.

This is plain Tex, not Latex.

You need to write backslash-1-f rather than backslash-f-1. I'm not sure why-- it must be that the number gets interpreted as doing something special to the definition rather than being part of the name.

You have to remember to put your definitions earlier in the document than when you use the term defined. You could put them all the start, actually, but then you might forget to re-order them when you change the order of the diagrams.

I think you can advance the fignum variable by a negative number if you want to.

Labels: ,

 

To view the post on a separate page, click: at (the permalink).