7

I have a script to query a database containing poems and typeset them in LaTeX within a verse environment. Some poems contain section which are in prose. These prose lines are clearly tagged in the database (<prose> ... </prose>) so I am able to manipulate them.

I am then exploring how to typeset them smartly in LaTeX (maybe defining a specific in verse "sub" environment?).

The results should be that

  1. The numeration of poem lines stops at the prose line to then continue immediately after;
  2. I should be able to define the styling of in verse prose globally for the whole document as I do with the verse environment.

Please consider the following MWE, with the verse environment as typeset by my script.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{verse}

\begin{document}

\verselinenumbersleft
\setlength{\vrightskip}{-2em}
\poemlines{1}

\begin{verse}
To see a World in a Grain of Sand\\
And a Heaven in a Wild Flower,\\!
<prose>AND here some prose, which shouldn't be enumerated and also should be styled differently</prose>\\!
Hold Infinity in the palm of your hand\\
And Eternity in an hour.\\!
\end{verse}

\end{document}

which produces

enter image description here

  • May be end verse, add the prose, restart verse and set the counter correctly? – Manuel May 23 '14 at 2:17
6

Use an environment insideverse, as you proposed yourself, disable the line number inside, store the line counter number and store it back after the prose part ended. The style of the prose part can be changed in the begin command section of the environment. The outer formatting is not affected, since all is safe in a \begingroup...\endgroup pair.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{verse}
\usepackage{xcolor}

\newcounter{saveverselinecounter}

\newenvironment{insideverse}{%
\setcounter{saveverselinecounter}{\number\value{poemline}}%
\let\thepoemline\relax%
% Style commands % Change at will
\bfseries\color{red}%
}{%
\setcounter{poemline}{\number\value{saveverselinecounter}}
}

\begin{document}

\verselinenumbersleft
\setlength{\vrightskip}{-2em}
\poemlines{1}

\begin{verse}
To see a World in a Grain of Sand\\
And a Heaven in a Wild Flower,\\!
\begin{insideverse}%
<prose>AND here some prose, which shouldn't be enumerated and also should be styled differently</prose>\\!
\end{insideverse}%
Hold Infinity in the palm of your hand\\
And Eternity in an hour.\\!
\end{verse}

\end{document}

enter image description here

Edit: Improved version with some control of the insideverse environment

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{verse}
\usepackage{xcolor}

\usepackage{etoolbox}
\usepackage{xkeyval}


\makeatletter
\newcounter{saveverselinecounter}[verse@envctr]
\makeatother


\providecommand{\ProvideBool}[2][false]{%
\providebool{#2}%
\setbool{#2}{#1}
\long\csgdef{Enable#2}{%
\booltrue{#2}%
}%
\long\csgdef{Disable#2}{%
\boolfalse{#2}%
}%
}%

\ProvideBool{InsideVerseCentered}%

\makeatletter
\define@boolkey[KV]{InsideVerseKeys}{center}[false]{%
\ifKV@InsideVerseKeys@center%
\EnableInsideVerseCentered%
\else%
\typeout{Nope, disabled!}
\DisableInsideVerseCentered%
\fi%
}%

\define@key{InsideVerseKeys}{topskip}[\baselineskip]{%
\def\KVInsideVerseKeysTopSkip{#1}%
}%

\define@key{InsideVerseKeys}{bottomskip}[\baselineskip]{%
\def\KVInsideVerseKeysBottomSkip{#1}%
}%

\makeatletter



\newenvironment{insideverse}[1][]{%
\setkeys{InsideVerseKeys}{#1}%
\setcounter{saveverselinecounter}{\number\value{poemline}}%
\let\thepoemline\relax%
% Style commands % Change at will
\vspace{\KVInsideVerseKeysTopSkip}%
\bfseries\color{red}%
\ifbool{InsideVerseCentered}{%
\centering%
}{%
\relax%
}%
}{%

\setcounter{poemline}{\number\value{saveverselinecounter}}%
\DisableInsideVerseCentered%
\vspace{\KVInsideVerseKeysBottomSkip}%
}%



\AtBeginDocument{%
\EnableInsideVerseCentered%
}%

\presetkeys{InsideVerseKeys}{center=false,%
                             topskip=0.1\baselineskip,%
                             bottomskip=0.1\baselineskip%
                           }{}%

\begin{document}

\verselinenumbersleft
\setlength{\vrightskip}{-2em}
\poemlines{1}

\begin{verse}
To see a World in a Grain of Sand\\
And a Heaven in a Wild Flower,\\!
\begin{insideverse}[center=true]%
AND here some prose, which shouldn't be enumerated and also should be styled differently%</prose>
\end{insideverse}%
Hold Infinity in the palm of your hand\\
And Eternity in an hour.\\!
\end{verse}

\begin{verse}[1em]
To see a World in a Grain of Sand\\
And a Heaven in a Wild Flower,\\!
\begin{insideverse}[center=false]%
AND here some prose, which shouldn't be enumerated and also should be styled differently%</prose>
\end{insideverse}%
Hold Infinity in the palm of your hand\\
And Eternity in an hour.\\!
\end{verse}


\end{document}

enter image description here

| improve this answer | |
  • Elegant! But why the inverse text is centered? – Francesco May 23 '14 at 5:39
  • Good question. I believe that the outer verse environment is responsible for that. I will check later on. – user31729 May 23 '14 at 5:53
  • Thanks, btw. I tried to use your example to create a centered inverse environment. Yet line numbers are not aligned with the number of the parent verse \newenvironment{insideverseCenter}{% \setcounter{saveverselinecounter}{\number\value{poemline}}% \begin{center}% \begin{verse}% \setcounter{poemline}{\number\value{saveverselinecounter}}% }{% \setcounter{saveverselinecounter}{\number\value{poemline}}% \end{verse}% \end{center}% \setcounter{poemline}{\number\value{saveverselinecounter}}% } – Francesco May 23 '14 at 5:56
  • @Francesco: I am not sure what you mean? Should the several lines of non-prose content be centered now? – user31729 May 23 '14 at 13:47
  • Nope, just looking for the mechanism to control it. I want to be able to vary within the verse from default to -> prose to -> -> verse centered -> back to default. – Francesco May 23 '14 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.