Tabbing and auto-numbering

29 views
Skip to first unread message

Hasan Qunoo

unread,
Oct 13, 2009, 1:03:17 PM10/13/09
to latexus...@googlegroups.com
Dear All,

I am using Tabbing to write a number of C like programs. I want to
number these lines either on the left side as usual or one the right
side as a comment. I am also referring to these numbers in the text. I
can do that manually but it involves a lot of updates per change.

I tried using  \ref and \label but they refer to the section number. I
know that I can use equations or enumerates to reset the numbering but
will have issues with alignment and style. I also found some people
advocating amsmath and mathenv. However, using these two packages
results in a lot of modifications that I would like to avoid.

Please advice,

Thanks in advance.

Hasan

Werner Grundlingh

unread,
Oct 13, 2009, 1:15:29 PM10/13/09
to LaTeX Users Group
Hasan,

Use the listings package, since it is designed specifically for your
requirements - line numbers, indentation, referencing, comments, etc.
It is available online via CTAN from:
http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=listings
Browse the package documentation to get an idea of the capabilities of
the package.

Werner

Hasan Qunoo

unread,
Oct 13, 2009, 4:35:49 PM10/13/09
to latexus...@googlegroups.com
Thanks a lot,

I can not use listings as it does not accept math. Any other ideas?

Hasan

2009/10/13 Werner Grundlingh <wgrun...@gmail.com>:
Message has been deleted

Werner Grundlingh

unread,
Oct 13, 2009, 5:01:14 PM10/13/09
to LaTeX Users Group
On Oct 13, 1:35 pm, Hasan Qunoo <hass...@gmail.com> wrote:
> Thanks a lot,
>
> I can not use listings as it does not accept math. Any other ideas?
>
> Hasan

Hasan,

This is not true. Listings is set up to accept math, although this is
not the default case, since programming languages have different
control mechanisms and operators. If you're interested in using
LaTeX's math mode inside a listing environment, use the mathescape
option:

\begin{lstlisting}
// \upshape calculate $a_{ij}$
$A[i][j]$ = A[j][j]/A[i][j];
\end{lstlisting}

versus

\begin{lstlisting}[texcl]
// \upshape calculate $a_{ij}$
A[i][j] = A[j][j]/A[i][j];
\end{lstlisting}

versus

\begin{lstlisting}[mathescape]
// calculate $a_{ij}$
$a_{ij} = a_{jj}/a_{ij}$;
\end{lstlisting}

Additionally, the mathescape options allows the addition of (almost?)
anything (La)TeX-like... even including graphics. See p 54 of the
documentation for an example.

Werner

Donald Arseneau

unread,
Oct 14, 2009, 4:05:13 AM10/14/09
to LaTeX Users Group
On Oct 13, 10:03 am, Hasan Qunoo <hass...@gmail.com> wrote:
> I am using Tabbing to write a number of C like programs. I want to
> number these lines either on the left side as usual or one the right
> side as a comment. I am also referring to these numbers in the text.

Use \refstepcounter instead of \stepcounter for the automatic
numbering. Each tabbing item is in a local group, so you must
put the \label after \refstepcounter in the same item.

But also check if existing packages can do what you need.


Donald Arseneau
Reply all
Reply to author
Forward
0 new messages