verse.

Typesetting simple verse with LATEX
Author: Peter Wilson, Herries Press
Maintainer: Will Robertson
http://github.com/wspr/herries-press/
v2.4b
2014/05/10
Abstract
The verse package provides some aids for the typesetting of simple verse.
Contents
1 Introduction
2
2 Verses in LATEX without this package
2
3 The verse package
3.1 Brief introduction . . . . . . . . .
3.2 Comprehensive documentation .
3.2.1 Main verse environments
3.2.2 Other verse commands . .
3.2.3 Generic verse formatting .
3.2.4 Line numbering . . . . . .
3.2.5 Titles . . . . . . . . . . .
3.3 Supports . . . . . . . . . . . . . .
3.4 Examples . . . . . . . . . . . . .
A Limerick . . . . . . . . . . . . . . .
Love’s lost
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5
5
5
5
6
6
7
7
8
8
9
9
Fleas
10
In the beginning
10
Mathematics
11
12
Clementine
12
1
2
2
Verses in LATEX without this package
Mouse’s Tale
4 The
4.1
4.2
4.3
4.4
1
package code
Preliminaries .
Verse code . . .
Pattern code .
Title code . . .
13
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
14
14
14
18
22
Introduction
The typesetting of a poem should be really be dependent on the particular poem.
Individual problems do not usually admit of a general solution, so this document
and code should be used more as a guide towards some solutions rather than
This manual is typeset according to the conventions of the LATEX docstrip utility which enables the automatic extraction of the LATEX macro source
files [GMS94].
Section 3 describes the usage of the verse package and commented source code
is in Section 4. Colour is used to indicate input and output material; a blue
background indicates LATEX input source, and a green background shows the
corresponding output one should expect.
The doggerel used as illustrative material has been taken from [Wil01].
2
Verses in LATEX without this package
LaTeX provides the verse environment which is defined as a particular kind of
list. Within the environment you use \\ to end a line and a blank line will end a
stanza. For example, here is a single stanza poem:
\newcommand{\garden}{
I used to love my garden \\
But now my love is dead \\
For I found a bachelor’s button \\
In black-eyed Susan’s bed.
}
When this is typeset as a normal LaTeX paragraph (with no paragraph indentation) it looks like:
I used to love my garden
But now my love is dead
For I found a bachelor’s button
In black-eyed Susan’s bed.
Typesetting it within LATEX’s verse environment produces:
3
I used to love my garden
But now my love is dead
For I found a bachelor’s button
In black-eyed Susan’s bed.
The stanza could also be typeset within the alltt environment, defined in the
standard alltt package, using a normal font and no \\ line endings.
\begin{alltt}\normalfont
I used to love my garden
But now my love is dead
For I found a bachelor’s button
In black-eyed Susan’s bed.
\end{alltt}
which produces:
I used to love my garden
But now my love is dead
For I found a bachelor’s button
In black-eyed Susan’s bed.
The alltt environment is like the verbatim environment except that you can use
LaTeX macros inside it.
In the verse environment long lines will be wrapped and indented but in the
alltt environment there is no indentation.
Some stanzas have certain lines indented, often alternate ones. To typeset
stanzas like this you have to add your own spacing. For instance:
\begin{verse}
There was an old party of Lyme \\
Who married three wives at one time. \\
\hspace{2em} When asked: ‘Why the third?’ \\
\hspace{2em} He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{verse}
will be typeset in a verse environment as:
There was an old party of Lyme
Who married three wives at one time.
He replied: ‘One’s absurd,
And bigamy, sir, is a crime.’
Using the alltt environment you can put in the spacing via ordinary spaces. That
is, this
\begin{alltt}\normalfont
There was an old party of Lyme
4
2
Verses in LATEX without this package
Who married three wives at one time.
He replied: ‘One’s absurd,
And bigamy, sir, is a crime.’
\end{alltt}
is typeset as
There was an old party of Lyme
Who married three wives at one time.
He replied: ‘One’s absurd,
And bigamy, sir, is a crime.’
More exotically you could use the TeX \parshape command:
\parshape = 5 0pt \linewidth 0pt \linewidth
2em \linewidth 2em \linewidth 0pt \linewidth
\noindent There was an old party of Lyme \\
Who married three wives at one time. \\
When asked: ‘Why the third?’ \\
He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’ \par
which will be typeset as:
There was an old party of Lyme
Who married three wives at one time.
He replied: ‘One’s absurd,
And bigamy, sir, is a crime.’
All of this is about as much assistance as standard (La)TeX provides.
5
3
The verse package
The code provided by the verse package is meant to help with some aspects of
typesetting poetry but does not, and cannot, provide a comprehensive solution to
all the requirements that will arise.
A brief introduction is included to get started quickly; see the examples in
Section 3.4 for more context.
3.1
Brief introduction
The verse package provides the verse environment for typesetting verses, overwriting LATEX’s original definition. Every line in a verse environment must end
with \\, and every stanza within a verse should end with \\! (an empty line afterwards is optional for readability). These requirements allow line numbering to
work correctly in all cases. Use the \poemlines{hN i} command to number every
hN ith line of a poem.
Use the \poemtitle{htitlei} command (just before the verse environment)
to give each poem a title; commands are provided to adjust the formatting and
Each stanza within a verse may optionally be surrounded by either an altverse
or patverse environment to effect specific typesetting; altverse indents every
second line of a stanza, and patverse allows arbitrary indentation based on
the hpatterni given by \indentpattern{hpatterni}. The command \flagverse,
placed at the very beginning of a stanza places a ‘title’; e.g., for numbering and
otherwise labelling stanzas.
3.2
3.2.1
verse
\versewidth
Comprehensive documentation
Main verse environments
The verse environment provided by the package is an extension of the usual
LaTeX environment. The environment takes one optional parameter, which is a
length; for example \begin{verse}[4em]. You may have noticed that the earlier
verse examples are all near the left margin, whereas verses usually look better if
they are typeset about the center of the page. The length parameter, if given,
should be about the length of an average line, and then the entire contents will be
typeset with the mid point of the length centered horizontally on the page.
The length \versewidth is provided as a convenience. It may be used, for
example, to calculate the length of a line of text for use as the optional argument
to the verse environment:
\settowidth{\versewidth}{This is the average line,}
\begin{verse}[\versewidth]
altverse
Within the verse environment verses are separated by a blank line in the
input. Individual verses within verse may, however, be enclosed in the altverse
environment. This has the effect of indenting the 2nd, 4th, etc., lines of the verse
by the length \vgap.
6
patverse
patverse*
\indentpattern
\\!
\\*
\\>
The verse package
Individual verses within the verse environment may be enclosed in the
patverse environment. Within the environment the indentation of each line is
specified by an indentation pattern, which consists of an array of digits, d1 to dn ,
and the nth line is indented by dn times \vgap. However, the first line is not
indented, irrespective of the value of d1 .
The patverse* environment is similar to patverse environment, except that
the pattern will keep on repeating itself.
The indentation pattern for a patverse environment is specified via the
\indentpattern{hdigitsi} command. If the pattern is shorter than the number
of lines in a verse, the trailing lines will not be indented.
3.2.2
\\
3
Other verse commands
Within the verse environment, the macro \\ must be used at the end of each line
of a verse, except for the last line in each stanza. If the lines in a poem are to be
numbered then \\! must be used at the end of the last line in each stanza (the
\\ macro increments the line numbers).
The starred version, \\*, prohibits a page break after the line. The \\> version
causes a linebreak within a verse line.
The \\ macro in its various forms can also take an optional length argument,
like \\[30pt] which will insert 30pt of vertical space; in the case of \\>[30pt] an
additional 30pt of horizontal space will be inserted after the linebreak (effectively
\\> is shorthand for \verselinebreak).
The allowable forms of the macro are:
\\, \\*. \\!, \\>, \\[...], \\*[...], \\![...], and \\>[...].
\vin
\vgap
\vindent
\verselinebreak
\flagverse
\vleftskip
The command \vin is shorthand for \hspace{\vgap} for use at the start of
an indented line of verse. The length \vgap (initially 1.5em) can be changed by
When a verse line is too long to fit within the typeblock it is wrapped onto the
next line with a space, given by the value of the length \vindent.
Using the command \verselinebreak[hlengthi] will cause later text in the
line of the verse to be typeset indented on the following line. If the optional length
argument is not given the indentation is \vgap, otherwise the indentation is given
by hlengthi plus \vgap. The broken line will count as a single line as far as the
Putting the command \flagverse{hflagi} at the start of a line of verse will
typeset hflagi towards the left margin, ending a distance \vleftskip before the
verse line.
3.2.3
\leftmargini
Generic verse formatting
The length \stanzaskip controls the spacing between stanzas. It may be changed
like any other length.
All verse lines have a minimum indent given by the length \leftmargini which
3.2
Comprehensive documentation
7
also applies to any list environment. To change the minimum indent for verses do
something along the lines:
\newlength{\saveleftmargini}
\setlength{\saveleftmargini}{\leftmargini}
\setlength{\leftmargini}{-1em}% for example to outdent verse
% verses
\setlength{\leftmargini}{\saveleftmargini}% restore original value
3.2.4
\poemlines
\setverselinenums
\thepoemline
\verselinenumfont
\vrightskip
\verselinenumbersleft
\verselinenumbersright
\label
\ref
The declaration \poemlines{hnthi} will cause every hnthi lines of succeeding
verses to be numbered. For example, \poemlines{5} will number every fifth
line. The default is \poemlines{0} which prevents any numbering.
The command \setverselinenums{hfirstlinenumi}{hstartnumsati} can be
used to set the number of the first verse line to hfirstlinenumi instead of the
default ‘1’ and to specify that the first printed line number should be for line
number hstartnumsati. If used the command must be given within the verse
environment before the first line of the verses. For example, if you were quoting
portions of poems from a source where the lines were numbered, your first line
might be the 112th of the original and that line was originally numbered:
\setverselinenums{112}{112}
or if it was line 115 that was first numbered:
\setverselinenums{112}{115}
Note that the numbers must be such that the following relationship holds:
firstlinenum <= startnumsat < firstlinenum + poemlines
Lines are numbered via \thepoemline which defaults to typesetting arabic
numerals via:
\renewcommand*{\thepoemline}{\arabic{poemline}}
The particular font is defined by \verselinenumfont{hfont-speci}, with default:
\verselinenumfont{\rmfamily}
By default the numbers are typeset at the distance \vrightskip into the right
margin. If you want line numbers set at the left use the \verselinenumbersleft
declaration. To revert to the default use \verselinenumbersright.
The standard \label{metakey} command can be used inside the verse environment, between the end of the text of a line and the line-ending \\, to grab that
line number, no matter what the setting of \poemlines. Elsewhere the standard
\ref{hkeyi} command can be used to refer to the line number.
3.2.5
\poemtitle
\poemtoc
Line numbering
Titles
\poemtitle[hshorti}{hlongi} typesets the title of a poem and makes an entry
into the ToC. There is a starred version that makes no ToC entry.
The kind of entry made in the ToC by the \poemtitle command is defined by
\poemtoc. The initial definition is:
\newcommand{\poemtoc}{section}
8
\poemtitlefont
\beforepoemtitleskip
\afterpoemtitleskip
\poemtitlemark
\setarrayelement
\getarrayelement
\checkarrayindex
\stringtoarray
\arraytostring
\checkifinteger
The verse package
for a section-like ToC entry. This can be changed to, say, chapter or subsection
or . . . .
This macro specifies the font and positioning of the poem title. Its initial
definition is:
\newcommand{\poemtitlefont}{\normalfont\bfseries\large\centering}
to give a \large bold centered title. This can of course be renewed if you want
something else.
These two lengths are the vertical space before and after the \poemtitle title
text. They are initially defined to give the same spacing as for a \section title.
They can be changed by \setlength or \addtolength for different spacings.
The \poemtitle macro, but not \poemtitle*, calls the \poemtitlemark{htitlei}
macro, which is defined to do nothing. This would probably be changed by a
pagestyle definition (like \sectionmark or \chaptermark).
3.3
\newarray
3
Supports
The package includes some macros for supporting the patverse environment
which may be more generally useful. See the code section for examples on how
these may be used.
\newarray{harraynamei}{hlow i}{hhighi} defines the harraynamei array, where
harraynamei is a name like MyArray. The lowest and highest array indices are set
to hlow i and hhighi respectively, where both are integer numbers.
\setarrayelement{harraynamei}{hindex i}{htexti} sets the hindex i location
in the harraynamei array to be htexti. For example:
\setarrayelement{MyArray}{23}{$2^{23}$}.
\getarrayelement{harraynamei}{hindex i}{hresulti} sets the parameterless
macro hresulti to the contents of the hindex i location in the harraynamei array.
For example:
\getarrayelement{MyArray}{23}{\result}.
\checkarrayindex{harraynamei}{hindex i} checks if harraynamei is an array
and if hindex i is a valid index for the array.
\stringtoarray{harraynamei}{hstringi} puts each character from hstringi
sequentially into the harraynamei array, starting at index 1. For example:
\stringtoarray{MyArray}{Chars}.
The macro \arraytostring{harraynamei}{hresulti} assumes that harraynamei
is an array of characters, and defines the macro hresulti to be that sequence of
characters. For example:
\arraytostring{MyArray}{\MyString}.
\checkifinteger{hnumi} checks if hnumi is an integer (not less than zero).
If it is then \ifinteger is set TRUE, otherwise it is set FALSE.
3.4
Examples
Here are some sample verses using the package facilities. First our old Limerick
friend, but titled and centered:
3.4
Examples
9
\renewcommand{\poemtoc}{subsection}
\poemtitle{A Limerick}
\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}
which gets typeset as below. The default \poemtoc is redefined to subsection so
the title is entered into the ToC as an unnumbered \subsection.
A Limerick
There was an old party of Lyme
Who married three wives at one time.
He replied: ‘One’s absurd,
And bigamy, sir, is a crime.’
Next is the Garden verse within the altverse environment. It is titled and
centered.
\settowidth{\versewidth}{But now my love is dead}
\poemtitle{Love’s lost}
\begin{verse}[\versewidth]
\begin{altverse}
\garden
\end{altverse}
\end{verse}
which produces:
Love’s lost
I used to love my garden
But now my love is dead
For I found a bachelor’s button
In black-eyed Susan’s bed.
It is left up to you how you might want to add information about the author
of a poem. Here is one example of a macro for this:
\newcommand{\attrib}[1]{%
\nopagebreak{\raggedleft\footnotesize #1\par}}
10
3
The verse package
This can be used as in the next bit of doggerel.
\poemtitle{Fleas}
\settowidth{\versewidth}{What a funny thing is a flea}
\begin{verse}[\versewidth]
What a funny thing is a flea. \\
You can’t tell a he from a she. \\
But he can. And she can. \\
Whoopee! \\
\end{verse}
\attrib{Anonymous}
Fleas
What a funny thing is a flea.
You can’t tell a he from a she.
But he can. And she can.
Whoopee!
Anonymous
Here is an example of line wrapping.
\poemtitle{In the beginning}
\settowidth{\versewidth}{And objects at rest tended to remain at rest}
\begin{verse}[\versewidth]
Then God created Newton, \\
And objects at rest tended to remain at rest, \\
And objects in motion tended to remain in motion, \\
And energy was conserved
and momentum was conserved
and matter was conserved \\
And God saw that it was conservative. \\
\end{verse}
\attrib{Possibly from \textit{Analog}, circa 1950}
In the beginning
Then God created Newton,
And objects at rest tended to remain at rest,
And objects in motion tended to remain in motion,
And energy was conserved and momentum was conserved and
matter was conserved
And God saw that it was conservative.
Possibly from Analog, circa 1950
3.4
Examples
11
Here is one with a forced line break and a slightly different title style.
\renewcommand{\poemtitlefont}{\normalfont\large\itshape\centering}
\poemtitle{Mathematics}
\settowidth{\versewidth}{Than Tycho Brahe, or Erra Pater:}
\begin{verse}[\versewidth]
In mathematics he was greater \\
Than Tycho Brahe, or Erra Pater: \\
For he, by geometric scale, \\
Could take the size of pots of ale;\\ \settowidth{\versewidth}{Resolve by}
Resolve, by sines \\>[\versewidth] and tangents straight, \\
If bread or butter wanted weight; \\
And wisely tell what hour o’ the day \\
The clock does strike, by Algebra. \\
\end{verse}
\attrib{Samuel Butler (1612--1680)}
Mathematics
In mathematics he was greater
Than Tycho Brahe, or Erra Pater:
For he, by geometric scale,
Could take the size of pots of ale;
Resolve, by sines
and tangents straight,
If bread or butter wanted weight;
And wisely tell what hour o’ the day
The clock does strike, by Algebra.
Samuel Butler (1612–1680)
Another limerick, but this time taking advantage of the patverse environment
and numbering every third line.
\settowidth{\versewidth}{There was a young lady of Ryde}
\begin{verse}[\versewidth]
\poemlines{3}
\indentpattern{00110}
\begin{patverse}
There was a young lady of Ryde \\
Who ate some apples and died. \\
The apples fermented \\
Inside the lamented \\
And made cider inside her inside. \\
\end{patverse}
\poemlines{0}
\end{verse}
12
3
The verse package
There was a young lady of Ryde
Who ate some apples and died.
The apples fermented
Inside the lamented
And made cider inside her inside.
3
The next example is a song you may have heard of. The ‘forty-niner’ in line 3
refers to the gold rush of 1849.
\settowidth{\versewidth}{In a cavern, in a canyon,}
\poemtitle{Clementine}
\begin{verse}[\versewidth]
\poemlines{2}
\begin{altverse}
\flagverse{1.} In a cavern, in a canyon, \\
Excavating for a mine, \\
Lived a miner, forty-niner, \label{vs:49} \\
And his daughter, Clementine. \\!
\end{altverse}
\begin{altverse}
\flagverse{\textsc{chorus}} Oh my darling, Oh my darling, \\
Oh my darling Clementine. \\
Thou art lost and gone forever, \\
Oh my darling Clementine \\!
\end{altverse}
\poemlines{0}
\end{verse}
Clementine
1.
chorus
In a cavern, in a canyon,
Excavating for a mine,
Lived a miner, forty-niner,
And his daughter, Clementine.
Oh my darling, Oh my darling,
Oh my darling Clementine.
Thou art lost and gone forever,
Oh my darling Clementine
The last example is a much more ambitious use of \indentpattern. In this
case it is defined as:
\indentpattern{0135554322112346898779775545653222345544456688778899}
and the result is shown on the next page.
2
4
6
8
3.4
Examples
13
Mouse’s Tale
Fury said to
a mouse, That
he met
in the
house,
‘Let us
both go
to law:
I will
prosecute
you. —
Come, I’ll
take no
denial;
We must
have a
trial:
For
really
this
morning
I’ve
nothing
to do.’
Said the
mouse to
the cur,
Such a
trial,
dear sir,
With no
jury or
judge,
would be
wasting
our breath.’
‘I’ll be
judge,
I’ll be
jury.’
Said
cunning
old Fury;
‘I’ll try
the whole
cause
and
condemn
you
to
death.’
Lewis Carrol, Alice’s Adventures in Wonderland, 1865
14
4
4
The package code
The package code
To try and avoid name clashes, all the internal commands include the string @vs.
4.1
Preliminaries
Announce the name and version of the package, which requires LATEX 2ε .
h∗usci
\NeedsTeXFormat{LaTeX2e}
3 \ProvidesPackage{verse}[2014/05/10 v2.4b verse typesetting]
1
2
For reference, here is the original definition of the verse environment from
classes.dtx, based on \letting \\ equal \@centercr.
\newenvironment{verse}
{\let\\\@centercr
\list{}{\itemsep \[email protected]
\itemindent -1.5em%
\listparindent\itemindent
\rightmargin \leftmargin
\item\relax}
{\endlist}
4.2
Verse code
vslineno
poemline
\[email protected]
[email protected]
[email protected]
\theHpoemlines
We need a counter for verse lines and poem lines, and one for unique hyperref
anchors (based on the verse environment). Also one for specifying the start of line
numbering.
\poemlines
\poemlines{hnthi} specifies that every hnthi poem line should be numbered. Default is not to number any lines.
\newcounter{vslineno}
\newcounter{poemline}
6 \newcounter{fvsline}
7
\setcounter{fvsline}{0}
8 \newcounter{[email protected]}
9 \newcounter{[email protected]}\setcounter{[email protected]}{0}
10 \newcommand*{\theHpoemline}{\arabic{[email protected]}.\arabic{poemline}}
4
5
\newcommand{\poemlines}[1]{%
\ifnum#1>\[email protected]
13
\setcounter{[email protected]}{#1}%
14
\else
15
\setcounter{[email protected]}{0}%
16
\fi
17 }
18 \poemlines{0}
11
12
4.2
\verselinenumfont
\vlvnumfont
15
Set the font for line numbers.
19
20
\setverselinenums
Verse code
\newcommand*{\verselinenumfont}[1]{\def\vlnumfont{#1}}
\verselinenumfont{\rmfamily}
\setverslinenums{hfirstlinenumi}{hstartnumsati} sets the number of the first
verse line to be hfirstlinenumi and the first line to be numbered to be hstartnumsati.
Note that startnumsat < (firstlinenum + poemlines)
21
\newcommand*{\setverselinenums}[2]{%
Set the poemline counter to #1.
\refstepcounter{poemline}%
\ifnum\[email protected]@vs>\[email protected]
22
23
24
If line numbers are to be printed, set \[email protected] to a suitable value so that the
first number to be printed will be line #2.
\@tempcnta #2\relax
\divide\@tempcnta\[email protected]@vs
\multiply\@tempcnta\[email protected]@vs
\[email protected] #2\relax
\fi
25
26
27
28
29
30
31
\[email protected]
}
This returns either nothing or a poem line number for printing.
\newcommand{\[email protected]}{\bgroup
\ifnum\[email protected]@vs<\@ne
% no line numbers
34
\else
35
\ifnum\[email protected]@vs<\[email protected] % every line numbered
36
\vlnumfont\thepoemline
37
\else
38
\@tempcnta\[email protected]
39
40
\divide\@tempcnta\[email protected]@vs
41
\multiply\@tempcnta\[email protected]@vs
42
43
\ifnum\@tempcnta=\[email protected]\vlnumfont\thepoemline\fi
44
\fi
45
\fi
46 \egroup}
32
33
\ifaltindent
This should be set TRUE for indenting alternate lines.
47
\ifpattern
This should be set TRUE for indenting lines according to a pattern.
48
\ifstarpattern
\newif\ifaltindent
\newif\ifpattern
This should be set TRUE for indenting lines according in a patverse* environment.
49
\newif\ifstarpattern
16
\versewidth
The package code
\versewidth is a convenience length for the user.
50
\vgap
\vin
\vindent
4
\newlength{\versewidth}
The length \vgap is used as the basis for spacing. \vin makes a horizontal space of
\vgap and \vindent is the indentation of wrapped lines in a verse. \stanzaskip
controls the space between stanzas.
\newlength{\vgap}
\setlength{\vgap}{1.5em}
53 \newcommand{\vin}{\hspace*{\vgap}}
54 \newlength{\vindent}
55 \setlength{\vindent}{2\vgap}
51
52
\vleftskip
\vrightskip
Skips to the left and right of a line of verse.
\newlength{\vleftskip}
\setlength{\vleftskip}{30pt}
60 \newlength{\vrightskip}
61 \setlength{\vrightskip}{10pt}
58
59
\flagverse
\flagverse{hflagi} inserts hflagi at the left (of a line).
\newcommand{\flagverse}[1]{%
\hskip-\vleftskip\llap{#1}\hskip\vleftskip
64
\ignorespaces
65 }
62
63
\verselinebreak
Break a verse line by inserting \newline.1
\newcommand*{\verselinebreak}[1][\[email protected]]{%
\newline\hspace*{#1}%
68
\ignorespaces
69 }
66
67
\[email protected]
Increment the line counters.
\newcommand{\[email protected]}{%
\refstepcounter{poemline}%
72
\stepcounter{vslineno}%
73 }
70
71
\@vsifbang
Like the kernel \@ifstar except it looks for an exclamation mark!
74
\@vsifgt
\newcommand{\@vsifbang}[1]{\@ifnextchar !{\@firstoftwo{#1}}}
Like the kernel \@ifstar except it looks for a > character.
75
\newcommand{\@vsifgt}[1]{\@ifnextchar >{\@firstoftwo{#1}}}
1 In an email to me dated 2006/01/13 Aaron Rendahl pointed out that this should include an
\ignorespaces.
4.2
Verse code
17
\@vstypelinenumright
\@vstypelinenumleft
\verselinenumbersright
\verselinenumbersleft
These control the typesetting of verse line numbers to the right and to the left of
the verse. Default is to set them at the right.
\@vscentercr
This puts the poem line number in the margin, increments the line numbers, and
then deals with the options. It is based on the kernel \@centercr. This has to
handle various forms of the \\ command: \\, \\*, \\!, and \\>, together with
an optional length argument.
\newcommand*{\@vstypelinenumright}{%
\hfill\rlap{\kern\vrightskip\kern\rightmargin\[email protected]}%
78 }
79 \newcommand*{\@vstypelinenumleft}{%
80
\hfill\rlap{\kern-\textwidth\kern-\vrightskip\[email protected]}%
81 }
82 \newcommand*{\verselinenumbersright}{\def\@vstypelinenum{\@vstypelinenumright}}
83 \newcommand*{\verselinenumbersleft} {\def\@vstypelinenum{\@vstypelinenumleft}}
84 \verselinenumbersright
76
77
\newcommand{\@vscentercr}{%
\ifhmode \unskip\else \@nolnerr\fi
87
\@vstypelinenum
88 %%%% \hfill\rlap{\kern\vrightskip\kern\rightmargin\[email protected]}%
85
86
For > call \verselinebreak to process it.
\@vsifgt{\verselinebreak}{%
\[email protected]
89
90
If the call is \\*... call \@vsxcentercr to handle the *.... If the call is \\!,
do nothing. If the call is \\![...], call \@vsicentercr to handle the [...].
Otherwise, call \@vsxcentercr.
\par\@ifstar{\nobreak\@vsxcentercr}{%
\@vsifbang{\@ifnextchar[ {\@vsicentercr}{}}{\@vsxcentercr}%
}%
91
92
93
}%
94
95
\@vsxcentercr
}
Processes \\*, and either calls \@vsicentercr to handle a [length], or
\[email protected]
\newcommand{\@vsxcentercr}{%
98
\@ifnextchar[ {\@vsicentercr}{\[email protected]}%
99 }
96
97
\@vsicentercr
Processes (\\...)[length] and then calls \[email protected]
100
\[email protected]
\def\@vsicentercr[#1]{\vskip #1\ignorespaces \[email protected]}
This is called at the start of every verse line except the first.
\newcommand{\[email protected]}{%
\ifaltindent\ifodd\[email protected]\else\vin\fi\fi%
103
\ifpattern\[email protected]\fi%
104
\ifstarpattern\[email protected]\fi
105 }
101
102
18
verse
4
The package code
The extended verse environment. It sets the verse line counter, then defines the
particular list environment adjusting the margins to center according to the length
parameter. If the length parameter is at least the \linewidth then the ‘centering’
defaults to the original verse layout.
\renewenvironment{verse}[1][\linewidth]{%
\stepcounter{[email protected]}%
108
\setcounter{poemline}{0}\refstepcounter{poemline}%
109
\setcounter{vslineno}{1}%
110
\let\\=\@vscentercr
111
\list{}{\itemsep \[email protected]
112
\itemindent -\vindent%
113
\listparindent\itemindent
114
\parsep
115
\ifdim #1 < \linewidth
116
\rightmargin
\[email protected]
117
\setlength{\leftmargin}{\linewidth}%
118
119
120
\else
121
\rightmargin
\leftmargin
122
\fi
123
124
\item[]%
125 }
126 {\endlist}
106
107
altverse
This sets \altindenttrue (afterwards false) and initialises the line counter.
\newenvironment{altverse}%
{\starpatternfalse\patternfalse\altindenttrue\setcounter{vslineno}{1}}%
129
{\altindentfalse}
127
128
4.3
Pattern code
The pattern code is based on the idea of converting a string of digits to an array
of digits, and then being able to access the digit at a particular position in the
array.
\[email protected]
A shorthand for using \[email protected]
\newcommand{\[email protected]}[1]{%
\expandafter\[email protected]\csname #1\endcsname
132 }
130
131
\ifbounderror
A flag set TRUE if an attempt is made to access an array element outside the
array limits.
133
\ifinteger
\newif\ifbounderror
A flag to indicate if a ‘number’ is an integer (TRUE) or not (FALSE).
134
\newif\ifinteger
4.3
\[email protected]
19
A counter for the number of characters.
135
\newarray
Pattern code
\newcounter{chrsinstr}
% CHARactersINSTRing
\newarray{harraynamei}{hlow i}{hhighi} defines an array called harraynamei (no
backslash e.g. MyArray), with low and high limits hlow i and hhighi.
\newcommand{\newarray}[3]{%
\[email protected]{#1-low}{#2}%
138
\[email protected]{#1-high}{#3}%
139
\ifnum #3<#2
140
\PackageError{verse}{Limits for array #1 are in reverse order}{\@ehc}%
141
\fi
142 }
136
137
\stringtoarray
\stringtoarray{harraynamei}{hstringi} puts each character from hstringi sequentially into the harraynamei array, starting with hlow i = 1. It checks for an
empty hstringi and handles that specially.
\newcommand{\stringtoarray}[2]{%
\def\@vsarrayname{#1}%
145
\[email protected]\[email protected]{#2}%
146
\newarray{\@vsarrayname}{1}{1}%
147
\@ifmtarg{#2}{%
148
\[email protected] \[email protected]
149
\@namedef{\@vsarrayname-1}{}%
150
}{%
151
\[email protected] \@ne
152
\expandafter\@vsstringtoarray \[email protected]\@vsend
153
}%
154 }
143
144
\@vsstringtoarray
Recursively adds characters to the array \@vsarrayname, incrementing the array’s
high limit.
\def\@vsstringtoarray #1#2\@vsend{%
\@namedef{\@vsarrayname-\the\[email protected]}{#1}%
157
\[email protected]{\@vsarrayname-high}{\the\[email protected]}%
158
\@ifmtarg{#2}{%
159
\def\@vsinext{}%
160
}{%
161
162
\def\@vsinext{%
163
\@vsstringtoarray #2\@vsend%
164
}%
165
}%
166
\@vsinext
167 }
155
156
\setarrayelement
\setarrayelement{harraynamei}{hindex i}{hvaluei} sets the harraynamei array’s element at hindex i to hvaluei.
168
169
\newcommand{\setarrayelement}[3]{%
\checkarrayindex{#1}{#2}%
20
4
\[email protected]{#1-#2}{#3}%
170
171
\getarrayelement
The package code
}
\getarrayelement{harraynamei}{hindex i}{hvaluei} defines the parameterless
macro hvaluei (e.g., \result) to be the value at hindex i in the harraynamei array.
\newcommand{\getarrayelement}[3]{%
\checkarrayindex{#1}{#2}%
174
\[email protected]#3{\@nameuse{#1-#2}}%
175 }
172
173
\checkarrayindex
\checkarrayindex{harraynamei}{hindex i} checks that the hindex i of the harraynamei
array is valid. \ifbounderror is set FALSE if everything is OK, otherwise it is
set TRUE.
\newcommand{\checkarrayindex}[2]{%
\bounderrorfalse
178
\expandafter\ifx\csname #1-low\endcsname\relax
179
\ifpattern\else
180
\PackageError{verse}{No array called #1}{\@ehc}%
181
\fi
182
\bounderrortrue
183
\fi
184
\ifnum #2<\@nameuse{#1-low}\relax
185
\ifpattern\else
186
\PackageError{verse}{Index #2 outside limits for array #1}{\@ehc}%
187
\fi
188
\bounderrortrue
189
\fi
190
\ifnum #2>\@nameuse{#1-high}\relax
191
\ifpattern\else
192
\PackageError{verse}{Index #2 outside limits for array #1}{\@ehc}%
193
\fi
194
\bounderrortrue
195
\fi
196 }
176
177
\@ifmtarg
Provides an if-then-else command for an empty macro argument (empty = zero
or more spaces only). Use as:
\@ifmtarg{arg1}{Code for arg1 empty}{Code for arg1 not empty}
This code is copied from my ifmtarg package.
\begingroup
\catcode‘\Q=3
199 \long\gdef\@ifmtarg#1{\@xifmtarg#1QQ\@secondoftwo\@firstoftwo\@nil}
200 \long\gdef\@xifmtarg#1#2Q#3#4#5\@nil{#4}
201 \long\gdef\@ifnotmtarg#1{\@xifmtarg#1QQ\@firstofone\@gobble\@nil}
202 \endgroup
197
198
\arraytostring
\arraytostring{harraynamei}{hstringi} converts the characters in the harraynamei
array into the parameterless macro hstringi (e.g., \MyString).
203
\newcommand{\arraytostring}[2]{%
4.3
205
206
\@vsarraytostring
21
\def#2{}%
\[email protected] = \@nameuse{#1-low}%
\@vsarraytostring{#1}{#2}%
204
207
Pattern code
}
\@vsarraytostring{harraynamei}{hstringi} recursively adds the (character) elements from harraynamei to hstringi.
\newcommand{\@vsarraytostring}[2]{%
\ifnum\[email protected]>\@nameuse{#1-high}\else
210
\[email protected]#2{#2\@nameuse{#1-\thechrsinstr}}%
211
212
\@vsarraytostring{#1}{#2}%
213
\fi%
214 }
208
209
\checkifinteger
\checkifinteger{hnumi} checks if hnumi is an integer. If it is, then \ifinteger
is set TRUE, otherwise it is set FALSE. (Code based on Donald Arseneau’s cite
package).
\newcommand{\checkifinteger}[1]{%
\[email protected]\@vsa{#1}%
217
\ifcat _\ifnum9<1\gobm{#1} _\else A\fi
218
\integertrue
219
\else
220
\integerfalse
221
\fi
222 }
215
216
\gobm
\gobm{hnumi} is defined as hnumi. It could be defined as:
\newcommand{\gobm}[1]{\ifx-#1\expandafter\gobm\else#1\fi}
which would remove a leading minus sign (hyphen) from its argument (gobm
= gobble minus sign). (Code from a posting to CTT by Donald Arseneau on
1997/07/21).
223
\indentpattern
\newcommand{\gobm}[1]{#1}
\indentpattern{hdigitsi} stores hdigitsi for use as a verse indentation pattern.
\newcommand{\indentpattern}[1]{%
\stringtoarray{[email protected]}{#1}%
226 }
224
225
\[email protected]
\[email protected] gets the indent pattern digit for the \thevslineno, then uses this
to specify the line indentation as digit*\vgap.
\newcommand{\[email protected]}{%
\getarrayelement{[email protected]}{\number\value{vslineno}}{\@vspat}%
229
\ifbounderror
230
\arraytostring{[email protected]}{\@[email protected]}%
231
\PackageWarning{verse}{%
232
Index ‘\thevslineno’ for pattern ‘\@[email protected]’ is out of bounds}%
233
\def\@vspat{0}%
227
228
22
4
\else
\checkifinteger{\@vspat}%
\ifinteger\else
\arraytostring{[email protected]}{\@[email protected]}%
\PackageWarning{verse}{%
‘\@vspat’ at index ‘\thevslineno’ in pattern ‘\@[email protected]’ is not a digit}%
\def\@vspat{0}%
\fi
\fi
\ifcase\@vspat\else\hspace*{\@vspat\vgap}\fi
234
235
236
237
238
239
240
241
242
243
244
\[email protected]
The package code
}
\[email protected] gets the indent pattern digit for the patverse* environment,
then uses this to specify the line indentation as digit*\vgap. It lets the pattern
repeat by resetting the vslineno counter.
\newcommand{\[email protected]}{%
\expandafter\ifx\csname [email protected]\endcsname\relax
247
\PackageError{verse}{A pattern has not been specified}{\@ehc}%
248
\else
249
\ifnum\[email protected]>\@nameuse{[email protected]}%
250
\setcounter{vslineno}{1}%
251
\fi
252
\[email protected]
253
\fi
254 }
245
246
patverse
The environment for setting verse line indents according to a pattern. It starts
by setting \ifpattern TRUE, any other flags to FALSE, and initialises the line
number. It ends by setting \ifpattern FALSE.
\newenvironment{patverse}
{\starpatternfalse\patterntrue\altindentfalse\setcounter{vslineno}{1}}
257
{\patternfalse}
255
256
patverse*
The environment for setting verse line indents according to a repeating pattern. It
starts by setting \ifstarpattern TRUE, any other flags to FALSE, and initialises
the line number. It ends by setting \ifstarpattern FALSE.
\newenvironment{patverse*}
{\starpatterntrue\patternfalse\altindentfalse\setcounter{vslineno}{1}}
260
{\starpatternfalse}
258
259
4.4
\poemtitle
Title code
Typeset a poem title (like \section or other). The actual work is done by
\@vsptitle (plain) or \@vssptitle (starred).
\newcommand{\poemtitle}{%
\par
263
\secdef\@vsptitle\@vssptitle
264 }
261
262
References
\poemtoc
The kind of entry \poemtitle is to make in the ToC.
265
\@vsptitle
23
\newcommand{\poemtoc}{section}
Typeset a poemtitle.
\def\@vsptitle[#1]#2{%
\@nameuse{phantomsection}%
268
269
\poemtitlemark{#1}%
270
\@vstypeptitle{#2}%
271
272 }
266
267
\@vssptitle
Typeset a \poemtitle*.
\def\@vssptitle#1{%
\@vstypeptitle{#1}
275
276 }
273
274
\@vstypeptitle
This really typesets the title.
\newcommand{\@vstypeptitle}[1]{%
\vspace{\beforepoemtitleskip}%
279
{\poemtitlefont #1\par}%
280
\vspace{\afterpoemtitleskip}%
281 }
277
278
\poemtitlefont
\poemtitlemark
Sets the appearance to the title of a poem, and something for a header.
282
283
\beforepoemtitleskip
\afterpoemtitleskip
\newcommand{\poemtitlefont}{\normalfont\large\bfseries\centering}
\newcommand{\poemtitlemark}[1]{}
Lengths before and after a poem title, using the \section values.
\newlength{\beforepoemtitleskip}
\setlength{\beforepoemtitleskip}{3.5ex \@plus 1ex \@minus .2ex}
286 \newlength{\afterpoemtitleskip}
287 \setlength{\afterpoemtitleskip}{2.3ex \@plus.2ex}
284
285
The end of this package.
288
h/usci
References
[GMS94] Michel Goossens, Frank Mittelbach, and Alexander Samarin. The LaTeX
[Wil01]
Peter Wilson. A Rumour of Humour: A scientist’s commonplace book.
To be published.
24
Index
Index
Numbers written in italic refer to the page where the corresponding entry is described; numbers underlined refer to the code line of the definition; numbers in
roman refer to the code lines where the entry is used.
Symbols
\@ehc . . . . . . . . 142,
187, 193, 199, 258
\@firstofone . . . . . . 209
\@firstoftwo 78, 79, 207
\@ifmtarg . 150, 162, 205
\@ifnextchar . . . . . .
. . . . 78, 79, 96, 98
\@ifnotmtarg . . . . . . 209
\@ifstar . . . . . . . . . 95
\@namedef . . . . 152, 160
\@nameedef . . . 129,
139, 140, 161, 175
\@nameuse . . . . 180,
191, 197, 214,
219, 220, 260, 279
\@nolnerr . . . . . . . . 90
\@secondoftwo . . . . . 207
\@vsa . . . . . . . . . . . . 227
\@vsarrayname . 147,
149, 152, 160, 161
\@vsarraytostring .
. . . . . . . . 215, 218
\@vscentercr . . . 89, 109
\@vsend . . . 155, 159, 167
\@vsicentercr 96, 98, 99
\@vsifbang . . . . . 78, 96
\@vsifgt . . . . . . . 79, 93
\@vsinext . 163, 166, 170
\@[email protected] 242, 244, 249, 251
\@vspat . . . 240, 245,
247, 251, 252, 255
\@vsptitle . . . 275, 278
\@vssptitle . . . 275, 285
\@vsstringtoarray .
. . . . . . . . 155, 159
\@vstypelinenum . . .
. . . . . . . 85, 86, 91
\@vstypelinenumleft 81
\@vstypelinenumright 81
\@vstypeptitle . . . .
. . . . 282, 286, 289
\@vsxcentercr 95, 96, 97
\@xifmtarg . . . 207–209
\\ . . . . . . . . . . . . . . . 6
A
\addtocounter . . . . . 26
\afterpoemtitleskip
. . . . . . 7, 292, 298
\altindentfalse . . .
. 53, 127, 267, 271
\altindenttrue . . . . 126
altverse
(environment) . . . . 5, 125
\arraytostring . . . .
. . 7, 212, 242, 249
B
\baselineskip . . . . .
\beforepoemtitleskip
. . . . . . 7, 290,
\bounderrorfalse . .
. . . . . . . . 133,
\bounderrortrue . . .
. . . . 189, 195,
64
298
184
201
C
\[email protected] 136, 151,
154, 160, 161,
165, 214, 219, 221
\[email protected] . . . . . . .
. . 5, 32, 33, 43, 46
\[email protected]@vs . 28, 30,
31, 37, 39, 44, 45
\[email protected] . . . . . 42, 47
\[email protected] . . . 101, 260
\catcode . . . . . . . . . 206
\centering . . . . . . . 295
\checkarrayindex . .
. . 7, 174, 179, 183
\checkifinteger . . .
. . . . . . 8, 226, 247
\csname . . . 130, 185, 257
E
\endcsname 130, 185,
environments:
altverse . . . . 5,
patverse . . . . 5,
patverse* . . . . 5,
verse . . . . . . . 5,
\flagverse
257
125
266
270
105
F
. . . . . . 6, 71
G
\[email protected] . . . . .
. . . . 102, 239, 263
\getarrayelement . .
. . . . . . 7, 178, 240
\[email protected] . . . . .
. . . . 36, 82, 84, 92
\[email protected] .
. . . . . . . . 103, 256
\gobm . . . . . . . . 228, 234
I
\ifaltindent . . . 52, 101
\ifbounderror . 132, 241
\ifcat . . . . . . . . . . . 228
\ifinteger . . . 134, 248
\ifodd . . . . . . . . . . . 101
\ifpattern . . . . 54,
102, 186, 192, 198
\ifstarpattern . 56, 103
\ignorespaces 71, 73, 99
\[email protected] . . . . 74, 94
\indentpattern . . 5, 236
\integerfalse . . . . . 231
\integertrue . . . . . . 229
\item . . . . . . . . . . . . 123
\itemindent . . . 111, 112
\itemsep . . . . . . . . . 110
L
\label . . . . . . . . . . . . 7
\large . . . . . . . . . . . 295
Index
25
\leftmargin . . . . . . .
. 116–118, 120, 122
\leftmargini . . . . . . . 5
\linewidth 105, 114, 116
\listparindent . . . . 112
M
\[email protected] . . . . . . . . 5
\multiply . . . . . . 31, 45
N
\newarray . . 7, 138,
\newif 52, 54, 56, 132,
\newline . . . . . . . . .
\normalfont . . . . . . .
149
134
73
295
P
\PackageError . 142,
187, 193, 199, 258
\PackageWarning 243, 250
\parsep . . . . . . . . . . 113
\parskip . . . . . . . . . 97
\patternfalse . . . . .
. 55, 126, 268, 271
\patterntrue . . . . . . 267
patverse
(environment) . . . . 5, 266
patverse*
(environment) . . . . 5, 270
\poemline . . . . . . . . . 5
\poemlines . . . . . . 6, 13
\poemtitle . . . . . 7, 274
\poemtitlefont . . . .
. . . . . . 7, 291, 295
\poemtitlemark . . . .
. . . . . . 7, 281, 295
\poemtoc . . . 7, 276, 280
\[email protected] 130,
148, 180, 220, 227
\ProvidesPackage . . . 3
\[email protected] .
\thechrsinstr .
\theHpoemline .
\theHpoemlines
\thepoemline . .
\thevslineno . .
Q
\Q . . . . . . . . . . . . . . 206
V
\value . . . . . . . . . . . 240
verse (environment) 5, 105
\[email protected] . . . . . . 5
\verselinebreak 6, 73, 93
\verselinenumbersleft
. . . . . . . . . . 6, 81
\verselinenumbersright
. . . . . . . . . . 6, 81
\verselinenumfont 6, 22
\versewidth . . . . . . 5, 59
\vgap . . . . . . . 5, 61, 255
\vin . . . . . . . . 5, 61, 101
\vindent
5, 61, 111, 122
\vleftskip . . . 6, 66, 71
\vlnumfont . . 22, 40, 47
\vlvnumfont . . . . . . . 22
\vrightskip . . . . . . .
. . 6, 66, 82, 84, 92
\vslineno . . . . . . . . . 5
R
\ref . . . . . . . . . . . . . . 7
\renewenvironment . 105
S
\setarrayelement 7, 173
\setverselinenums 6, 25
\stanzaskip . . 6, 61, 113
\starpatternfalse .
. 57, 126, 267, 272
\starpatterntrue . . 271
\[email protected] 98, 99, 100
\stepcounter . . . 76, 106
\stringtoarray . . . .
. . . . . . 7, 146, 237
\textwidth
T
.......
84
148, 155
. . . . 220
. . . . 11
..... 5
6, 40, 47
244, 251
U
\unskip . . . . . . . . . .
90