我想要行号不是使用环境时重置verse
。
考虑一下这个MWE:
\documentclass{book}
\usepackage{verse}
\poemlines{5}
\begin{document}
\chapter{}
\begin{verse}
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\!
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\!
\end{verse}
{\let\clearpage\relax \chapter{}}
\begin{verse}
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\!
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\!
\end{verse}
\end{document}
有没有办法让行号继续计数,即使你已经开始了新的verse
环境?
答案1
(重新定义的)环境在开始时verse
将相关计数器设置为 0。poemline
删除该设置。还需要在环境结束时减一,因为计数器在开始时是步进的。
当需要时,您将发出\setcounter{poemline}{0}
重置编号的命令。
\documentclass{book}
\usepackage{verse}
\usepackage{xpatch}
\xpatchcmd{\verse}
{\setcounter{poemline}{0}}% find
{}% replace
{}{}% auxiliary arguments
\xpretocmd{\endverse}{\addtocounter{poemline}{-1}}{}{}
\poemlines{5}
\begin{document}
\chapter{}
\begin{verse}
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\!
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\!
\end{verse}
{\let\clearpage\relax \chapter{}}
\begin{verse}
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\!
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\
Lorem ipsum dolor sit amet, consectetur adipiscing elit\\!
\end{verse}
\end{document}