
Table of contents
파일에서 사용하는 것을 .tex
별도의 파일로 내보내는 가장 좋은 방법은 무엇입니까 .pdf
?
현재 파일이 있고 ( ) 의 결과를 목차만 포함된 my-report.tex
와 쌍으로 만들고 싶습니다 .pdflatex
my-report.pdf
my-report-toc.pdf
이를 달성하는 간단한 방법이 있습니까?
내 .tex
파일에는 다음과 같은 레이아웃이 있습니다(단순화).
...
\begin{titlepage}
\includepdf[pages=-]{abstract.pdf}
\end{titlepage}
% -------------------------------------------------
% This should go to a separate .pdf file on export.
\tableofcontents
\pagebreak
% -------------------------------------------------
\section{Section1}
...
\section{Section2}
...
\section{Section3}
...
답변1
PDF 추출
외부 도구를 사용하여 PDF 파일에서 페이지를 추출할 수 있습니다(예: pdftk
. 목차가 5페이지와 6페이지에 있는 경우:
pdftk myreport.pdf cat 5-6 output myreport-toc.pdf
\include
기본 문서가 여러 \include
파일 로 분리된 경우 \tableofcontents
별도의 파일로 이동됩니다 myreport-tableofcontents.tex
.
\tableofcontents
\newpage
그리고 myreport.tex
그 목차를 포함하려면:
\include{myreport-tableofcontents}
그런 다음 myreport-toc.tex
목차만 포함합니다.
\includeonly{myreport-tableofcontents}
\input{myreport}
hyperref
및 링크 포함
myreport.tex
패키지를 로드 하면 hyperref
목차 파일 myreport.toc
에도 앵커 이름이 포함됩니다. 이는 문서 간 링크를 만드는 데 사용될 수 있습니다. 예를 들어 CTAN의 내 번들에 대한 개요 파일은oberdiek.pdf번들에 포함된 모든 패키지의 목차가 포함되어 있습니다. 소스 파일oberdiek.tex\tocinclude
이 기술을 사용하는 경우 아래 예의 정의를 참조하세요 . 물론 myreport.tex
과 myreport-toc.tex
need 가 모두 필요합니다 hyperref
.
또한 필요한 것:
에서 사용되는 모든 매크로는
myreport.toc
에서 제공되어야 합니다myreport-toc.tex
.동일한 클래스, 글꼴, 페이지 레이아웃 등을 사용해야 합니다.
페이지 번호의 경우, 예제 에서는
zref
페이지 번호에 대한 데이터를 . 레이블에는 목차의 시작 페이지에 대한 페이지 번호가 기록됩니다. 모듈을 사용하면 문서의 모든 페이지 번호의 시각적 모양도 기억됩니다. 그런 다음 의 파일을 에서 읽 습니다 ..aux
myreport
toc
zref-thepage
.aux
myreport
zref-xr
myreport-toc.tex
파일 myreport.tex
:
\documentclass{book}
\usepackage{zref-abspage,zref-thepage}
\makeatletter
\newcommand*{\pagevaluelabel}[1]{%
\zref@labelbyprops{toc}{abspage}%
}
\makeatother
\AtBeginDocument{%
\addtocontents{toc}{\string\providecommand\string\pagevaluelabel[1]{}}%
\addtocontents{toc}{\string\pagevaluelabel{toc}}%
}
\usepackage{hyperref}
\setcounter{secnumdepth}{4}
\begin{document}
\frontmatter
Title page
\newpage
\chapter*{Foreword}
\tableofcontents
\mainmatter
\chapter{Chapter}
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\end{document}
파일 myreport-toc.tex
:
\documentclass{book}
\usepackage{hyperref}
\usepackage{zref-xr}
\zexternaldocument[main:]{test}\relax
\makeatletter
\newcommand*{\tocinclude}[1]{%
\chapter*{\contentsname
\@mkboth{\MakeUppercase\contentsname}%
{\MakeUppercase\contentsname}%
}%
\begingroup
\makeatletter
\def\@prj{#1}%
\let\contentsline\foreign@contentsline
\input{\@prj.toc}%
\endgroup
}
\def\foreign@contentsline#1#2#3#4{%
\ifx\\#4\\%
\csname l@#1\endcsname{#2}{#3}%
\else
\ifHy@linktocpage
\csname l@#1\endcsname{{#2}}{%
\hyper@linkfile{#3}{\@prj.pdf}{#4}%
}%
\else
\csname l@#1\endcsname{%
\hyper@linkfile{#2}{\@prj.pdf}{#4}%
}{#3}%
\fi
\fi
}%
\begin{document}
\makeatletter
\zref@refused{main:toc}
\setcounter{page}{%
\numexpr\zref@extractdefault{main:toc}{abspage}{1}\relax
}
\renewcommand*{\thepage}{%
\zref@extractdefault{main:thepage\number\value{page}}%
{page}{\arabic{page}}%
}
\tocinclude{myreport}
\end{document}
답변2
첫 번째 방법(shorttoc
)
가장 쉬운 방법은 임의 파일에서 ToC를 로드하고 인쇄하는 패키지 \anothertableofcontents
의 명령을 사용하는 것입니다 .shorttoc
.toc
주요 문서가
my-report.tex
\documentclass{article}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\blinddocument
\end{document}
my-report-toc.tex
다음 내용으로 생성
my-report-toc.tex
\documentclass{article}
\usepackage{shorttoc}
\usepackage{xspace} % this shouldn't be needed in your document
\begin{document}
\anothertableofcontents{my-report}{Contents}{3}
\end{document}
후자를 컴파일하면 결과에는 my-report-toc.pdf
다음의 ToC가 포함됩니다 my-report.pdf
.
두 번째 방법(pdfpages
)
또 다른 방법은 패키지를 사용하여 pdfpages
다른 파일의 ToC 페이지만 로드하는 것입니다. 이 경우 ToC가 포함된 페이지에는 다른 내용이 포함되어서는 안 됩니다.
주요 문서가
my-report.tex
\documentclass{article}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\clearpage
\blinddocument
\end{document}
my-report-toc.tex
다음 내용으로 만들기 ( pages=1
ToC의 실제 페이지 범위로 대체)
my-report-toc.tex
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=1]{my-report.pdf}
\end{document}
후자를 컴파일하면 결과에는 my-report-toc.pdf
다음의 ToC가 포함됩니다 my-report.pdf
.
답변3
pdfseparate
PDF 파일에서 페이지 또는 페이지 범위를 추출하는 데 사용할 수 있습니다 .
목차의 길이가 한 페이지라고 가정하고, 다음을 시도해 보세요.pdfseparate -f 2 -l 2 my-report.pdf my-report-toc.pdf
물론 이를 위해서는 목차가 몇 페이지를 차지하는지 알아야 합니다.
답변4
mycontents.tex
:
\documentclass{article}
\begin{document}
\section*{My Contents}
\input{mwe.toc}
\end{document}
어디mwe.toc
보조 파일은이미 컴파일됨 mwe.tex
동일한 디렉터리에 있는 기본 문서입니다.
일부 편집자는 이러한 파일을 다른 위치로 옮기거나 컴파일 후 보조 파일을 제거할 수 있지만 터미널에서 컴파일하는 데 문제가 없다는 점에 유의하십시오.