我需要将一页打印三次。在纯 TeX 中,是否可以输出最后一页的两个精确副本而不增加页码?
答案1
当然,这可以通过“简单破解”普通 TeX 例程来实现\output
。实际上,重新定义\plainoutput
普通 TeX 例程使用的宏就足够了\output
:
\newcount\nbcopies
\nbcopies=0
% Used to save the page box in case we need to ship it out several times
\newbox\pagebox
\def\additionalcopies#1{%
\global\nbcopies=#1\relax
}
\catcode`\@=11
\def\plainoutput{%
\setbox\pagebox=\vbox{\makeheadline\pagebody\makefootline}%
\loop
\shipout\copy\pagebox
\ifnum\nbcopies>\z@
\global\advance\nbcopies by \m@ne
\repeat
\setbox\pagebox=\copy\voidb@x % free the memory used by the page contents
% The following two lines are exactly as in the plain TeX \output routine.
\advancepageno
\ifnum\outputpenalty>-\@MM \else\dosupereject\fi
}
% Convenient macro for repeating things, that supports nesting.
\long\def\myrepeat#1#2#3{%
#1=#2\relax
\loop
\ifnum #1>\z@
\advance#1by \m@ne
\begingroup
#3%
\endgroup
\repeat
}
\catcode`\@=12
\newcount\outercount
\newcount\innercount
\myrepeat{\outercount}{20}{%
Foo bar\myrepeat{\innercount}{40}{ foo bar baz quux}.%
\endgraf % \loop doesn't like \par
}
% One additional copy -> the current page will be output twice.
\additionalcopies{1}\vfil\eject
\myrepeat{\outercount}{10}{%
\myrepeat{\innercount}{20}{Rest of the text. }\endgraf
% Due to the implicit \unskip at the end of a paragraph, there won't be any
% unwanted space after the last 'text.' in each of these paragraphs.
}
% Two additional copies -> the current page will be output three times.
\additionalcopies{2}
\bye
答案2
我提供了两个计数器:一个是全局计数器,一个是本地计数器。\repeatallpages=3
所有页面都重复三次,但\repeatpages=4
(任何值 > 1) 会覆盖当前页面的计数器。
%% first five lines just for a smaller picture
\pdfpageheight=3in
\pdfpagewidth=5in
\hsize=3in
\vsize=1in
\font\bbbigfont=cmr17 \bbbigfont
%%%
\catcode`@=11
\def\repeatplainoutput{%
\ifnum\repeatallpages>0
\ifnum\repeatpages>1
\else
\global\repeatpages=\repeatallpages
\fi
\fi
\global\advance\repeatpages 1
% \plainoutput has \vbox{\makeheadline\pagebody\makefootline}
% we save the contents and \copy it
\setbox\savedpagebox=\vbox{\makeheadline\pagebody\makefootline}%
\loop\ifnum\repeatpages>1
\shipout\copy\savedpagebox
\global\advance\repeatpages -1
\repeat
\advancepageno
\ifnum\outputpenalty>-\@MM \else\dosupereject\fi
}
\catcode`@=12
\newbox\savedpagebox
\newcount\repeatallpages
\newcount\repeatpages
\output={\repeatplainoutput}
%%% start of the document
\repeatallpages=3
This is page 1 (three times)
\vfill\eject
\repeatpages=4
This is page 2 (four times)
\vfill\eject
This is page 3 (three times)
\bye