# Left-hand vertical rule applied to flalign environment with automatic pagebreak

I am referring to the coderule environment (see Override \centering to left justify an image) presented earlier by @TH as answer to the following question: Override \centering to left justify an image

I use the defined coderule environment for equations (i.e., flalign, amsmath package). Since my equations are quite long, I allow automatic page breaking for them (\allowdisplaybreaks[1]). If I apply the coderule around the flalign, the equations do not break anymore and leave a lot of unused white space. Is it possible to change the coderule environment in such a way that it adapts to the automatic page break?

-
Welcome to TeX.sx! Please add a minimal working example (MWE) that compiles and shows the working of your coderule environment. It would make it much easier for others to investigate modifications rather than re-inventing the wheel or gather information from different sources across TeX.SX. –  Werner Nov 1 '11 at 15:41

Here is a completely revamped version of the coderule environment. This time using the mdframed environment from the similarly-named mdframed package. The package is loaded with the framemethod=tikz, thinking that you're compiling your document using pdflatex.

Although mdframed produces a framed environment, we set the top, bottom and right margins and lines to 0pt, and adjust only the left margin specifications. mdframed naturally breaks across a page without problem, thereby providing the required functionality by default.

In the following minimal example, the coderule environment takes 3 optional arguments:

\begin{coderule}[<rule width>][<rule sep>][<rule colour>]
...
\end{coderule}


The width of the rule is set by the first optional argument <rule width> (default is 1em), while the separation between the rule and the paragraph text is set by the second <rule sep> (default is 1em). Finally, the third optional argument allows you to modify the colour to suit your needs (default is black).

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage[framemethod=tikz]{mdframed}% http://ctan.org/pkg/mdframed
\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentEnvironment{coderule}{O{1em} O{1em} O{black}}%
{% \begin{coderule}[<rule width>][<rule sep>][<rule colour>]
\allowdisplaybreaks[1]%
\begin{mdframed}%
[topline=false,rightline=false,bottomline=false,%
innertopmargin=0pt,innerrightmargin=0pt,innerbottommargin=0pt,%
skipabove=\parskip,skipbelow=0.3\baselineskip,%
innerleftmargin=#2,outerlinewidth=#1,linecolor=#3]
}
{\end{mdframed}}% \end{coderule}

\begin{document}
\lipsum[1] \bigskip \bigskip \bigskip
\begin{coderule}
\lipsum[2-4]
\begin{align}
f(x) &= ax^2+bx+c \\
f(x) &= ax^2+bx+c \\
f(x) &= ax^2+bx+c \\
f(x) &= ax^2+bx+c
\end{align}
\lipsum[5-6]
\end{coderule}
\lipsum[7-8]
\begin{coderule}[2em][1em][orange]
Here is a short introduction:
\begin{align}
f(x) &= ax^2+bx+c \\
f(x) &= ax^2+bx+c \\
f(x) &= ax^2+bx+c \\
f(x) &= ax^2+bx+c \\
f(x) &= ax^2+bx+c \\
f(x) &= ax^2+bx+c
\end{align}
\lipsum[5-6]
\end{coderule}
\end{document}


Of course, the choice of 3 additional arguments may be superfluous. So, that can be removed as well, or the order switched around. Also, the choice of align from amsmath is interchangeable with flalign.

xparse provided the environment definition interface, while lipsum was used for dummy text generation, Lorem Ipsum style.

-