使用行内换行符时如何避免重复行号?

使用行内换行符时如何避免重复行号?

我正在使用该verse包排版一些诗歌。考虑以下 MWE:

\documentclass{article}
\usepackage{verse}
\begin{document}

% count the verses
\poemlines{5}

\begin{verse}
First,\\
second,\\
third,\\
fourth,\\
fifth\\>
and sixth.\\!
\end{verse}

\end{document}

\poemlines{5}命令会计算诗节数(每五节计算一次)。但是,如果出现编号的诗节在行内被打断(被宏打断\\>),编号就会重复,如下图所示:

在此处输入图片描述

有没有办法避免这种行为?具体来说,我希望数字只出现在第一个子节旁边(即fifth在 MWE 中)。

答案1

我查看了该verse包,找到了输出诗行的例程:\getmodulo@vs。然后我对其进行了修改,以便当打印出诗行时(即当满足模诗条件时),紧接着的下一行也不能被编号。我使用宏\dupskip来存储当前状态。

已编辑,以解决 OP 相关的评论\!

\documentclass{article}
\usepackage{verse}
\makeatletter
\renewcommand{\getmodulo@vs}{\bgroup
  \ifnum\c@modulo@vs<\@ne   % no line numbers
  \else
    \ifnum\c@modulo@vs<\tw@ % every line numbered
      \vlnumfont\thepoemline
    \else
      \@tempcnta\c@poemline
      \advance\@tempcnta -\c@fvsline
      \divide\@tempcnta\c@modulo@vs
      \multiply\@tempcnta\c@modulo@vs
      \advance\@tempcnta\c@fvsline
      \ifnum\@tempcnta=\c@poemline\vlnumfont
        \if F\dupskip
          \thepoemline\gdef\dupskip{T}%
        \else
          \gdef\dupskip{F}%
        \fi
      \else
        \gdef\dupskip{F}%
      \fi
    \fi
  \fi
\egroup}
\newcommand\dupskip{F}

\makeatother
\begin{document}

% count the verses
\poemlines{5}

\begin{verse}
First,\\
second,\\
third,\\
fourth,\\
fifth\\>
and sixth.\\
First,\\
second,\\
third,\\
fourth,\\
fifth\\>
and sixth.\\
First,\\
second,\\
third,\\
fourth,\\
fifth\\>
and sixth.\\!
\end{verse}

\end{document}

在此处输入图片描述

答案2

您还可以使用以下\verselinebreak命令:

\documentclass{article}
\usepackage{verse}
\begin{document}

\begin{verse}
\poemlines{5}
   There was an Old Man with a beard, \\
               Who said, "It is just as I feared!--\\
               Two Owls and a Hen,\\
               Four Larks and a Wren,\\
               Have all built their nests\verselinebreak[1.1in] in my beard!"\\

\end{verse}

\end{document} 

在此处输入图片描述

相关内容