내 페이지 수가 4의 배수인지 확인하고 싶습니다. 4의 배수가 아닌 경우 \newpage\begin{center}\textbf{BLANK PAGE}\end{center}
페이지 수가 4의 배수가 될 때까지 추가하고 싶습니다 . 나는 기본적으로 다음에 설명된 expl3 솔루션을 사용하려고 시도하고 있습니다.이 답변다음 MWE를 사용합니다.
\documentclass{article}
\usepackage{refcount, lastpage}
\newcommand{\blankpage}{\newpage\begin{center}\textbf{BLANK PAGE}\end{center}}
\ExplSyntaxOn
\NewDocumentCommand{\ensurefour} { }
{
\prg_replicate:nn
{ \int_mod:nn { 4 - \int_mod:nn { \getpagerefnumber{LastPage} } { 4 } } { 4 } }
{ \blankpage }
}
\ExplSyntaxOff
\begin{document}
Test\newpage
\ensurefour
\end{document}
어떤 엔진에서든 처음으로 컴파일하면 한 페이지, 즉 "Test"라고 표시된 단일 페이지의 출력이 생성됩니다. 두 번째로 컴파일하면 원하는 출력인 4페이지의 출력이 생성됩니다.
그런데 .aux 파일을 제거하지 않고 세 번째 컴파일을 계속하면 페이지 번호가 1로 돌아옵니다.
이는 첫 번째 컴파일 중에 LaTeX가 .aux 파일에 다음을 기록하기 때문입니다.
\relax
\newlabel{LastPage}{{}{1}}
\xdef\lastpage@lastpage{1}
\gdef\lastpage@lastpageHy{}
\gdef \@abspage@last{1}
따라서 두 번째 편집에서는 \getpagerefnumber{LastPage}
"1"을 보고 \ensurefour
3페이지를 추가하여 총 4페이지가 됩니다. 그러나 4개의 페이지가 생성된 것을 확인하고 aux 파일에 씁니다.
\relax
\newlabel{LastPage}{{}{4}}
\xdef\lastpage@lastpage{4}
\gdef\lastpage@lastpageHy{}
\gdef \@abspage@last{4}
이로 인해 세 번째 편집에서는 이미 4페이지가 있다고 생각하게 되므로 더 이상 페이지가 추가되지 않고 한 페이지만 남게 됩니다... 등등.
질문: 1과 4 사이를 번갈아 가며 페이지 번호를 4로 수렴하는 방법이 있나요?
답변1
불행히도 패키지는 lastpage
레이블을 관리하는 방식을 변경했으며 이제 Hook 을 사용합니다 afterlastpage
.
\clearpage
의 현재 값을 발행하여 사용할 수 있습니다 page
.
\documentclass{article}
\newcommand{\blankpage}{\begin{center}\textbf{BLANK PAGE}\end{center}\clearpage}
\ExplSyntaxOn
\NewDocumentCommand{\ensurefour} { }
{
\clearpage
\prg_replicate:nn
{ \int_mod:nn { 4 - \int_mod:nn { \value{page}-1 } { 4 } } { 4 } }
{ \blankpage }
}
\ExplSyntaxOff
\AtEndDocument{\ensurefour}
\begin{document}
Test
%\newpage
test
%\newpage
test
%\newpage
test
\end{document}
명령 의 주석 처리를 제거하면 \newpage
올바른 결과가 표시됩니다.
답변2
마지막 페이지에는 라벨을 붙일 필요가 없습니다. 매크로 가 먼저 \ensurefor
실행될 수 있습니다 (또는 문서에 부동 소수점이 있는 경우). 그런 다음 마지막 실제 페이지가 완료되고 이것이 n+1과 같다고 확신합니다. 여기서 n은 실제 페이지 수입니다. 레지스터를 이용하여 원하는 뱅크 페이지를 추가할 수 있습니다 .\vfill\break
\vfill\supereject
\pageno
\pageno
이 솔루션의 또 다른 장점은 올바른 페이지 수를 얻기 위해 두 번째 TeX 실행을 기다릴 필요가 없다는 것입니다.
OpTeX에서 이를 수행하는 방법을 보여드릴 수 있습니다. LaTeX 솔루션은 유사할 수 있습니다.
\newcount\restpages
\def\ensurefour{\vfill\break
\restpages = \expr[0]{ 4 - (\the\pageno-1)\%4 }\relax
\ifnum\restpages=4 \restpages=0 \fi
\fornum 1..\restpages \do{\null\vfill\break}
}
Test:
\lipsum[1-10]
\ensurefour
\bye
답변3
빠르고 더러운 해결책은 LastPage(또는 이에 상응하는 것)에 라벨을 붙이는 것입니다.~ 전에 \ensurefour
추가 페이지를 생성합니다. 예를 들어:
\documentclass{article}
\usepackage{refcount}
\newcommand{\blankpage}{\newpage\begin{center}\textbf{BLANK PAGE}\end{center}}
\ExplSyntaxOn
\NewDocumentCommand{\ensurefour} { }
{
\label{LastPageBeforeEnsureFour}
\prg_replicate:nn
{ \int_mod:nn { 4 - \int_mod:nn { \getpagerefnumber{LastPageBeforeEnsureFour} } { 4 } } { 4 } }
{ \blankpage }
}
\ExplSyntaxOff
\begin{document}
Test
\ensurefour
\end{document}
답변4
저는 페이지 수가 4의 배수이고 마지막 두 페이지에 특정 내용을 넣고 싶은 인쇄된 문서를 생성합니다. 이 목적을 위해 제가 작성한 명령은 다음과 같습니다.
현재 실제 페이지 수를 얻습니다 \ReadonlyShipoutCounter
(이미 생성된 전체 페이지 수, 현재 페이지를 고려하여 하나 추가).
\newcommand{\theabsolutepage}{\inteval{\ReadonlyShipoutCounter+1}}
\blankpage
페이지 스타일을 설정할 수 있는 명령을 정의합니다 ( 빈 페이지에 페이지 스타일을 \blankpage[plain]
원하는 경우 ).plain
\NewDocumentCommand{\blankpage}{ O{empty} }
% #1: page style for the blank page
{
\clearpage{}\thispagestyle{#1}\null\clearpage{}
}
\clearpagestoend
원하는 수의 빈 페이지를 얻는 명령
\NewDocumentCommand{\clearpagestoend}{ O{0} O{empty} }
% #1: number of reserved pages at end
% #2: page style for blank pages
{
\clearpage{\pagestyle{#2}}
\count255=\theabsolutepage \advance \count255 by #1 \advance \count255 by -1
\count254=\count255
\divide \count254 by 4 \multiply \count254 by 4
\advance \count255 by -\count254
\ifcase\count255 % pages nb % 4 == 0: do nothing
\relax
\or % pages nb % 4 == 1: skip 3 pages
\blankpage[#2] \blankpage[#2] \blankpage[#2]
\or % pages nb % 4 == 2: skip 2 pages
\blankpage[#2] \blankpage[#2]
\or % pages nb % 4 == 3: skip 1 page
\blankpage{\pagestyle{#2}}
\fi
}
예를 들어
\clearpagestoend[2][plain]
페이지 스타일 을 사용하여 4에서 2페이지를 뺀 페이지 수의 배수를 얻기 위해 빈 페이지 수를 생성합니다 plain
.
전체 예:
\documentclass{article}
\usepackage{lipsum}
\newcommand{\theabsolutepage}{\inteval{\ReadonlyShipoutCounter+1}}
\NewDocumentCommand{\blankpage}{ O{empty} }
% #1: page style for the blank page
{
\clearpage{}\thispagestyle{#1}\null\clearpage{}
}
\NewDocumentCommand{\clearpagestoend}{ O{0} O{empty} }
% #1: number of reserved pages at end
% #2: page style for blank pages
{
\clearpage{\pagestyle{#2}}
\count255=\theabsolutepage \advance \count255 by #1 \advance \count255 by -1
\count254=\count255
\divide \count254 by 4 \multiply \count254 by 4
\advance \count255 by -\count254
\ifcase\count255 % pages nb % 4 == 0: do nothing
\relax
\or % pages nb % 4 == 1: skip 3 pages
\blankpage[#2] \blankpage[#2] \blankpage[#2]
\or % pages nb % 4 == 2: skip 2 pages
\blankpage[#2] \blankpage[#2]
\or % pages nb % 4 == 3: skip 1 page
\blankpage{\pagestyle{#2}}
\fi
}
\begin{document}
\lipsum
\clearpagestoend
\end{document}