我有一本用 latex 排版的书,里面有大约 30 个故事。这些故事符合 3 本书,并且故事有重叠,例如,这意味着故事 1 出现在书 1 和书 2 中。
我如何生成包含 3 个目录的乳胶文档?每个目录指向与每本“子书”相对应的故事?
我认为解决方案应该包括一种方法来告诉每个故事(章节)属于哪本“子书”。
答案1
由于没有给出示例,我将尝试根据假设和minitoc
包提供答案。
这使用\part
“subbook”和\parttoc
宏来指示minitoc
生成本地目录。可以通过重新定义\ptctitle
宏来更改本地目录标题。
笔记:minitoc
截至撰写本文时,该软件包已有大约 6 年历史,并且不知何故无人维护。另一种选择可能是使用软件包etoc
。
\documentclass{book}
\usepackage{minitoc}
\usepackage{filecontents}
\usepackage{blindtext}%
\usepackage[hypertexnames=false]{hyperref}
\makeatletter
\@addtoreset{chapter}{part}
\makeatother
\let\standardptctitle\ptctitle%
\doparttoc
\renewcommand{\partname}{Book}
\begin{filecontents}{story1.tex}
\chapter{Story 1}%
\end{filecontents}
\begin{filecontents}{story2.tex}
\chapter{Story 2}%
\end{filecontents}
\begin{filecontents}{story3.tex}
\chapter{Story 3}%
\end{filecontents}
\begin{document}
\part{Some Stories}
\tableofcontents
\renewcommand{\ptctitle}{\standardptctitle~of \partname~\thepart}
\parttoc
\input{story1}
\input{story2}
\part{More Stories}
\parttoc
\input{story2}
\input{story3}
\part{Even More Stories}
\parttoc
\input{story3}
\input{story1}
\end{document}
etoc
带软件包的版本
该etoc
软件包提供了方便的访问\localtableofcontents
和维护。参见埃托克了解更多信息。
\documentclass{book}
\usepackage{etoc}%
\usepackage{filecontents}
\usepackage{blindtext}%
\usepackage[hypertexnames=false]{hyperref}
\makeatletter
\@addtoreset{chapter}{part}
\makeatother
\let\StandardContentsName\contentsname
\renewcommand{\partname}{Book}
\begin{filecontents}{story1.tex}
\chapter{Story 1}%
\end{filecontents}
\begin{filecontents}{story2.tex}
\chapter{Story 2}%
\end{filecontents}
\begin{filecontents}{story3.tex}
\chapter{Story 3}%
\end{filecontents}
\begin{document}
\tableofcontents% The whole document contents
\renewcommand{\contentsname}{\StandardContentsName~of \partname~\thepart}
\part{Some Stories}
\localtableofcontents
\input{story1}
\input{story2}
\part{More Stories}
\localtableofcontents
\input{story2}
\input{story3}
\part{Even More Stories}
\localtableofcontents
\input{story3}
\input{story1}
\end{document}
答案2
\documentclass{article}
\makeatletter
\let\old@starttoc\@starttoc
\let\old@addcontentsline\addcontentsline
\def\@toc{toc}
\def\@alltoc{tocabc}
\def\@starttoc#1{%
\def\tmp{#1}%
\ifx\tmp\@toc\let\tmp\currenttoc\fi
\old@starttoc\tmp}
\def\addcontentsline#1#2#3{%
\def\tmp{#1}%
\ifx\tmp\@toc
\ifx\currenttoc\@alltoc
\old@addcontentsline{toca}{#2}{#3}%
\old@addcontentsline{tocb}{#2}{#3}%
\old@addcontentsline{tocc}{#2}{#3}%
\else
\old@addcontentsline{\currenttoc}{#2}{#3}%
\fi
\else
\old@addcontentsline{#1}{#2}{#3}%
\fi}
\makeatother
\begin{document}
\def\currenttoc{toca}\def\contentsname{story 1 contents}\tableofcontents
\def\currenttoc{tocb}\def\contentsname{story 2 contents}\tableofcontents
\def\currenttoc{tocc}\def\contentsname{story 3 contents}\tableofcontents
\def\currenttoc{tocabc}
\section{book, the first}
\def\currenttoc{toca}
\subsection{start}
red red blue yellow red red blue yellow
red red blue yellow red red blue yellow
\def\currenttoc{tocb}
\subsection{new start}
one two three four five one two three four five
one two three four five one two three four five
\def\currenttoc{tocabc}
\section{book, the second}
\def\currenttoc{tocb}
\subsection{more numbers}
one two three four five one two three four five
one two three four five one two three four five
\def\currenttoc{tocc}
\subsection{even newer start}
rome paris london
rome paris london
rome paris london
\def\currenttoc{toca}
\subsection{return to colour}
black blue green black blue green black blue green
black blue green black blue green black blue green
\def\currenttoc{tocabc}
\section{book, the third}
\def\currenttoc{tocb}
\subsection{numbers again}
one two three four five one two three four five
one two three four five one two three four five
\end{document}