我正在寻找一种使用行号注释 pdf 的方法(就像我们使用 lineno 包获得的那样)。但我希望这些数字与源 (tex) 文件中的行号相对应,这样我就知道在哪里可以更改它。
使用这个答案我已经构建了以下内容 - 括号中的数字是我希望位于边缘的源文件编号(不要介意 lorem ipsum)。
\documentclass[a5paper,12pt]{article}
\usepackage[a5paper]{geometry}
% Get the source file number
\makeatletter
\ifnum\inputlineno=\m@ne
\let\showlineno\@empty
\else
\def\showlineno{line \the\inputlineno}
\fi
\makeatother
% Package to write numbers in the margin
\usepackage{lineno}
% set the file number as the number lineno will show
\renewcommand\LineNumber{\the\inputlineno}
\begin{document}
\linenumbers
(20) This is a story of a person, and another, and another.
(21) Who tried to have some fun, doing something or another.
(22) And they did, just so, until the afternoon was gone.
(23) Thus ends our little story.
(25) A second paragraph begins, like a dance.
(26) While green serenades are played at a stance,
(27) and mosquitos bite be, pray me, delicious blood!
(28) I think we should move in this tasty neighbourhood!
(30) And so we did it all again! (But in a single line.)
(32) This is a story of a person, and another, and another. Who tried to have some fun, doing something or another. And they did, just so, until the afternoon was gone. Thus ends our little story.
(34) A second paragraph begins, like a dance. While green serenades are played at a stance, and mosquitos bite be, pray me, delicious blood! I think we should move in this tasty neighbourhood!
\end{document}
上面的代码对于我个人来说已经足够好了,但所有以同一段落结尾的行都用最后行号段落中某一行的标签(即:我得到标签 24 (x4)、29 (x4) 31、33 (x4) 和 35 (x4))。有没有简单的方法可以避免这种情况?
编辑:我刚刚注意到,如果我们只打印(每个段落的)第一个行号,那么我们就完成了(或者,至少,我会完全满意)。
答案1
这似乎可以解决问题,但仅打印每一段第一行的行号。
问题。似乎可行的方法lineno
是(在页边空白处)写上从\linenumber
段落开头的值开始递增的数字。设置\Linenumber
为\inputlineno
只会为每个段落的第一行提供正确的输入行号。
解决方案 (?)为了避免打印错误的(源)行号,我们仅打印每个段落的第一个行号,并且为了检查我们是否位于段落的第一行,我们使用该everyhook
包在每个段落的开头设置一个计数器(tnlinecounter
) 。 (然后我们可以比较和\inputlineno
的值来确定我们是否位于第一行。)linenumber
tnlinecounter
\documentclass[a5paper,12pt]{article}
\usepackage[a5paper]{geometry}
% Package to write numbers in the margin
\usepackage{lineno}
\newcounter{tnparcounter}
\usepackage[excludeor]{everyhook}
\PushPreHook{par}{%
\resetlinenumber[\the\inputlineno]%
\setcounter{tnparcounter}{\the\inputlineno}}
% set the file number as the number lineno will show
\renewcommand\LineNumber{%
\ifnum\value{linenumber}=\value{tnparcounter}%
\thelinenumber\fi}
\begin{document}
\linenumbers
(20) This is a story of a person, and another, and another.
(21) Who tried to have some fun, doing something or another.
(22) And they did, just so, until the afternoon was gone.
(23) Thus ends our little story.
(25) A second paragraph begins, like a dance.
(26) While green serenades are played at a stance,
(27) and mosquitos bite be, pray me, delicious blood!
(28) I think we should move in this tasty neighbourhood!
(30) And so we did it all again! (But in a single line.)
(32) This is a story of a person, and another, and another. Who tried to have some fun, doing something or another. And they did, just so, until the afternoon was gone. Thus ends our little story.
(34) A second paragraph begins, like a dance. While green serenades are played at a stance, and mosquitos bite be, pray me, delicious blood! I think we should move in this tasty neighbourhood!
\end{document}