0

In the poetry anthology I'm compiling, the poems are fairly unsorted (and since it followed hand-written notes, that can't be changed). I would like to create a handful of groups, such as War, Love, Birthdays, Misc, and then have one List of Poems for each of them.

The package specifies a way of adding groups to the LoP, but it seems this is mostly done for cases where the poems are arranged according to the group. That is, first all War poems, then all Love poems, etc.

So, is there a way to create tags and then print custom list of poems?

MWE below. I have not implemented any groupings, and honestly, I don't really understand how to use that part of the package. I'm very grateful for the help in this forum!

UPDATED! I've changed the MWE to look like what I'm trying to achieve -- that is, the sections "Limericks" and "Songs" at the end are now written manually, but I'd want a way to achieve them automatically. Please excuse the ugliness of repeated dots, I didn't want to enlarge the MWE by using proper tables or similar.

\documentclass[]{article}

\usepackage{poetry}\poemlinenumsfalse

\begin{document}

\poemfirstline{In a cavern} % Tag: Song
\addtolop{Clementine}
\section*{Clementine}\vspace{-0.5cm}
\begin{poem}
In a cavern\\
In a canyon\\-
\end{poem}


\poemfirstline{Imagine there's no heaven} % Tag: Song
\addtolop{Imagine}
\section*{Imagine}\vspace{-0.5cm}
\begin{poem}
Imagine there's no heaven\\
It's easy if you try\\-
\end{poem}


\poemfirstline{There once was a man from Nantucket} % Tag: Limerick
\addtolop{The man from Nantucket}
\section*{The man from Nantucket}\vspace{-0.5cm}
\begin{poem}
There once was a man from Nantucket\\
Who kept all his cash in a bucket\\-
\end{poem}


\poemfirstline{Is this the real life?} % Tag: Song
\addtolop{Bohemian Rhapsody}
\section*{Bohemian Rhapsody}\vspace{-0.5cm}
\begin{poem}
Is this the real live?\\
Is this just fantasy?\\-
\end{poem}


\poemfirstline{There once was a lady from Riga} % Tag: Limerick
\addtolop{The tiger ride}
\section*{The tiger ride}\vspace{-0.5cm}
\begin{poem}
There once was a lady from Riga\\
Who went for a ride on a tiger\\-
\end{poem}


\section*{Index}
\listofpoems

\section*{Limericks}
The man from Nantucket..................1\\
The tiger ride.....................................1

\section*{Songs}
Clementine ...................................1\\
Imagine........................................1\\
Bohemian Rhapsody.......................1



 
\printiofl

\end{document}
2
  • In a situation like yours I’d check tag poetry, which often leads to conclusions: tex.stackexchange.com/questions/tagged/poetry
    – MS-SPO
    Apr 11, 2022 at 9:55
  • @MS-SPO I looked through the tag but couldn't find anything about how to create filtered lists of poems unfortunately.
    – Wilhelm
    Apr 11, 2022 at 10:22

2 Answers 2

1

Here is one way to achieve what you have in mind with Latex. Key was to recognize that what you call "tagging" is "indexing" in Latex. And in fact you want more than one index. Here we go, topic by topic.

For sorting, extracting, adminstrating etc. your poems I'd still like to redirect you to my first answer https://tex.stackexchange.com/a/640414/245790. In fact, you could let the database generate the required code (see \newcommand below).

% .. make sure:
% .... do a first compile
% .... run from command line in same directory:
% ...... splitindex <filename_without_extension>
% .... do a second compile

\documentclass[12pt]{article}

\usepackage{verse} % <<< package poetry didn't work well

% --- "tagging", i.e. creating multiple indexes
\usepackage{splitidx}
\makeindex
% --- generic indexes --------------
\newindex[Index of First Lines]{frst}
\newindex[Index of Titles]{ttl}

% --- "tagging" --------------------
\newindex[Index of Songs]{sng}
\newindex[Index of Limericks]{lim}

% --- making editing easier --------
\newcommand\pom[4]{ % title / tag / firstLine / verses
 \begin{verse}
   \poemtitle{#1}
   \sindex[ttl]{#1}
   \sindex[#2]{#1}
   \sindex[frst]{#3}
   #4
 \end{verse}
}

% --- content -----------
\begin{document}
 % how you would do it manually
 \begin{verse}
   \poemtitle{Clementine}
   \sindex[ttl]{Clementine}
   \sindex[sng]{Clementine}
   \sindex[frst]{In a canyon}
   In a canyon\\
 \end{verse}


\pom{Imagine}{sng}{Imagine there's no heaven}{
Imagine there's no heaven\\
It's easy if you try
}

 \pom{The man from Nantucket}{lim}{There once was a man from Nantucket}{
 There once was a man from Nantucket\\
 Who kept all his cash in a bucket
 }
 
 \printindex*
 
\end{document}

The comments on top of the code illustrate the workflow you have to follow: compile, run splitindex, recompile again. This replaces the normal workflow using makeindex (shell command) to extract and generate all required index-files.

Package poetry unfortunately seems to cause problems with other packages. So I decided to replace it by package verse, which gives you many options to style and present your poems. See https://mirror.marwan.ma/ctan/macros/latex/contrib/verse/verse.pdf for more details.

Next, there are a few ways to create multiple indexes. E.g. wikibooks on Latex still mentions multind, but using a more up to date package like splitidx is recommended. See https://mirror.marwan.ma/ctan/macros/latex/contrib/splitindex/splitidx.pdf for more details.

Using splitindex you can create the entries package poetry had provided AND additional "tags". To expand this create a \newindex[headline]{tag} statement in the preamble and put \sindex[tag]{text} inside your verses where useful.

As you will see in the content part, creating the required content can be cumbersome, boring and error-prone. As a short-cut I defined my own new command called \pom, which takes 4 parameters and puts them where they should be.

In the content part I used "Clementine" to show what you'd need to create manually. That works, if you want it that way (I shortended the verses to reduce code size, to focus on the relevant parts).

The next two \pom statements will expand into exactly the same code as the manually created one.

Remember to compile, splitindex and recompile once you finished editing.

Finally splitindex's \printindex* shows all the indexes from above. By default, i.e. you can modify both, it puts pagebreaks and uses a two-column layout (that's why the Nantucket entry is a bit weird). So you'll find "Index of First Lines", "Index of Titles", "Index of Songs" and "Index of Limericks", just as the preamble specified. See the documentation to further configure \printindex.

That's it. Here's a screenshot preview of the first 1 1/4 pages.

Preview

2
  • This looks exactly like what I was looking for! Unfortunately, running the splitindex doesn't work, the computer says I'm missing the perl script engine... :/
    – Wilhelm
    Apr 12, 2022 at 13:35
  • 1
    Fine :) Just install a perl version and repeat.
    – MS-SPO
    Apr 12, 2022 at 13:39
0

Having peeked into the poem-manual, I agree it probably does not support categories and extraction.

However, this is a typical task for databases. Though you can introduce database-functions in Latex, it's probably easier to do in an external DB, like Access for example. While you could do it with a spreadsheet, too, with bigger datasets you quickly want to turn to databases: they were made for this purpose.

There is more than one way to do it ... here's an example combining Access and Latex, in separate workflows.

You basically need two things:

  • a table, where you enter your poems (as text of arbitrary length), together with all kinds of categories and extras as you like and need, like more sorting criteria
  • a query, which extracts the poems according to your search criteria.

The "poems" are just the text snippets from your Latex-source between \poemfirstline and \end{poem}.

Once you have it, store only what you need (i.e. the poem-field) as 1 big text file, which you either c&p into your document or save it and \include it.

Here are some screenshots for further reference in its most basic form.

Table, holding all Latex-coded poems: DB and some Latex-entries

Example for a query on category "A": Query for category "A"

Results, to be exported/stored as ASCII: Result: only "A"-poems

So your code would collapse to sth. like the following, assuming a file extracted_poems.tex in your root directory:

\documentclass[]{article}
\usepackage{poetry}\poemlinenumsfalse

\begin{document}
  \include{extracted_poems} % create by external DB query

  \section*{Index}
  \listofpoems

  \printiofl

\end{document}
9
  • This is a great way to include only the poems I want in the anthology, but I want all of them, in various order -- just printed in separate indexes.
    – Wilhelm
    Apr 11, 2022 at 15:24
  • I've updated the MWE to mimic what I'm hoping to achieve automatically.
    – Wilhelm
    Apr 11, 2022 at 15:41
  • Ok, unfortunately this site is not made for discussion. I'm about to flag your initial post requesting improvement, as the code you presented, does not compile for me, even if I discard most of its content. It has several unclear issues, like how often does a specific poem occure in-pdf?// Perhaps it's a good idea to create a short hand-drafted Latex version of what you want as a final result (pdf) ? I suspect your code is closer to pseudocode than to code which compiles, isn't it? // Next would be finding a way to achieve your objective.
    – MS-SPO
    Apr 11, 2022 at 17:11
  • Can it be that you want poetrytex? See e.g. chapter "Grouping and linking" in ctan.math.washington.edu/tex-archive/macros/latex/contrib/…
    – MS-SPO
    Apr 11, 2022 at 17:14
  • Do you compile it locally? There's a name collision making the poetry package difficult to use with MikTeX. The example compiles in Overleaf, see links at the end. Apart from that, I don't really know what you mean by it looking like pseudocode? (I mean, I know what pseudocode is, but the example isn't close to it). The example shows what I'd like to happen, but done manually instead of done by LaTeX. I'm hopeful there's a better way. Example in Overleaf: overleaf.com/read/fpqzmxzjkxkp Pdf: 1drv.ms/b/s!AsSmByL8vZhWi_dyVw4eLrsFvEhg3Q?e=5hOww9
    – Wilhelm
    Apr 11, 2022 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .