%%%%%%%%%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
}

