# Automatic versewidth

verse package has \settowidth command to center a poetry. Example:

\settowidth{\versewidth}{There was an old party of Lyme}
\begin{verse}[\versewidth]
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{verse}


I have a lot of poetries, and it's impossible to do this for everyone.

Is there a method to do the same thing without the specification of \versewidth?

Like, for example, this:

\begin{verse}
\start{unknown_command}
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{unknown_command}
\end{verse}

-
Incidentally, is this limerick one of Edward lear's? –  Bernard Jul 21 '14 at 1:14
Are you always using the first line for setting \versewidth? –  egreg Jul 21 '14 at 8:18
@egreg No, the largest line is what should be used. –  John Peyton Sep 23 '14 at 23:13

The final \cenverse seems to be the command you are expecting. Certainly, it can be transformed into an environment. The first two occurences of your limerick are for the comparision.

\documentclass{article}

\usepackage{verse}
\begin{document}

I have a lot of poetry, and it's impossible to do this for everyone.
I have a lot of poetry, and it's impossible to do this for everyone.

\settowidth{\versewidth}{There was an old party of Lyme}
\begin{verse}[\versewidth]
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{verse}

I have a lot of poetry, and it's impossible to do this for everyone.
I have a lot of poetry, and it's impossible to do this for everyone.

\begin{verse}
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{verse}

\def\cenverse#1\\{\settowidth{\versewidth}{#1}\begin{verse}[\versewidth]#1\\}

I have a lot of poetry, and it's impossible to do this for everyone.
I have a lot of poetry, and it's impossible to do this for everyone.

\cenverse
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{verse}

\end{document}


-
Is there a method to use this in a poetry without //? For example if I use boldfirst [tex.stackexchange.com/a/192468/59415 ] I not insert // and it doesn't work! –  user Jul 21 '14 at 11:24
And how can I turn the code into a \newenvironment for using it like \begin{cenverse} ..text... \end{cenverse}? –  user Jul 21 '14 at 13:02

This will use the widest verse for deciding the width and center the poem.

\documentclass{article}
\usepackage{verse,varwidth,environ}

\usepackage{lipsum} % just for the example

\newsavebox{\versebox}
\NewEnviron{cverse}{%
\setlength{\leftmargini}{0pt}%
\begin{lrbox}{\versebox}
\begin{varwidth}{\textwidth}
\begin{verse}
\BODY
\end{verse}
\end{varwidth}
\end{lrbox}%
\begin{verse}[\wd\versebox]
\BODY
\end{verse}
}

\begin{document}

\lipsum[2]

\begin{cverse}
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{cverse}

\begin{cverse}
Clof, clop, cloch,\\
cloffete,\\
cloppete,\\
clocchette,\\
chchch\dots\\
\E gi\u,\\
nel cortile,\\
la povera\\
fontana\\
malata;\\
che spasimo!\\
sentirla\\
tossire.\\
Tossisce,\\
tossisce,\\
un poco\\
si tace\dots\\
di nuovo.\\
tossisce.
\end{cverse}

\end{document}


The second poem is the start of Aldo Palazzeschi's “La fontana malata” (The sick fountain).

I used varwidth for measuring the width; because of how verse works, we need to set \leftmargini to zero (the setting is inside cverse, so it's local).

If you need footnotes in poems, change the code above into

\newsavebox{\versebox}
\newcounter{mockfootnote}
\NewEnviron{cverse}{%
\setlength{\leftmargini}{0pt}%
\begin{lrbox}{\versebox}
% remember the current value of footnote
\setcounter{mockfootnote}{\value{footnote}}%
% disable footnotes in the first pass over the poem
\renewcommand\footnote[1]{\stepcounter{mockfootnote}\textsuperscript{\themockfootnote}}%
\begin{varwidth}{\textwidth}
\begin{verse}
\BODY
\end{verse}
\end{varwidth}
\end{lrbox}%
\begin{verse}[\wd\versebox]
\BODY
\end{verse}
}

-
This gives me a runaway argument error: file ended while scanning use of cverse. –  John Peyton Sep 24 '14 at 0:21
@JohnPeyton Are you perhaps using cverse in the definition of another environment? –  egreg Sep 24 '14 at 9:07
I don't think I was. However, I tried it again and it is working now­ … sorry that my problem was irreproducible. –  John Peyton Sep 25 '14 at 2:32
I’ve also found that this fails when the poem contains footnotes. In such a case the entire block is aligned left. This is probably testable using your example. –  John Peyton Sep 26 '14 at 0:06
@JohnPeyton I added a new definition of cverse to cope with footnotes. –  egreg Sep 26 '14 at 9:12