6

I will write a Book of Poetry, written by many authors. I hope that each author will write a poem in a plain text file.

So far, I wrote a master file BookOfPoetry.tex

\documentclass{article}
\begin{document}
\input{Poetry/FirstPoetry.txt}
\end{document}

and FirstPoetry.txt

\title{theTitle}
\author{theAuthor}
\date{theDate}
\maketitle
\begin{verbatim}
it is first line
it is second line
\end{verbatim}

How to simplify the writing of a text file with minimal formatting like this FirstPoetryRev.txt

theTitle
theAuthor
theDate

it is first line
it is second line 

then the BookOfPoetry.tex will translate

  • the first line as the title
  • the second line as the author
  • the third line as the date
  • and (space)
  • the fifth line and so on as the content of the poem, without writing \\ at the end of each line.
10
  • 1
    Consider using the package 'fancyvrb' so you can control the font. Then have each author put each poem in a separate file with it formated by the author exactly as they want it to appear. Mar 11, 2015 at 3:40
  • the authors aren't familiar with using LaTeX.
    – Edy Jo
    Mar 11, 2015 at 3:48
  • They don't need to be. That's why you pipe it in verbatim. I would just preprocess the files with awk, say, to add the \title{} \author{} \date{} \maketitle and whichever environment you end up using. You can do it with LaTeX. But I don't see the point.
    – cfr
    Mar 11, 2015 at 4:01
  • Do you require any formatting of the content? Specifically, the title-related stuff?
    – Werner
    Mar 11, 2015 at 5:14
  • I've downloaded GAWK from here, and then install it. I've tried to execute the program makeitemizelist and it work. gawk -f makeitemizelist.awk FirstPoetry.txt But, the execution results displayed in the command window. How to make it as a LaTeX file?
    – Edy Jo
    Mar 11, 2015 at 5:20

2 Answers 2

4

enter image description here

\documentclass{article}
\usepackage{fancyvrb}  
\begin{document}
\renewcommand{\FancyVerbFormatLine}[1]{%
\ifcase\value{FancyVerbLine}\or
\makebox[\textwidth]{\huge#1\strut}\or
\makebox[\textwidth]{\LARGE#1\strut}\or
\makebox[\textwidth]{\Large#1}\else#1\fi}
\VerbatimInput{file}
\end{document}

Edit table of contents add

\documentclass{article}
\usepackage{fancyvrb}  
\begin{document}
\tableofcontents
\renewcommand{\FancyVerbFormatLine}[1]{%
\ifcase\value{FancyVerbLine}\or
\makebox[\textwidth]{\xdef\mttitle{#1}\huge#1\strut}\or
\makebox[\textwidth]{\addcontentsline{toc}{section}{\mttitle\ by #1}\LARGE#1\strut}\or
\makebox[\textwidth]{\Large#1}\else#1\fi}
\VerbatimInput{file}
\newpage
\VerbatimInput{file1}
\end{document}
4
  • A simple and elegant solution!
    – Daniel
    Mar 11, 2015 at 13:28
  • @touhami, How to add the title and author of each poem to the Table of Contents (TOC)?
    – Edy Jo
    Mar 11, 2015 at 19:53
  • In my case, it is necessary to add file extension. \VerbatimInput{FirstPoetry.txt} \newpage \VerbatimInput{SecondPoetry.txt} etc.
    – Edy Jo
    Mar 11, 2015 at 20:02
  • @EdyJo I edit the answer
    – touhami
    Mar 11, 2015 at 20:55
1

For completeness I will add my solution here.

I use memoir as the class and verse and gmverse packages. Gmverse is great and gives you:

  1. automatic visual centering of each poem. (no need to enter the longest line and calc its length)
  2. No need for \ at the end of each line (but NOT last line) if each stanza. This makes copy and paste from emails or text, word etc files much easier.

Then I use subfiles package which acts like include but each subfile also knows the name of the major doc file and can read the preamble (before \begin{document}) and therefore be compiled independently. This makes editing, assembling and creating several collections (ie journal submissions) simpler than one big file. It also keeps the single poem template quite small. Reordering is also easier.

So I re-use a template for each poem (on the Mac you set the file to be stationery in the info panel, and then a double click will give a new copy of the file) and rename them as needed.

Template for a single poem:

\documentclass[older_poems_40.tex]{subfiles}

\begin{document}

\vocweigh3      %needed for gmverse package, must be here not    
                %  in preamble

\thispagestyle{empty} %remove before using as subfile

\PoemTitle{TITLE} %%%% this will be numbered * version is not numbered
%\epigraph{}{}
\begin{verse} 
\index{FIRST_LINE}FIRST_line of poem
line 2
line 3

new stanza 1
line 2
\end{verse}


\end{document}

The main file of course has lots of formatting stuff in so I will add a truncated version here. (But note I have kept the list of poems (contents) and also the index of first lines (which needs you to re-run make index after you add a new subfile) for your pleasure.

%file = older_poems_40.tex
\documentclass[12pt, twoside]{memoir}


%\usepackage[utf8]{inputenc}  % I use Xetex so I don't need this anymore

\usepackage{epigraph}
    % set a note, subtitle quote or source under the poem title 
\setlength{\epigraphwidth}{.45\textwidth} % Was 0.4 
 
\usepackage{makeidx}
\makeindex

\usepackage{verse, gmverse}
\usepackage{currfile} %% to get a compile date for records/sanity
\usepackage{hyperref}


\renewcommand{\PoemTitlefont}{\Large\slshape\centering} 


\title{Your poetry book name here}

\author{Your name here!}
\date{}


\hypersetup{
pdftitle={poems of blah},
pdfsubject={blah},
pdfauthor={David J. Garbutt},
pdfkeywords={poetry}
}
% or set to blank for anonymous submissions 


\usepackage{subfiles}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%.  DOCUMENT%%%%%%%%%%%%%%
\begin{document}

\maketitle

\epigraph{street }{town, postcode, country}

\clearpage
\tableofcontents

\vfill

Compiled from \texttt{\currfilepath} on \today{}.

\clearpage

\subfile{poem1}

\clearpage
\subfile{poem2} %.tex is assumed

%% repeat lots of poems…
%% here I have clear pages only in the master file this makes it easier
%% to create a more compact version if wanted. 

%%%%% end poems
\renewcommand\indexname{Index of First Lines}
\onecolindex

\printindex 
\end{document}

It is up to you to make sure the file pointed to in the single poem template is the one with the subfile statements in!

You must log in to answer this question.

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