我想要一個(逐項列出)我包含在 pdf 中的文件列表,該列表在\includeonly{}
.
我的方法根本不起作用,因為每個包含的文件都需要大量的手動工作,環境missing \item
中有一個itemize
,並且在方法上是不正確的,因為每個文件中bools
總是設置為;true
是否包含並不重要。
這是我的 MWE:
\documentclass{scrbook}
\usepackage{filecontents,etoolbox}
\newbool{chapter01}
\newbool{chapter02}
\newbool{chapter03}
\usepackage{blindtext}
\begin{filecontents}{chapter01.tex}
\chapter{This is chapter 01}
\booltrue{chapter01}
\blindtext[3]
\end{filecontents}
\begin{filecontents}{chapter02.tex}
\chapter{This is chapter 02}
\booltrue{chapter02}
\blindtext[3]
\end{filecontents}
\begin{filecontents}{chapter03.tex}
\chapter{This is chapter 03}
\booltrue{chapter03}
\blindtext[3]
\end{filecontents}
\includeonly{%
chapter01,
% chapter02,
chapter03
}
\begin{document}
\begin{titlepage}
This PDF contains:
\begin{itemize}
\ifbool{chapter01}{\item Chapter 01}{}
\ifbool{chapter02}{\item Chapter 02}{}
\ifbool{chapter03}{\item Chapter 03}{}
\end{itemize}
\end{titlepage}
\include{chapter01}
\include{chapter02}
\include{chapter03}
\end{document}
答案1
該\includeonly
巨集建立一個名為 的檔案的逗號分隔清單\@partlist
。因此,我們需要做的就是創建一個巨集來處理該列表並以您喜歡的方式輸出它。列表的順序將與命令中的順序完全相同\includeonly
。對清單進行排序將需要更多開銷。
這是一個範例(已更新以處理檔案名稱中的下劃線)。
\documentclass{report}
\begin{filecontents}{\jobname_1.tex}
\chapter{First Chapter}
\end{filecontents}
\begin{filecontents}{\jobname_2.tex}
\chapter{Second Chapter}
\end{filecontents}
\begin{filecontents}{\jobname_3.tex}
\chapter{Third Chapter}
\end{filecontents}
\includeonly{\jobname_1, \jobname_2}
\usepackage{titling}
\usepackage{etoolbox}
\usepackage{url}
\DeclareUrlCommand{\filename}{\urlstyle{rm}}
\makeatletter
\newcommand{\listincluded}{%
\begin{enumerate}
\renewcommand*{\do}[1]{\item \filename{##1.tex}}
\expandafter\docsvlist\expandafter{\@partlist}
\end{enumerate}
}
\makeatother
\renewcommand{\maketitlehookd}{%
\begin{center}
\bfseries List of Included Files
\end{center}
\listincluded
}
\title{A title}
\author{An author}
\date{}
\begin{document}
\maketitle
\tableofcontents
\include{\jobname1}
\include{\jobname2}
\include{\jobname3}
\end{document}