# Multiple vertical rules along text – by using \leaders?

I want to draw individual vertical rules on the left side of consecutive paragraphs/vertical boxes covering the vertical skips. In my case for every paragraph/vertical box, there can be different vertical rules. Each paragraph itself is short and not breakable, that is why I am calling them vertical boxes. The rules of a paragraph should start directly after the previous paragraph and cover the vertical skip between the two paragraphs. The main problem is how to cover this skip properly with vertical rules.

1. one solution aimed at source code listings (where new lines are obeyed), and another solution using the package framed: How to make continuous (but breakable) vertical rule along left side of paragraph?

2. using package mdframed (which is based on framed): Left-hand vertical rule applied to flalign environment with automatic pagebreak

3. avoiding to write a new output routine seems impossible: Can I write a macro for placing a vertical, breakable rule along arbitrary paragraphs without an output routine?

The common approach of 1. and 2. is to do the page breaking "manually" by own code instead of completely automatically by TeX. That is, to create a vertical list of all the lines or paragraphs, and use \vsplit to cut this list into piece to fill the pages. Another common characteristic is that this takes at least 50 lines of TeX code and is not easy...

I came about box leaders and it seems that \leaders could do the job. I am wondering whether my attempts can be made working.

Attempt 1: Tell TeX never to insert any glue after a paragraph and instead insert a standard amount of glue. (The amount can be changed setting \currentvskip.)

Attempt 2: Ask TeX how much space is inserted between two paragraphs (during or after page breaking) and then cover this vertical skip with rules.

Not tried since it seems complicated: extending the framed package to work for multiple rules...

The attempts are not completely working. For example, the vertical rules are not continuous on one page, and there is something wrong with the usage of \lastskip. The following document shows my attempts. Is there a way to fix one of them?

\documentclass[12pt,english]{article}
\usepackage{babel}
\usepackage{blindtext}

\def\rules{\vrule width2pt \kern8pt \vrule \kern10pt}
\def\ruless{\vrule width2pt \kern8pt \vrule \kern8pt \vrule \kern10pt}

\newbox\vrules \setbox\vrules=\vbox{\hbox{\vrule width0pt height1pt \rules}}
\newbox\vruless \setbox\vruless=\vbox{\hbox{\vrule width0pt height1pt \ruless}}
\newbox\vl

\def\line#1{\setbox\vl=\vbox{\hbox{\rules \strut #1\unskip}}%
\def\linee#1{\setbox\vl=\vbox{\hbox{\ruless \strut #1\unskip}}%

\def\minibox{\begin{minipage}{5cm}\blindtext\end{minipage}}

\begin{document}
\parindent0pt \lineskip20pt \xdef\currentvskip{\lineskip}
\section*{Attempt 1}
\line{\minibox\bigskip}
{\edef\currentvskip{\bigskipamount}%
\linee{The vertical rules on the left should continue above (problem with bigskip)!}
}
\linee{One more line...}
\line{The vertical rules on the left should not continue below because of the page break.}
\line{\minibox}

\section*{Attempt 2}
\vbox{\hbox{\rules \minibox \bigskip}}%
\vbox{\hbox{\ruless \strut The vertical rules on the left should continue above!}}
\vbox{\hbox{\ruless \strut One more line...}}
\vbox{\hbox{\rules \strut The vertical rules on the left should not continue below because of the page break.}}
\vbox{\hbox{\rules \minibox}}
\end{document}

-

If you first build your paragraphs off the main vertical list you can remove inter box skips and replace them by leaders:

\documentclass{article}

\textwidth.7\textwidth
\textheight.7\textheight

\parskip\baselineskip

\def\a{One two three four. }
\def\b{\refstepcounter{enumi} \Roman{enumi} \a\a\a}
\def\c{\b\a\a\b}

\makeatletter

\def\zboxes{\setbox\z@\vbox\bgroup\bgroup}
\def\endzboxes{\endgraf\egroup\egroup
\unvbox\z@}

\long\def\zbox#1#2{%
\par
\noindent\hbox{\vrule\@width#1\kern#1\relax
\parbox[t]{\dimexpr\textwidth-(#1)*2\relax}{#2}}%  2 times 2pt is 4pt not 22pt
\ruleskip{#1}}

\def\ruleskip#1{{%
\par
\setbox0\lastbox
\count@\z@
\skip@\z@skip
\loop
\@tempswafalse
\ifnum\lastnodetype=13
\unpenalty
\@tempswatrue
\fi
\ifnum\lastnodetype=11
\unskip
\@tempswatrue
\fi
\if@tempswa
\repeat%
\unskip\unskip\unskip
\penalty\z@
\nobreak
\nointerlineskip
\box\z@}}

\makeatother

\begin{document}

\begin{zboxes}
\zbox{1pt}{\c}

\zbox{3pt}{Hello. \c}

\bigskip

\zbox{5pt}{\c\c\b\c}

\bigskip

\zbox{3pt}{Red \b\c}

\zbox{4pt}{Yellow \a\c}

\zbox{2pt}{Goodbye. \b\c}

\end{zboxes}

\end{document}

-
Clear code, down to the point! - So \lastbox, \lastskip, etc. cannot be used when TeX is building the pages, that is in the external vertical mode. But they work in the internal vertical mode, which is started by \vbox in your code. In this mode the vertical material with possible points for page breaking (but not broken yet) is collected. I think I have understood... –  e-birk Feb 3 '13 at 1:29
Yes sounds like you got it:-) –  David Carlisle Feb 3 '13 at 1:49
Focusing on separate rules, I replaced the line \leaders\vrule\@width#1..... with \leaders\copy\vrules..... where \vrules is as in my code above. That introduces some vertical white space - probably 1pt. If I reduce the height in \setbox\vrules=\vbox{\hbox{\vrule width0pt height0.01pt \rules}} then the white space will be invisible. Is this approach okay or should a different approach be chosen? –  e-birk Feb 3 '13 at 16:41
If you want multiple rules rather than just different thickness you need to do something like that: you could put a small negative kern in the leader box so it overlaps and you get no gap, but if you put too much it will overlap the text. –  David Carlisle Feb 3 '13 at 17:04