TransWikia.com

3-level Verse in LaTeX

TeX - LaTeX Asked by user156344 on July 13, 2021

In Vietnamese, there is a type of poem (song thất lục bát — double seven – six – eight) which goes like this

                       LIPSUM

  Lorem ipsum dolor sit amet, consectetur adipiscing
  Elit, sed do eiusmod tempor incididunt ut
    Labore et dolore magna aliqua. Ut
Enim ad minim veniam, quis nostrud exercitation ullamco
  Laboris nisi ut aliquip ex ea commodo
  Consequat. Duis aute irure dolor in reprehenderit 
    In voluptate velit esse cillum dolore
Eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat.

                                            Lipsum, 2018

(After two 7-word sentences is a 6-word sentence and then a 8-word sentence, and then another two 7-word sentences, and so on)

The alignment of the poem needs to be as above.

JosephHarriott’s answer has helped me a lot in 2-level verse. However, I can’t edit it so that it can output a 3-level verse.

Also, is it possible to make a n-level verse for any value of n? (this is not necessary right now, but it may help me in the future).

Any helps will be highly appreciated. Thanks in advance!

2 Answers

This 1st version just types as text, indenting as it goes. Therefore, it is left-aligned to the margin and can break mid-verse across page boundaries.

documentclass[12pt]{article}
usepackage{listofitems}
newcommanddefineverse[1]{%
  setsepchar{,}%
  greadlist*vindent{#1}%
}
newcommandsetverse[1]{%
  parnoindent%
  setsepchar{}%
  readlist*versedata{#1}%
  ifnumlistlenversedata[]=listlenvindent[]relax%
    foreachitemxinversedata{%
      ifnumxcnt=1relaxelsefi%
      mbox{}hspace{vindent[xcnt]dimexprverseindentrelax}%
      x%
    }%
  else%
    textit{Line count does not correspond to verse definition.}
  fi%
  par%
}
defverseindent{1em}
begin{document}
defineverse{1,1,2,0,1,1,2,0}
setverse{
Lorem ipsum dolor sit amet, consectetur adipiscing
Elit, sed do eiusmod tempor incididunt ut
Labore et dolore magna aliqua. Ut
Enim ad minim veniam, quis nostrud exercitation ullamco
Laboris nisi ut aliquip ex ea commodo
Consequat. Duis aute irure dolor in reprehenderit 
In voluptate velit esse cillum dolore
Eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat.}
bigskip Try to set a poorly composed verse:
setverse{Abcd}
end{document}

enter image description here

Here is a version that creates each verse in a stack. Therefore, it can be easily centered. But the verse cannot break across pages.

documentclass[12pt]{article}
usepackage{listofitems,stackengine}
newcommanddefineverse[1]{%
  setsepchar{,}%
  greadlist*vindent{#1}%
}
newcommandsetverse[2][]{%
  par%
  ifxrelax#1relaxelsecenterline{#1}medskipfi%
  setsepchar{}%
  readlist*versedata{#2}%
  ifnumlistlenversedata[]=listlenvindent[]relax%
    saveboxstackedbox{}%
    foreachitemxinversedata{%
      stackengine{0pt}{usebox{stackedbox}}{%
      mbox{strut}%
      hspace{vindent[-xcnt]dimexprverseindentrelax}%
      versedata[-xcnt]}{O}{l}{T}{F}{S}%
    }%
    centerline{usebox{stackedbox}}%
  else%
    textit{Line count does not correspond to verse definition.}
  fi%
  parmedskip%
}
newcommandattribution[1]{%
  centerline{hspace{wdstackedbox}makebox[0pt][r]{#1}}%
  par
}
defverseindent{1em}
begin{document}
defineverse{1,1,2,0,1,1,2,0}
setverse[Lipsum]{
Lorem ipsum dolor sit amet, consectetur adipiscing
Elit, sed do eiusmod tempor incididunt ut
Labore et dolore magna aliqua. Ut
Enim ad minim veniam, quis nostrud exercitation ullamco
Laboris nisi ut aliquip ex ea commodo
Consequat. Duis aute irure dolor in reprehenderit 
In voluptate velit esse cillum dolore
Eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat.}%
setverse{
Lorem ipsum dolor sit amet, consectetur
Elit, sed do eiusmod tempor incididunt ut
Labore et dolore magna aliqua. Ut
Enim ad minim veniam, quis nostrud exercitation
Laboris nisi ut aliquip ex ea commodo
Consequat. Duis aute irure dolor in reprehenderit 
In voluptate velit esse cillum dolore
Eu fugiat nulla pariatur. Excepteur sint occaecat.}%
attribution{Lipsum, 2018}

bigskip Try to set a poorly composed verse:

fbox{setverse{Abcd}}
end{document}

enter image description here

Correct answer by Steven B. Segletes on July 13, 2021

You can try with the verse package.

documentclass{report}
usepackage{verse}
begin{document}
begin{verse}
indentpattern{0010} % line indents
begin{patverse}
First line 
Second line 
Third line 
hspace{-vgap}Fourth line 
end{patverse}
begin{patverse}
Fifth line 
Sixth line 
Seventh line 
hspace{-vgap}Eifgth line 
end{patverse}
end{verse}

end{document}

See the verse package documentation (> texdoc verse) for more information.

EDIT

I have updated the above answer showing a better result.

% verseprob.tex  SE 462211
documentclass{report}
usepackage{verse}
begin{document}
indentpattern{00100} % line indents

poemtitle{First verse}
begin{verse}[0.13textwidth]  % move verse to the right (centering)
begin{patverse}
First line 
Second line 
Third line 
hspace{-vgap}Fourth line 
end{patverse}
begin{patverse}
Fifth line 
Sixth line 
Seventh line 
hspace{-vgap}Eigth line 
end{patverse}
end{verse}

poemtitle{Second verse}
begin{verse} % verse near left margin
begin{patverse}
First line 
Second line 
Third line 
hspace{-vgap}Fourth line 
end{patverse}
begin{patverse}
Fifth line 
Sixth line 
Seventh line 
hspace{-vgap}Eigth line 
end{patverse}
end{verse}

end{document}

enter image description here

Answered by Peter Wilson on July 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP