回忆录中的诗句在行首没有编号

回忆录中的诗句在行首没有编号

我正在使用 memoir 包排版包含一些诗篇的材料。诗篇被放置在 verse 环境中。我希望诗句被编号。但是当诗句特别长时,换行似乎会弄乱诗句编号。例如,我帖子底部的代码生成的诗句如下所示:

   O LORD, rebuke me not in Thine anger, neither chas-
1       ten me in Thy wrath.
   Have mercy upon me, O Lord, for I am weak; O Lord,
2       heal me, for my bones are vexed.

代替

1   O LORD, rebuke me not in Thine anger, neither chas-
       ten me in Thy wrath.
2   Have mercy upon me, O Lord, for I am weak; O Lord,
       heal me, for my bones are vexed.

对应的代码是:

%! program = pdflatex
\documentclass{memoir}

\begin{document}
    
    \linenumberfrequency{1}
    \verselinenumbersleft   
    \settowidth{\versewidth}{My soul also is sore troubled;}
    \begin{verse}[\versewidth]      
        O LORD, rebuke me not in Thine anger, neither chasten me in Thy wrath.\\
        Have mercy upon me, O Lord, for I am weak; O Lord, heal me, for my bones are vexed.\\!
    \end{verse} 
\end{document}

我做错了什么?

谢谢您的指导——

答案1

有点晚了,但这里有一个补丁,可能是将被添加到的解决方案memoir。请注意,需要安装现代 LaTeX 才能使用段落钩子。

此修复主要有三个部分

  • 使用诗句+段落钩子组合在每行诗句的开头自动添加内容(实际上是幕后的段落)。感谢 Ulrike Fischer 在聊天中提出此建议。
  • 替换用于放置行号的代码
  • 从“新行”宏中删除行号部分,并将其添加到钩子中。

它解决了编号方面的一些额外问题,以前要求\\所有行(甚至最后一行)都编号。现在,即使最后一行\\缺失,也会进行编号。

\documentclass{memoir}

\makeatletter
\renewcommand*\@vslnumleft{%
  \llap{%
    \llap{\vlvnumfont\getthelinenumber{poemline}{memfvsline}}%
    \hspace{\dimexpr\@totalleftmargin+\memRTLvrightskip}%
  }%
}
\renewcommand*\@vslnumright{%
  \rlap{%
    \hspace{\dimexpr-\@totalleftmargin+\textwidth+\memRTLvrightskip}%
    {\vlvnumfont\getthelinenumber{poemline}{memfvsline}}%
  }%
}

\AddToHook{env/verse/begin}{\AddToHook{para/begin}[memoir/versenum]{\@vstypelinenum}} 
\AddToHook{env/verse/end}{\RemoveFromHook{para/begin}[memoir/versenum]}                 

\patchcmd{\@vscentercr}%
{\@vstypelinenum}%
{}% replacement
{}% ok
{\typeout{Patch for \string\@vstypelinenum\space failed}}% bad

\makeatother


\begin{document}
    
    \linenumberfrequency{1}
    \verselinenumbersleft   
    \settowidth{\versewidth}{My soul also is sore troubled;}
    \begin{verse}[\versewidth]      
        O LORD, rebuke me not in Thine anger, neither chasten me in Thy wrath.\\
        Have mercy upon me, O Lord, for I am weak; O Lord, heal me, for my bones are vexed.\\!
    \end{verse} 
\end{document}

答案2

这不是答案,更像是承认失败。我尝试过多种verse代码,但真的没有运气。我同意两行条目的第一行应该编号,而不是第二行。但是……

 % verseprob.tex  SE 609802

%! program = pdflatex
\documentclass{memoir}

\begin{document}
    
    \linenumberfrequency{1}
    \verselinenumbersleft   
    \settowidth{\versewidth}{My soul also is sore troubled;}

First verse.

    \begin{verse}[\versewidth]      
        O LORD, rebuke me not in Thine anger, neither chasten me in Thy wrath.\\
        Have mercy upon me, O Lord, for I am weak; O Lord, heal me, for my bones are vexed.\\!
    \end{verse} 

Second verse.

    \begin{verse}[\versewidth]      
        O LORD, rebuke me not in Thine anger,\\!
         neither chasten me in Thy wrath.\\
\end{verse}

Third verse

\begin{verse}[\versewidth]
        Have mercy upon me, O Lord, for I am weak; O Lord, heal me, for my bones are vexed.\\!
    \end{verse} 

Fourth verse.

    \begin{verse}[\versewidth]      
        O LORD, rebuke me not in Thine anger,\\>
         neither chasten me in Thy wrath.%\\!
\end{verse}

Fifth verse

    \begin{verse}[\versewidth]      
        O LORD, rebuke me not in Thine anger, neither chasten me in Thy wrath.\\>[0pt]
        Have mercy upon me, O Lord, for I am weak; O Lord, heal me, for my bones are vexed.\\!
    \end{verse} 

Sixth verses.

    \begin{verse}[\versewidth]      
        O LORD, rebuke me not in Thine anger,\\>
         neither chasten me in Thy wrath.%\\!
\end{verse}
%\setcounter{poemline}{2}
\vspace{-1.8\baselineskip}
\begin{verse}[\versewidth] \setcounter{poemline}{2}
%  \setcounter{vslineno}{2}
        Have mercy upon me, O Lord, for I am weak; \\>
        O Lord, heal me, for my bones are vexed.%\\!
    \end{verse} 

\end{document}

在此处输入图片描述

我花了相当多的时间查看memoir代码,但必须承认我不再理解它;我的记忆正在消退。希望memoir维护者 Lars Madsen(又名 daleif)能够提供帮助。

相关内容