summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ntabbing/ntabbing.sty
blob: 0442b58083d3260635777e205a0b865238a4d9d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
%% This file contains the ntabbing.sty
%% Written by Gideon Stupp stupp@math.tau.ac.il
%%
%% The ntabbing environment is an extension  of the tabbing environment.
%% Two commands added:
%% \label{} -  enumerates the and gives
%%            a reference to the line just like any \label operation.
%%
%% \reset   - Resets line numbering.
%%
\NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{ntabbing}[2000/03/20 v2.0 tabbing enhancements]

\newcounter{g@linecounter}
\newbox\g@numbox%
\newdimen\numboxsize          \numboxsize=1.5em%
\newbox\g@seperator           \setbox\g@seperator=\hbox{:}

\gdef\g@setnumbox{
      \refstepcounter{g@linecounter}%
      \global\setbox\g@numbox=\hbox to\numboxsize{\hfil \theg@linecounter\copy\g@seperator\hfil }
}

% newlabel increments counter and set numbox. Empty labels are not passed to old label.
\gdef\g@newlabel#1{\g@setnumbox\ifx#1\@empty\else\g@oldlabel{#1}\fi}

% Change tabbing startline to give empty default value to numbox
\gdef\g@newstartline{\global\setbox\g@numbox=\hbox to\numboxsize{}
    \g@oldstartline}

% Change tabbing stopline to print numbox before current line.
\gdef\g@newstopline{\unskip\@stopfield\if@rjfield
\global\@rjfieldfalse
   \@tempdima\@totalleftmargin \advance\@tempdima\linewidth
 \hb@xt@\@tempdima{\@itemfudge\box\g@numbox\hskip\dimen\@curtabmar
   \box\@curline\hfil\box\@curfield}\else\@addfield
   \hbox{\@itemfudge\box\g@numbox\hskip\dimen\@curtabmar\box\@curline}\fi}

%ntabbing environment definition.
\def\ntabbing{

\def\reset{\setcounter{g@linecounter}{0}}

\let\g@oldstopline=\@stopline
\let\@stopline=\g@newstopline

\let\g@oldstartline=\@startline
\let\@startline=\g@newstartline

\let\g@oldlabel=\label
\let\label=\g@newlabel

\let\g@oldcaption=\caption

% redefine \caption{} to support the old \label
\def\caption##1{\let\label=\g@oldlabel \g@oldcaption{##1}}
 \tabbing

} % Of ntabbing.

\def\endntabbing {\endtabbing}