Typesetting poems

enter image description here

\documentclass[twocolumn]{article}

\textheight.5\textheight

\begingroup
\makeatletter
\catcode13\active%
\gdef\verseinput#1{%
{%
\interlinepenalty\@M%
\def^^M{\@ifnextchar^^M\par{\ifhmode\break\fi}}%
\rightskip\fill%
\parindent\z@%
\parskip\baselineskip%
\raggedbottom%
\catcode13\active\input{#1}%
\par%
}}%
\endgroup%
\begin{document}

\verseinput{v1.txt}

\end{document}

line 1
line 2
line 3
line 4

line 5
line 6
line 7
line 8

line 9
line 10
line 11
line 12

line a9
line a10
line a11
line a12

line b9
line b10
line b11
line b12

line a9
line a10
line a11
line a12

line b9
line b10
line b11
line b12

line a9
line a10
line a11
line a12

line b9
line b10
line b11
line b12

line a9
line a10
line a11
line a12

line b9
line b10
line b11
line b12

line a9
line a10
line a11
line a12

line b9
line b10
line b11
line b12

Add the following to your preamble and you don't need to type any mark-up:

\documentclass{article}
\makeatletter
\newdimen\allttindent \allttindent=0pt % set this to change the indent

\def\docspecials{\do\ \do\$\do\&%
  \do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~}

\def\alltt{\trivlist \item[]\if@minipage\else\vskip\parskip\fi
\leftskip\@totalleftmargin  \advance\leftskip\allttindent \rightskip\z@
\parindent\z@\parfillskip\@flushglue\parskip\z@
\@tempswafalse \def\par{\if@tempswa\hbox{}\fi\@tempswatrue\@@par}
\obeylines \tt \catcode``=13 \@noligs
\let\do\@makeother \docspecials
 \frenchspacing\@vobeyspaces}

\let\endalltt=\endtrivlist
\AtBeginDocument{\alltt}
\AtEndDocument{\endalltt}
\makeatother

\begin{document}
There was an old woman of 92
Parlez-vous
There was an old woman of 92
Parlez-vous
There was an old woman of 92
Did a fart and away it flew
Inky pinky parlez-vous

The fart went rolling down the street
Knocked a copper off his feet

The copper got out his rusty pistol
Blew the fart right on to Bristol

The people of Bristol were having a dance
The fart went rolling on to France

The people of France were not at home
The fart went rolling on to Rome
\end{document}

It does not do the multicolumn but it maybe possible to trigger a multicolumn based on a word of the poem. Let me know the word and maybe egreg can come up with a macro for that! The preamble is borrowed from alltt2.


An alternative option is to convert the plain text poems to the verse environment using another program. This method has the advantage that you could use it to automate the processing of poems from different files or from a database.

To prevent page breaks inside verses the following answer may be relevant: https://tex.stackexchange.com/a/21985/7092

As an example of the conversion, here's a simple tool using JavaScript with that performs this task. Here I consider a verse as any number of lines separated by a single line breaks. Save the code below as an html file to use it.

verses

<html>
<head>
<title>Verses!</title>

<script>
function convertVerses() 
{
    var input = document.getElementById('input').value
    var lines = input.split(/\r?\n/);
    var env = "verse"
    var output = "";
    for (var i = 0;i < lines.length;i++)
    {
        if (!lines[i].match(/^[ \t\n]*$/))
        {   
         //   alert(lines[i])
        // no empty line       
            if (lines.length==1 || 
              (i==0 && lines[i+1].match(/^[ \t\n]*$/)) ||
                (i==lines.length && lines[i-1].match(/^[ \t\n]*$/)) ||
                (lines[i-1].match(/^[ \t\n]*$/) && lines[i+1].match(/^[ \t\n]*$/))) {
                // only line of verse
                output += '\\begin\{'+env+'\}\n' + lines[i] + '\n\\end\{'+env+'\}\n\n';   
            } else  if (i==0 || lines[i-1].match(/^[ \t\n]*$/)) { 
                // first line of verse
                output += '\\begin\{'+env+'\}\n' +lines[i] + '\\\\\n';
            } else if (i==lines.length || lines[i+1].match(/^[ \t\n]*$/))  {
                // last line of verse
                output += lines[i] + '\n\\end\{'+env+'\}\n\n';   
            } else {
                // any other line of the verse 
                output += lines[i] + '\\\\\n';
            }  
        }
    }
    document.getElementById('output').value = output;
}

</script>

<style>
textarea {width:700px;height:330px;display:block;margin:10px}
button {width:700px;height:50px;margin:10px}
</style>
</head>

<body>    
<textarea id="input">
p0

p1
p2
p3 

p5
p6

p9
</textarea>
<button onclick="convertVerses()"> Convert!</button>
<textarea id="output">
</textarea>
</body>    
</html>

Tags:

Poetry