# [texhax] Simple line numbering for tabular environments

Reinhard Kotucha reinhard.kotucha at web.de
Wed Jul 18 23:14:10 CEST 2007

James Smith writes:

> I have tried to create an enviroment for my more abstract code listings,
> the ones that require assertions and maths bits. Here is what I have so
> far:
>
> \begin{tabular*}{\linewidth}
> {l>{$}l<{$}>{$}l<{$}}
> \hline\\
> 1&\mathsf{process\_file}(*f:file)\{\\
> 7&\}\\
> \\
> \hline
> \end{tabular*}
>
> I'm almost happy with this. I need the maths environment, for a start,
> so I can't use any packages that offer line numbering but take away the
> maths formatting. I have found, however, that constantly renumbering the
> lines when I change the listings becomes tiresome, so can I automate
> this process. I'd like to keep the tabular* environment if at all
> possible. I've had a look at the lineno package, amognst others, but
> find them daunting. Can anyone get me started? I don't need to wrap
> these environments over more than one page or anything like that.

You can replace line numbers by a macro which uses a count register
and increases the value of the count register by one whenever it is
called.

Related LaTeX commands are \newcounter and \addtocounter.

However, obviously you are a programmer.  Isn't it easier to write a
little program which converts the code to something which can be read
by TeX?  Almost everything can be done in TeX/LaTeX but sometimes you
can save a lot of time with a little program written in your favorite
programming language which does the conversion.

You can include LaTeX code with \input{somefile.tex}.

Regards,
Reinhard

--
----------------------------------------------------------------------------
Reinhard Kotucha			              Phone: +49-511-4592165
Marschnerstr. 25
D-30167 Hannover	                      mailto:reinhard.kotucha at web.de
----------------------------------------------------------------------------
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.
----------------------------------------------------------------------------