
목표
내 목표는 여러 개의 독립적인 문서에 대해 연속적인 페이지(및 가능한 경우 섹션) 카운터를 갖는 것입니다. 각 논문은 저널의 레이아웃을 최대한 유지해야 하지만 학교에서는 지속적인 페이지 매김이 필요한 누적 논문을 작성하는 것이 목적입니다. 여러 장의 종이를 서로 붙인 것처럼 보기 흉해 보일 수도 있지만 본질적으로 그렇습니다.
나는 깔끔한 진행 방법이 아마도 저널의 파일에서 형식 정보를 추출하여 환경에 압축하는 것이라는 것을 알고 있지만 , 그것은 아마도 나처럼 .cls
문맹인 사람에게는 많은 작업이 될 것입니다 . TeX
따라서 나는 대체 접근 방식인 패키지를 사용하는 해킹을 시도하여 어느 정도 성공했습니다 xr
. 그러나 몇 가지 잔여 문제가 있습니다.
먼저 제가 무엇을 했는지 설명하겠습니다.
내 설정
소개와 결론이 포함된 기본 파일이 있습니다. 페이지 카운터와 섹션 카운터는 모두 1에서 시작해야 하므로 중단점에서만 본문의 마지막 장에서 입력된 값으로 업데이트해야 합니다. 의 출력을 정수가 아닌 문자열로 \setcounter{page}{\pageref{external-endfile}}
표현하는 것과 관련이 있는 것으로 보이는 문서 내에서 사용하려고 할 때 문제가 발생했으며 패키지에 의해 트리거되는 것 같아서 숫자를 내가 입력 한 그런 다음 필요할 때 실제 카운터를 읽습니다. 이 기본 파일은 다음과 같습니다.\pageref
babel
\newcounter
\documentclass{article}
\usepackage{xr} %imports labels from external document
\externaldocument[finalCh]{file1} %prefix external labels to avoid name clashes
\newcounter{finalcount}
\setcounter{finalcount}{\pageref{finalChendfile}}% probably not the most elegant way to pack the input file's page number into a numberical variable, but it works.
\stepcounter{finalcount}% +1 since counters are initialised at 0
\newcounter{othersectioncount}
\setcounter{othersectioncount}{\ref{finalChendfile}}
\usepackage{ifthen} %conditionals
\newcommand{\exportcounters}{
\ifthenelse{%
\isodd{\thepage}} % if current page is odd-numbered
{\newpage \ % new page, forced space to make sure the following command is actually parsed, i.e. the page not treated as totally empty
}%
{\relax}
\label{endfile}
\newpage
}
%... other packages
\usepackage[english]{babel} %for some reason I don't understand, this clashes with treating \pageref as a number, so you have to put it *after* determining the page number
\usepackage{lipsum}
\begin{document}
\tableofcontents
\section{Introduction}
\subsection{Subsection}
\lipsum[1-2]
\newpage
\subsection{Another subsection}
\exportcounters
\setcounter{section}{\theothersectioncount}
\section{Conclusions}
\setcounter{page}{\thefinalcount} %load the final pagenumber of the last chapter here
\lipsum[4-40]
\end{document}
그 외에도 다음과 같은 장의 파일이 있습니다.
\documentclass{article}
\usepackage{substr}
\usepackage{xr} %imports labels from external document
\usepackage{ifthen} %conditionals
\externaldocument[intro]{introandextro} %prefix external labels to avoid name clashes
\addtocounter{page}{\pageref{introendfile}}
\newcommand{\exportcounters}{
\ifthenelse{%
\isodd{\thepage}} % if current page is odd-numbered
{\newpage \ % new page, forced space to make sure the following command is actually parsed, i.e. the page not treated as totally empty
}%
{\relax}
\label{endfile}
\newpage
}
\usepackage{lipsum}
%\setcounter{section}{2}
\begin{document}
\setcounter{section}{\ref{introendfile}}
\section{Chapter I}
\subsection{intro}
\lipsum[1-4]
\newpage
\subsection{Chapter 1 body}
\lipsum[5-44]
\exportcounters
\label{endfile}
\end{document}
이 설정을 사용하면 "pdflatex introandextro", "pdflatex file1", 그리고 다시 "pdflatex introandextro"를 두 번만 실행하면 연속적인 페이지와 섹션 번호를 얻을 수 있습니다. (이 작업을 수행할 수 있는 쉘 스크립트가 있습니다.) 또한 toc
다른 파일에서 모든 관련 정보를 추출하고 모든 섹션을 참조하는 목차를 얻기 위해 aux
해당 정보로 기본 파일을 컴파일하는 Python 스크립트도 있습니다. toc
어떤 파일에 나타나든 대부분 정상적으로 작동합니다.
당연히 \addtocounter{page}{\pageref{introendfile}}
소개 끝부분의 페이지 카운터를 file1로 가져옵니다. 또한 그래야 하는 것처럼 \setcounter{section}{\ref{introendfile}}
외부 참조 반환 값(이 경우 1.2)의 섹션 부분을 먹고 이를 적절하게 사용하여 섹션 카운터를 설정합니다. 아쉽게도 나머지 표현식을 어떻게 처리해야 할지 모르기 때문에 다시 뱉어내고 페이지 상단에 ".2"를 씁니다. 보기 흉해서 없애려고 노력 중이에요. 내 직감은 이를 위한 가장 좋은 방법은 최상위 섹션 명령만 and 로 보내도록 \label
내부를 일시적으로 재정의하는 것이지만 내 일반 텍스트로는 시작할 위치를 알 수 없을 만큼 좋지 않습니다.\exportcounters
.aux
.toc
잔여 문제
그래서 내 질문: 누구든지 -command를 적절하게 재정의하는 방법에 대한 힌트를 줄 수 있습니까 \label
? 즉, 하위 섹션이나 더 깊은 곳에 포함되어 있음에도 불구 하고 .aux
-file 에 알리도록 하려면 어떻게 해야 합니까? (또는 '.'에 넣기 전에 부분을 제거하려면 어떻게 해야 합니까 ? 시도했지만 숫자가 아닌 문자열이 생성되어 컴파일 중에 "누락된 숫자, 0으로 처리됨" 오류가 발생합니다.)\newlabel{endfile}{{<thesection>}{12}}
\newlabel{endfile}{{<\thesection>.<\thesubsection>}{12}}
\setcounter{section}{...}
\SubStringBefore
내가 겪고 있는 두 번째 문제는 두 문서 모두에서 첫 번째 페이지를 끝내려는 위치에 명시적인 내용을 삽입해야 한다는 것입니다. \newpage
그렇지 않으면 두 페이지 분량의 텍스트가 실행됩니다. 이 동작은 (또는 및 xr
의 결합 ) 에 의해 유발되는 것으로 보입니다 . 이것은 알려진 문제입니까? 명시적인 s를 포함하지 않는 해결 방법이 있습니까 ?xr
lipsum
\newpage
또 다른 (매우 사소한) 문제는 pdflatex가 서문의 사용 \ref
("Missing \begin{document}")에 대해 불평한다는 것입니다. 그러나 결과가 올바르면 무시해도 괜찮습니다.
아니면 완전히 다른 각도에서 이 문제를 해결하는 것이 가능할까요? 서식 .cls
지정 명령을 환경에 포함시킬 때 일반 TeX을 많이 이해하지 못하는 사람들을 지원하는 도구가 있습니까 ? 같은 것 \importasenvironment{<environmentname>}{<classname>.cls}
?
답변1
zref
패키지 , 모듈 lastpage
및 를 통해 이전 문서에서 페이지 및 섹션 값을 가져올 수 있습니다 xr
.
첫 번째 문서
첫 번째 문서는 패키지에 의해 설정된 레이블에 의해 작성된 속성 목록에 DocumentA
속성을 저장 pagevalue
합니다 .sectionvalue
LastPage
LastPage
zref-lastpage
예제 파일 DocumentA.tex
, 첫 번째 문서:
\documentclass{article}
\usepackage{zref-lastpage}
\makeatletter
\zref@ifpropundefined{pagevalue}{% it is defined by some modules of zref
\zref@newprop*{pagevalue}[0]{\number\value{page}}%
}{}
\zref@newprop{sectionvalue}[0]{\number\value{section}}%
\zref@addprops{LastPage}{pagevalue,sectionvalue}
\makeatother
\begin{document}
\section{Section A of first document}
\section{Section B of first document}
\newpage
\section{Section C of first document}
\section{Section D of first document}
\end{document}
패키지는 zref-lastpage
다음 작업을 수행합니다.
- 에 도착진짜문서의 끝(패키지를 통해
atveryend
) .aux
를 통해 파일 에 쓰기\immediate\write
. 정확한 페이지 번호를 얻기 위해\label
사용 하지만, 이를 위해서는 다음 페이지를 출력해야 합니다.\write
마지막 페이지 이후에는 해당 페이지가 없습니다. 또한 패키지는 페이지 번호 수정을 처리합니다.
파일 .aux
에는 다음이 포함됩니다.
\zref@newlabel{LastPage}{\default{4}\page{2}\abspage{2}\pagevalue{2}\sectionvalue{4}}
다음 문서
다음 문서는 이전 문서의 레이블에서 데이터를 가져오고 LastPage
카운터를 설정합니다. 또한 이전 문서의 코드를 사용하여 속성을 정의하고 다음 문서에 대한 카운터 값을 작성합니다.
예제 파일 DocumentB.tex
, 다음 문서:
\documentclass{article}
\usepackage{zref-lastpage,zref-xr}
\makeatletter
\zref@ifpropundefined{pagevalue}{% it is defined by some modules of zref
\zref@newprop*{pagevalue}[0]{\number\value{page}}%
}{}
\zref@newprop{sectionvalue}[0]{\number\value{section}}%
\zref@addprops{LastPage}{pagevalue,sectionvalue}
\zexternaldocument[pre-]{DocumentA}\relax
\zref@ifrefundefined{pre-LastPage}{%
\@latex@error{Zref label `LastPage' of `DocumentA' is undefined}\@ehc
}{%
\setcounter{page}{%
\numexpr\zref@extractdefault{pre-LastPage}{pagevalue}{0}+1\relax
}%
\setcounter{section}{%
\zref@extractdefault{pre-LastPage}{sectionvalue}{0}%
}%
}
\makeatother
\begin{document}
\section{Section E of second document}
\section{Section F of second document}
\newpage
\section{Section G of second document}
\section{Section H of second document}
\end{document}
그런 다음 두 번째 문서의 첫 번째 섹션에 Section E of second document
5로 번호가 매겨지고 3페이지에서 시작됩니다.
답변2
Heiko Oberdiek의 답변은 서로 완벽하게 구축된 여러 문서의 기본 사례를 해결합니다.
포함될 장 앞과 뒤의 부분을 모두 포함하는 주 파일의 좀 더 복잡한 경우, 즉 카운터를 문서의 임의 지점에서 외부 문서로 전달한 다음 동일하거나 다른 외부 문서를 검색하는 경우 문서 내에서도 카운터를 정의 \importcounters
하고 \exportcounters
적절한 위치에서 호출하여 조정을 관리했습니다. 아마도 더 줄일 수 있지만 이것은 현재 Heiko Oberdiek의 게시물을 기반으로 구축하는 순간에 가깝습니다.
\documentclass{article}
\usepackage{zref-lastpage,zref-xr}
\makeatletter
\zref@ifpropundefined{pagevalue}{% it is defined by some modules of zref
\zref@newprop*{pagevalue}[0]{\number\value{page}}%
}{}
\zref@newprop{sectionvalue}[0]{\number\value{section}}%
%\zref@addprops{LastPage}{pagevalue,sectionvalue}%
\zexternaldocument[pre-]{DocumentB}\relax
\zref@ifrefundefined{pre-LastPage}{%
\@latex@error{Zref label `LastPage' of `DocumentB' is undefined}\@ehc
}{%
\newcounter{@otherpage}
\setcounter{@otherpage}{%
\numexpr\zref@extractdefault{pre-LastPage}{pagevalue}{0}+1\relax
}%
\newcounter{@othersection}
\setcounter{@othersection}{%
\zref@extractdefault{pre-LastPage}{sectionvalue}{0}%
}%
}
\newcommand{\importcounters}{% enables importing the external page and section counters at an arbitrary point in the document
\setcounter{section}{\the@othersection}
\setcounter{page}{\the@otherpage}
}
\newcommand{\exportcounters}{% exporting counters after the intro rather than at the end of the document
\cleardoublepage \ %
\zref@labelbyprops{LastIntroPage}{pagevalue,sectionvalue}
}
\makeatother
\usepackage[english]{babel}
\begin{document}
\section{Section A of first document}
\section{Section B of first document}
\exportcounters
\newpage
\importcounters
\section{Section C of first document}
\section{Section D of first document}
\subsection{D 1}
\subsection{D 2}
\end{document}
( 에서 DocumentB.tex
유일한 변화는 pre-LastIntroPage
가 아닌 에 카운터를 공급한다는 것입니다 pre-LastPage
.)
다음 목표는 계속 진행하기 전에 기본 파일을 일시 중지하고 종속 파일의 컴파일로 이동하는 방법을 알아내는 것입니다 write18
. 그러나 이는 별도의 질문입니다.