6

I'm trying to make a kind of breviary containing psalms indented like e.g. here
What I managed so far is indenting by hand every two other verses. It goes like this:

\documentclass[12pt,a4paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}

\noindent O God, you are my God, for you I long; *\\
for you my soul is thirsting.\\
\indent My body pines for you *\\
\indent like a dry, weary land without water.\\
So I gaze on you in the sanctuary *\\
to see your strength and your glory.\\
\indent For your love is better than life, *\\
\indent my lips will speak your praise.\\
So I will bless you all my life, *\\
in your name I will lift up my hands.\\
\indent My soul shall be filled as with a banquet, *\\
\indent my mouth shall praise you with joy.\\
On my bed I remember you. *\\
On you I muse through the night\\
\indent for you have been my help; *\\
\indent in the shadow of your wings I rejoice.\\
My soul clings to you; *\\
your right hand holds me fast.\\
\indent Glory to the Father, and to the Son, *\\
\indent and to the Holy Spirit:\\
as it was in the beginning, is now, *\\
and will be for ever. Amen.

\end{document}

It looks fine but takes a lot of nonsense work.
Does anyone know how to automatize the job? Thanks in advance.

Precluch
  • 117

2 Answers2

7

enter image description here

\documentclass[12pt,a4paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}


\begingroup
\setlength\parskip{0pt}
\def\par{\ifvmode\noindent\else\endgraf\fi}
\obeylines


O God, you are my God, for you I long; *

for you my soul is thirsting.
My body pines for you *
like a dry, weary land without water.

So I gaze on you in the sanctuary *

to see your strength and your glory.
For your love is better than life, *
my lips will speak your praise.

So I will bless you all my life, *

in your name I will lift up my hands.
My soul shall be filled as with a banquet, *
my mouth shall praise you with joy.

On my bed I remember you. *

On you I muse through the night
for you have been my help; *
in the shadow of your wings I rejoice.

My soul clings to you; *

your right hand holds me fast.
Glory to the Father, and to the Son, *
and to the Holy Spirit:

as it was in the beginning, is now, *

and will be for ever. Amen.

\endgroup

\end{document}
David Carlisle
  • 757,742
  • 1
    Could you please explain how it works? Even if the 'trick' is only two commands, I'm hardly understanding its functioning! – ebosi Mar 21 '17 at 14:45
  • 3
    @ebo \obeylines makes the end of line an active character with definition \par which means that every line is a paragraph (so you can not use \hangindent) however you can indent everything (leftskip then detect in the local definition of \par that you had a blank line and if so back-space up to remove the \leftskip indentation. – David Carlisle Mar 21 '17 at 14:49
  • 1
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Chris Chudzicki Mar 21 '17 at 14:49
  • @ChrisChudzicki why? – David Carlisle Mar 21 '17 at 14:51
  • 2
    @DavidCarlisle I was first confused with the "1/blank/2-3-4/blank" scheme for clustering lines. But thanks to your explanations I got it. It should be understood as: "if a line of text has a blank line above, then it's not indented" and thus be read as "blank-1/blank-2/3/4". – ebosi Mar 21 '17 at 14:58
  • @DavidCarlisle I meant to say essentially what ego asked you for: it is helpful to have some explanation of the code. It's great that you provided it in a comment. For future viewers of this answer, though, it might be nice to add your explanations to the answer itself. – Chris Chudzicki Mar 21 '17 at 15:00
  • Very neat indeed. It is also possible to put \bfseries and \normafont in the appropriate places in the redefinition of \par so that the indented bits are in bold while the unindented bits are not. And, an added benefit, with a minimum of markup. – sgmoye Mar 21 '17 at 15:12
  • The liturgical requirements that I had to fulfill required roman type for odd lines and bold for the even. In any event, a very neat (in all senses) solution. Thanks. – sgmoye Mar 21 '17 at 15:29
  • Thank you all for help. It'll make my work a lot easier now :) – Precluch Mar 21 '17 at 19:20
  • While using the code I found that treating every line as a separate paragraph gives new vertical spaces between the lines. Also \hspace*{-\leftskip} was doubling horizontal space between indented and unindented verses. I also created a new environment just to make things easier for myself. What I'm left with is `\newenvironment{psalm}{ \setlength{\parskip}{0pt} \def\par{\ifvmode\noindent\else\endgraf\fi} \obeylines

    }{}`

    – Precluch Mar 21 '17 at 20:22
  • @Precluch oh sorry Yes I see what you mean, yes you need to set parskip to 0 if it is not 0 in your real document. the hspace was remains from an earlier try it is nonsense, i'll update, sorry:-) – David Carlisle Mar 21 '17 at 20:30
  • @DavieCarlisle I'm struggling with the comment while you manage to answer :) I'm glad we both know now what should it be and that I have my macro. Thank you – Precluch Mar 21 '17 at 20:34
  • @DavidCarlisle: Interesting! What about when any line flows to the next line? Typically in this case, the indent of the flowed line is set to 2 or 3 times \parindent (I end up using a list environment to set psalms, but your set-up is much simpler!) – David Purton Mar 25 '17 at 07:14
  • This works to get the extra hanging indent: \def\par{\ifvmode\noindent\else\endgraf\fi\hangindent=3\parindent\hangafter=1} – David Purton Mar 25 '17 at 07:38
  • @DavidPurton that doesn't look quite right (the unindented lines won't get a hang indent in that case which the OP wanted.) Note in my version above you can set the two hang indent values to different values if you want the ones that start indented to hang indent more. No time now, I'll pass by later today see if any more comments here. – David Carlisle Mar 25 '17 at 08:06
1

Using the scripture package. Internally, this uses the same technique as David's answer, but with extra features and configuration options.

\documentclass[12pt,a4paper]{article}
\usepackage{scripture}
\scripturesetup{
  poetry/leftmargin=0pt
}
\begin{document}
\begin{scripture}
  \begin{poetry}
    O God, you are my God, for you I long; *
for you my soul is thirsting.
My body pines for you *
like a dry, weary land without water.

So I gaze on you in the sanctuary *

to see your strength and your glory.
For your love is better than life, *
my lips will speak your praise.

So I will bless you all my life, *

in your name I will lift up my hands.
My soul shall be filled as with a banquet, *
my mouth shall praise you with joy.

On my bed I remember you. *

On you I muse through the night
for you have been my help; *
in the shadow of your wings I rejoice.

My soul clings to you; *

your right hand holds me fast.
Glory to the Father, and to the Son, *
and to the Holy Spirit:

as it was in the beginning, is now, *

and will be for ever. Amen.

\end{poetry} \end{scripture} \end{document}

David Purton
  • 25,884