+% \subsection{The \package{svcolour} package}
+%
+% This is in a separate package to avoid dragging in the \package{color}
+% package if it's unwanted.
+%
+% I prefer English spellings. Here's a trivial redirection for Americans.
+%
+% \begin{macrocode}
+%<*color>
+\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{svcolour}}
+\ProcessOptions
+\RequirePackage{svcolour}
+%</color>
+% \end{macrocode}
+%
+% And now we can start the thing properly.
+%
+% \begin{macrocode}
+%<*colour>
+\RequirePackage{color}
+% \end{macrocode}
+%
+% \begin{macro}{\@snarfcolour}
+%
+% Reading a colour specification is something we'll need to do a few times,
+% so an abstraction is useful. Its single argument is a continuation to
+% which we pass a colour-spec acceptable to the |\color| command. (This is
+% the same code as found in the \package{mdwtab} package. Remember to keep
+% them in step.)
+%
+% \begin{macrocode}
+\def\@snarfcolour#1{%
+ \@ifnextchar[{\@snarfcolour@i{#1}}{\@snarfcolour@ii{#1}{}}%
+}
+\def\@snarfcolour@i#1[#2]{\@snarfcolour@ii{#1}{[#2]}}
+\def\@snarfcolour@ii#1#2#3{#1{#2{#3}}}
+% \end{macrocode}
+%
+% \end{macro}
+%
+% \begin{macro}{\svcolourline}
+% \begin{macro}{\svcolorline}
+%
+% Snarf the option, and plot the coloured bar. Note the penalties which are
+% meant to stick the glue and leaders onto the colour specials.
+%
+% \begin{macrocode}
+\def\svcolourline{\@snarfcolour\svcl@i}
+\def\svcl@i#1#2{%
+ \skip@\wd#2%
+ \advance\skip@\parfillskip%
+ \advance\skip@.2em%
+ \strut%
+ \kern.2em%
+ \begingroup\color#1\nobreak\leaders\vrule\hskip\skip@\endgroup%
+ \nobreak\hskip-\skip@%
+ \kern.2em%
+ \box#2%
+ \nobreak\hskip-\rightskip\vadjust{}%
+ \par%
+}
+\let\svcolorline\svcolourline
+% \end{macrocode}
+%
+% \end{macro}
+% \end{macro}
+%
+% Done!
+%
+% \begin{macrocode}
+%</colour>
+% \end{macrocode}
+%
+% \subsection{The \package{svsplit} package}
+%
+% \begin{macrocode}
+%<*split>
+\RequirePackage{sverb}
+% \end{macrocode}
+%
+% \begin{environment}{splitverb}
+% \begin{environment}{splitverb*}
+%
+% The basic environments are simple enough.
+%
+% \begin{macrocode}
+\def\splitverb{\listinghook\sv@readenv\splitverb@}
+\expandafter\def\csname splitverb*\endcsname%
+ {\listinghook\begingroup\@noligs\svsplit@star}
+\def\svsplit@star#1{\endgroup\splitverb@{#1}{\end{splitverb*}}}
+% \end{macrocode}
+%
+% \end{environment}
+% \end{environment}
+%
+% \begin{macro}{\splitverb@}
+%
+% Even this isn't so bad, really.
+%
+% \begin{macrocode}
+\def\splitverb@#1#2{\sv@startlisting\sv@read{#1}\svsplit@line{\svafter#2}}
+% \end{macrocode}
+%
+% \end{macro}
+%
+% \begin{macro}{\svsplit@line}
+%
+% For the sake of readability (and maybe saving a few tokens), we define some
+% synonyms for \TeX's scratch registers. |\svsplit@remain| will be a
+% |\global| register containing the remaining horizontal space on the line;
+% |\svsplit@indent| is a local register containing the amount of initial
+% whitespace on the line.
+%
+% \begin{macrocode}
+\dimendef\svsplit@remain=1
+\dimendef\svsplit@indent=2
+% \end{macrocode}
+%
+% The switch |\svsplit@| is set if we've found a good place to split the
+% current line.
+%
+% \begin{macrocode}
+\newif\ifsvsplit@
+% \end{macrocode}
+%
+% And finally a delimiter. This is the same one I use everywhere else.
+%
+% \begin{macrocode}
+\def\q@delim{\q@delim}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\begingroup
+\catcode`\~=\active \lccode`\~=32
+\catcode`\!=\active \lccode`\!=9
+\lowercase{\endgroup
+% \end{macrocode}
+%
+% So far, so good. The |\svsplit@line| macro is given a line of text. We
+% initialize |\svtab| to be a \emph{single} space, |\svsplit@remain| to be
+% the text width, and |\svsplit@indent| to zero. Then we embark on the first
+% loop, which attempts to find the width of the leading whitespace.
+%
+% \begin{macrocode}
+\def\svsplit@line#1{%
+ \divide\svtab8%
+ \global\svsplit@remain\linewidth%
+ \svsplit@indent\z@%
+ \sv@emptybox\tw@%
+ \let\next@\svsplit@findindent%
+ \next@#1\q@delim%
+}
+% \end{macrocode}
+%
+% A straightforward tail-recursive loop finds out how much whitespace there
+% is at the start of the current line. Note that |\next@| is already set up
+% for the optimized case of continuing the loop. Also, if we reach the end
+% then this is a blank line, so only emit something if we didn't see the
+% end-marker. This is the only place we need to check for this.
+%
+% \begin{macrocode}
+\def\svsplit@findindent#1{%
+ \ifx~#1%
+ \advance\svsplit@indent\svtab%
+ \else\ifx!#1%
+ \dimen@8\svtab%
+ \divide\svsplit@indent\dimen@%
+ \multiply\svsplit@indent\dimen@%
+ \advance\svsplit@indent\dimen@%
+ \else\ifx\q@delim#1%
+ \if@matched\else\svline\tw@\fi%
+ \let\next@\relax%
+ \else%
+ \def\next@{\svsplit@scanline{#1}}%
+ \fi\fi\fi%
+ \next@%
+}
+% \end{macrocode}
+%
+% Now we have to actually scan the line to find breakpoints. We build the
+% current unbreakable chunk in |\box|~0. When we find a breakpoint, we close
+% the box, maybe stretch it to take into account trailing space, and attach
+% it to |\box|~2, which is gathering the current line. If |\svsplit@remain|
+% hits zero then we flush |\box|~2 to the output and continue on the next
+% line with a (more-or-less) clean slate.
+%
+% If there's no breakpoint then we're hosed. In that case, we just insert a
+% (|\normalfont|) hyphen and eject what we've got.
+%
+% Note that this assumes that the indentation will fit. If not, then we're
+% deeply stuffed.
+%
+% \begin{macrocode}
+\def\svsplit@scanline{%
+ \svsplit@false%
+ \let\next@\svsplit@char%
+ \setbox\z@\hbox\bgroup%
+ \kern\svsplit@indent%
+ \global\advance\svsplit@remain-\svsplit@indent%
+ \next@%
+}
+% \end{macrocode}
+%
+% Scanning a character isn't so bad, if we take it a step at a time.
+%
+% \begin{macrocode}
+\def\svsplit@char#1{%
+% \end{macrocode}
+%
+% If the character is a space or a tab, then we call |\svsplit@space| which
+% knows about adding breakable whitespace. For tabs, this involves computing
+% the correct tab size.
+%
+% \begin{macrocode}
+ \ifx~#1%
+ \svsplit@space\svtab%
+ \else\ifx!#1%
+ \@tempdima\linewidth%
+ \advance\@tempdima-\svsplit@remain%
+ \@tempdimb\@tempdima%
+ \dimen@8\svtab%
+ \divide\@tempdimb\dimen@%
+ \multiply\@tempdimb\dimen@%
+ \advance\@tempdimb\dimen@%
+ \advance\@tempdimb-\@tempdima%
+ \svsplit@space\@tempdimb%
+% \end{macrocode}
+%
+% We might have reached the end of the line. If so, then we finish off.
+%
+% \begin{macrocode}
+ \else\ifx\q@delim#1%
+ \let\next@\svsplit@done%
+% \end{macrocode}
+%
+% Otherwise it's a normal character. If there's not enough space then force
+% a break.
+%
+% \begin{macrocode}
+ \else%
+ \ifdim\svsplit@remain<2\svtab%
+ \ifsvsplit@\else\normalfont-\svsplit@break\fi%
+ \svsplit@eject%
+ \fi%
+% \end{macrocode}
+%
+% Insert the character and decrement the distance-left register.
+%
+% \begin{macrocode}
+ #1%
+ \global\advance\svsplit@remain-\svtab%
+% \end{macrocode}
+%
+% Now we see if it's a breakable-after character and if so mark it as being
+% breakable.
+%
+% \begin{macrocode}
+ \def\temp@##1#1##2\q@delim%
+ {\ifx\q@delim##2\q@delim\else\svsplit@break\fi}%
+ \expandafter\temp@\svsplitchars#1\q@delim%
+% \end{macrocode}
+%
+% And with that, we're done.
+%
+% \begin{macrocode}
+ \fi\fi\fi%
+ \next@%
+}
+% \end{macrocode}
+%
+% Our next macro is the break-insertion subroutine, which is quite easy.
+%
+% \begin{macrocode}
+\def\svsplit@break{%
+ \egroup%
+ \sv@addtobox\tw@\z@%
+ \svsplit@true%
+ \setbox\z@\hbox\bgroup%
+}
+% \end{macrocode}
+%
+% Now we add space to the current box. The argument is a dimen register.
+%
+% \begin{macrocode}
+\def\svsplit@space#1{%
+ \ifdim\svsplit@remain>#1\kern#1\global\advance\svsplit@remain-#1\fi%
+ \svsplit@break%
+ \ifdim\svsplit@remain>#1\else\svsplit@eject\fi%
+}
+% \end{macrocode}
+%
+% We now come to a slightly involved piece of code, which is how to flush out
+% a line, and then fix up the registers for the next line correctly.
+%
+% \begin{macrocode}
+\def\svsplit@eject{%
+ \egroup%
+ \svline\tw@%
+ \sv@emptybox\tw@%
+ \svsplit@false%
+ \setbox\z@\hbox\bgroup%
+ \kern\svsplit@indent%
+ \global\svsplit@remain\linewidth%
+ \global\advance\svsplit@remain-\svsplit@indent%
+ \global\advance\svsplit@remain-\wd\z@%
+ \unhbox\z@%
+}
+% \end{macrocode}
+%
+% Finally, how to finish the line and go home.
+%
+% \begin{macrocode}
+\def\svsplit@done{%
+ \egroup%
+ \sv@addtobox\tw@\z@%
+ \svline\tw@%
+}
+% \end{macrocode}
+%
+% End the |\lowercase| hack.
+%
+% \begin{macrocode}
+}
+% \end{macrocode}
+%
+% \end{macro}
+%
+% Finally, set the breakable characters to something plausible.
+%
+% \begin{macrocode}
+\def\svsplitchars{:/.}
+% \end{macrocode}
+%
+% And with that, we're done!
+%
+% \begin{macrocode}
+%</split>
+% \end{macrocode}
+%