I'm looking for a way in Plain TeX to make a continuous vertical rule along the left side of a paragraph (or arbitrary block of text), such that it observes normal page-break rules. I started with the following, which looks exactly how I want, except of course it has the undesirable side-effect of preventing page breaks for large runs of text, since it uses \vbox:
% Definition
\def\codeblock#1{%
\hbox{%
{\vrule width .6pt}%
\hskip 1em%
\vbox{\tt #1}%
}%
}
% Example
\codeblock{%
\hbox{void main(int argc, char *argv[]) \char123}%
\hbox{{\ }{\ }printf("Hello, world!{\char92}n");}%
\hbox{\char125}%
}
As a workaround, I'm currently resorting to breaking things into separate lines and a series of kludged non-continous-but-overlapping vertical rule segments:
% Definition
\def\codeline#1{%
\hbox{%
\vrule width .6pt height .85em depth .46em%
\hskip 1em%
\tt #1%
}%
\vskip -.11em%
}
% Example
\codeline{void main(int argc, char *argv[]) \char123}
\codeline{{\ }{\ }printf("Hello, world!{\char92}n");}
\codeline{\char125}
In a perfect world, I'd like to simply pass an arbitrary block of text to a macro and have it apply normal pagination rules to the block of text, while at the same time making a vertical rule down the left. I don't have much experience with TeX but I suspect the answer is that it's not trivial?
While typing this question, a similar question appeared in the margin. I will definitely give that a try — and it looks really powerful and well thought out — but it also seems quite heavyweight for something that I would think ought to be reasonably straightforward. Also, not that I have anything against LaTeX, but I'd prefer to use a solution as close to Plain TeX as possible, so that I can have some hope of understanding it.



\advance\dimen0 by -1exand thedepth-1ex, since I want the rules to extend the full heights of lines rather than starting and ending in the middle. I think I also want the rule to line up with the left text margin (rather than offset 10pt to the left of it) since this is for code interleaved with documentation... but this is really perfect to start with. Thank you so much. – Todd Lehman Dec 14 '11 at 00:26\codeblockmacro for you. – Justin Bailey Dec 17 '11 at 00:46\zeroboxand\nullsignificant? Also,\parboxis a LaTeX command. This might create problems if your code is run with LaTeX. – Ahmed Musa Dec 17 '11 at 01:23\zeroboxisn't special. It's not actually used and should be deleted, I think. Same for\charbox. – Justin Bailey Dec 17 '11 at 08:08\raggedbottom). Thecodeblockenvironment leaves an extra newline if you have empty lines before the closing}; – Justin Bailey Dec 17 '11 at 17:24