# Auto two column mode

I'm trying to create songbook document class. Every song is on its own page. I want to achieve that if the song is regular sized (fits to one page in one column) the song's page is one column, but if the song is too long to fit one page in one column, then the song's page is two column (all this has to happen automatically without songbook author interaction). Is it possible to achieve that? If yes, how?

PS: please don't recommend me another songbook styles and classes, I've searched them but they don't satisfy my needs.

-
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Martin Scharrer Jul 8 '11 at 12:59

You could typeset the song inside a \savebox first using one column mode and measure the resulting size. If it is too large it is typeset again in two column mode. There are no packages for this as far as I know, but this could be programmed easily enough. You can collect the environment content using e.g. the environ package.

Here an example implementation using environ and multicol. Adjust it to your needs. I included two example usages with dummy text.

\documentclass{article}

\usepackage{environ}
\usepackage{multicol}

\newsavebox{\songbox}

\NewEnviron{song}{% can also have arguments
\clearpage
% Add song title, at as argument etc.
%
% The content is \BODY
% Let's save it in normal single column mode:
\savebox{\songbox}{%
\begin{minipage}{\linewidth}%
\BODY
\end{minipage}%
}%
% To high? (Replace \textheight if required)
% \ht = hight, \dp = depth, both together is the total height
\ifnum\dimexpr\ht\songbox+\dp\songbox > \textheight
% Typeset again in two column mode:
\begin{multicols}{2}%
\BODY
\end{multicols}%
\else
% Size is already OK, so use the content of the saved box:
\usebox{\songbox}%
\fi
}

\begin{document}

\begin{song}
A short song\\
La la la la la \\
A very short song indeed\\
But this is a very long line to demonstrate that we are still in single column mode. In fact it is so long that it will be broken into two lines.
\end{song}

\begin{song}
This is a long song\\
This is a long song\\
And this is a long line to show the two column mode.
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
This is a long song\\
\end{song}

\end{document}


-
This looks useful. Please can you tell me more details about measuring the size of the saved box? –  uiii Jul 8 '11 at 16:12
@uiii: See my update. –  Martin Scharrer Jul 8 '11 at 16:17
This is exactly what I want. Good thing that environ package. Thank you very much. –  uiii Jul 8 '11 at 16:40