5

As far as I know, a double line break introduces a new paragraph. Within verse this is used to separate stanzas, which can also be done with \\!. So in LaTeX source code for long, standalone poems, almost every line ends with \\. Is it possible to use a single line break for newlines instead?

Essentially I have

\begin{verse}
There was a young lady of Niger \\
Who smiled as she rode on a tiger; \\
They returned from the ride \\
With the lady inside, \\
And the smile on the face of the tiger.

Second verse.
\end{verse}

and would instead like to be able to write

\begin{verse}
There was a young lady of Niger
Who smiled as she rode on a tiger;
They returned from the ride
With the lady inside,
And the smile on the face of the tiger.

Second verse.
\end{verse}
lockstep
  • 250,273
XZS
  • 2,953

2 Answers2

6

Here's one possibility, using \obeylines and a variation of egreg's answer to Inserting automatic vertical space between blocks when \obeylines is active to redefine the standard verse environment:

\documentclass{article}

\makeatletter
\renewenvironment{verse}
  {\let\\\@centercr
    \list{}{\itemsep \z@
    \itemindent -1.5em
    \listparindent\itemindent
    \rightmargin \leftmargin
    \advance\leftmargin 1.5em}
    \item\relax\obeylines\begingroup\lccode`~=`\^^M
    \lowercase{\endgroup\def~}{\par\leavevmode}%
    \parskip=0pt plus 1pt%
  }
  {\endlist}
\makeatother               

\begin{document}

\begin{verse}
There was a young lady of Niger
Who smiled as she rode on a tiger;
They returned from the ride
With the lady inside,
And the smile on the face of the tiger.

Second verse.
\end{verse}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
0

Great question and fantastic answer of Gonzalo Medina! Works fine! A refinement for the current version of MiKTeX 2.9:

\makeatletter
\renewenvironment{verse}[1][\linewidth]{%
    \stepcounter{verse@envctr}%
    \setcounter{poemline}{0}\refstepcounter{poemline}%
    \setcounter{vslineno}{1}%
    \let\\=\@vscentercr
    \list{}{\itemsep \z@
        \itemindent  -\vindent%
        \listparindent\itemindent
        \parsep       \stanzaskip
        \ifdim #1 < \linewidth
        \rightmargin        \z@
        \setlength{\leftmargin}{\linewidth}%
        \addtolength{\leftmargin}{-#1}%
        \addtolength{\leftmargin}{-0.5\leftmargin}%
        \else
        \rightmargin        \leftmargin
        \fi
        \addtolength{\leftmargin}{\vindent}}%
    \item\relax\obeylines\begingroup\lccode`~=`\^^M
    \lowercase{\endgroup\def~}{\par\leavevmode}%
    \parskip=0pt plus 1pt%
}
{\endlist}
\makeatother