summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/vertbars/vertbars.sty
blob: 9b24d2049648ae78bcc1b38b4075b12136973360 (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
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5
%% Bundled source file for the VERTBARS package
%%-------1---------2---------3---------4---------5
%% Please see the accompanying README for author,
%% license, documentation and installation information
%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{vertbars}[2018/12/16 v1.0c vertical bars in the margin]

\newcommand{\LNenv}{runninglinenumbers}
\DeclareOption{switch}{%
  \renewcommand{\LNenv}{runningpagewiselinenumbers}
  \PassOptionsToPackage{\CurrentOption}{lineno}
}

\DeclareOption{switch*}{%
  \renewcommand{\LNenv}{runningpagewiselinenumbers}
  \PassOptionsToPackage{\CurrentOption}{lineno}
}

\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{lineno}}
\ProcessOptions\relax
\RequirePackage{lineno}

% Code to add stuff at start and end of a pre-existing zero argument macro:
\newcommand{\addtodef}[3]{\begingroup
  \@temptokena{#2}%
  \toks@\expandafter{#1#3}%
  \edef\x{\endgroup
    \def\noexpand#1{\the\@temptokena \the\toks@}}%
  \x
}

% It's useful to preserve \cmd\baselineskip:
\newlength{\pwvbbl}
\setlength{\pwvbbl}{\baselineskip}

% Width of bars:
\newlength{\barwidth}
\setlength{\barwidth}{0.4pt}

% Horizontal space between bars:
\newlength{\barspace}
\setlength{\barspace}{0.5\linenumbersep}

\newcommand{\addtomakeLNL}{{\rule[-0.25\pwvbbl]{\barwidth}{1.1\pwvbbl}\hskip\barspace\relax}}
\newcommand{\pwvbLNL}{}

\newenvironment{vertbar}{%
  \par
  \pagewiselinenumbers
  \begin{\LNenv}%
    \addtodef{\pwvbLNL}{}{\addtomakeLNL}%
    \let\LineNumber\pwvbLNL
}{%
  \end{\LNenv}%
  \par
}