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.
  • 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. – R. Schumacher Mar 11 '15 at 3:40
  • the authors aren't familiar with using LaTeX. – Edy Jo Mar 11 '15 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 '15 at 4:01
  • Do you require any formatting of the content? Specifically, the title-related stuff? – Werner Mar 11 '15 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 '15 at 5:20
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}
  • A simple and elegant solution! – Daniel Mar 11 '15 at 13:28
  • @touhami, How to add the title and author of each poem to the Table of Contents (TOC)? – Edy Jo Mar 11 '15 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 '15 at 20:02
  • @EdyJo I edit the answer – touhami Mar 11 '15 at 20:55

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.