問題

問題

問題

如果我的文件包含多個目錄,我可以限制新增的目錄部分的範圍並重設目錄嗎?

情況

我有一份由 10 種語言組成的文件。 (使用\input{en}, \input{de}, \input{da}等)有11個目錄:

  • 語言目錄(由每個組成\input(可能只是一個包含每個的鉤子的自訂表\input。我還不知道如何實現它。
  • 每種特定語言的本地目錄(10 種語言)

範例程式碼

Main .tex 的範例

\documentclass{article}
\usepackage{fontspec}
\begin{document}
\maketableofcontents % language directory (list of inputs with language names)
\input{en}
\input{de}
\input{da}
\end{document}

en.tex 的範例

\maketableofcontents % local toc
\section{apple}
%\somecommand % TOC scope limit

de.tex 範例

\maketableofcontents % local toc
\section{apfel}
%\somecommand % TOC scope limit

da.tex 的範例

\maketableofcontents % local toc
\section{æble}
%\somecommand % TOC scope limit

答案1

這是一個使用的解決方案etoc注意預設 filecontents 環境的限制

\begin{filecontents}{en.tex}
\localtableofcontents
\section{apple}
\end{filecontents}
\documentclass{article}
\usepackage{bookmark}
\usepackage{etoc}

% Use this version \newlang{<name>}{<file>}
% to use external files
\newcommand\newlangfile[2]{%
  \newlang{#1}%
  \input{#2}%
}
\newcommand\newlang[1]{%
  \newpage\pdfbookmark{#1}{bkm#1}%
  \renewcommand\contentsname{#1 Contents}%
  \etoctoccontentsline{part}{#1}%
}


\begin{document}
\setcounter{tocdepth}{0}
\renewcommand\contentsname{Language directory}
\tableofcontents
\setcounter{tocdepth}{3}


%\newlang{english}
%\localtableofcontents
%\section{Apple}
% Or use 
\newlangfile{english}{en.tex}
% if you prefer the second macro

\newlang{german}
\localtableofcontents
\section{Apfel}
\newlang{danish}
\localtableofcontents
\section{able}

\end{document}

相關內容