如何在 ConTeXt 中创建仅限于文档各部分的目录?

如何在 ConTeXt 中创建仅限于文档各部分的目录?

我正在处理单个 PDF 中的多卷文档,并且没有重置页码或章节号。

由于 ConTeXt 似乎没有任何\volume标题,而 和 有,\part因此\chapter我只需在需要时添加新的标题页即可。文档结构如下所示,\titlepage是一个自定义宏,用于放置标题信息并显示卷号:

\titlepage
\startbodymatter
    \part{Alligators}
        \chapter{Freshwater}
            \section{Diet}
            \section{Habitat}
    \part{Fish}
\stopbodymatter
\titlepage
\startbodymatter
    \part{Birds}
    \part{Snakes}
\stopbodymatter
\titlepage
\startbodymatter
    \part{Frogs}
\stopbodymatter

我发现如果将目录放在第一卷中,它会太长。我需要在每一卷中放置一个目录,该目录仅显示该卷的条目,例如\part\chapter\section等,而不显示其他条目。

我如何在宏中放置目录\titlepage,以便 ConText 在每个标题后创建一个目录,并且每个目录仅显示该标题页之后出现的内容,但不显示下一个标题页之后的内容?例如,上面出现的第一卷的目录将如下所示:

Contents
1 Alligators
    1 Freshwater
        1 Diet
        2 Habitat
 2 Fish

“volume” 的条目不需要出现在这些列表中。

答案1

您希望顶层结构被命名体积并为每个结构设置单独的目录。棘手的部分是每个结构都有一个与之关联的列表,您不能一路清除它,只留下本地项目进行排版。因此,显而易见的解决方案是:不要总是使用相同的结构。不同的结构,不同的列表。

下面的代码演示了一个\titlepage宏,每次调用时都会动态创建新的结构(标题、列表)。一切都在后台进行,因此您可以继续使用结构宏。但有一个例外:我擅自对标签进行了标题化(例如\part-> \Part),以避免混淆。

A6 纸上的演示输出。

%% 1. Define headings matching your structuring preferences. To get a
%%    “volume” structure at level 1, just map it to part =) These will
%%    form the base of the dynamically generated structures later.
%%    NB: To achieve a consistent overall layout you will want to
%%    \setuphead and \setuplist these blueprints here, not their
%%    copies.
\definehead [base_volume]  [part]                                    % level 1
\definehead [base_part]    [chapter]    [sectionsegments=chapter]    % level 2
\definehead [base_chapter] [section]    [sectionsegments=section]    % level 3
\definehead [base_section] [subsection] [sectionsegments=subsection] % level 4

\definelist [base_volume]  [part]
\definelist [base_part]    [chapter]    [style={\word\sc}]
\definelist [base_chapter] [section]    [style=bold]
\definelist [base_section] [subsection] [style=italic]

%% 2. Some settings to fake the  titlepage.
\definemakeup [titlepage]
\defineframed [volumetitledisplay] [
  align=middle,
  frame=off,
  width=\hsize,
]

\unprotect

%% 3. Initialize a counter. It will be used to create macros and lists
%%    for each volume.
\newcount \nvolumes \nvolumes0

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                            main macro
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\titlepage{%
  %% 4. Increment the volume counter.
  \advance\nvolumes\plusone

  %% 5. Define some internal shortcuts involving the current counter.
  \setevalue {currentvolume}{volume_\the\nvolumes}
  \setevalue   {currentpart}{part_\the\nvolumes}
  \setevalue{currentchapter}{chapter_\the\nvolumes}
  \setevalue{currentsection}{section_\the\nvolumes}
  \setevalue   {currentlist}{list_\the\nvolumes}

  %% 6. Create the structures local to this volume. They inherit the
  %%    setups from their parents as defined above.
  \definehead [\currentvolume]  [base_volume]
  \definehead [\currentpart]    [base_part]
  \definehead [\currentchapter] [base_chapter]
  \definehead [\currentsection] [base_section]

  \definelist [\currentvolume]  [base_volume]
  \definelist [\currentpart]    [base_part]
  \definelist [\currentchapter] [base_chapter]
  \definelist [\currentsection] [base_section]

  %% 7. The TOC is a combined list. It needs to be recombined for each
  %%    volume, referencing the appropriate structure lists.
  \definecombinedlist [\currentlist] [%\currentvolume,%
                                      \currentpart,%
                                      \currentchapter,%
                                      \currentsection,]
  \setupcombinedlist [\currentlist] [ criterium=text, ]

  %% 8. The user macros. They are uppercased to distinguish them from
  %%    the builtin ones with the same name. Nothing special, really:
  %%    they just map to the most recently generated structures.
  \setevalue {Volume}{\csname\currentvolume\endcsname}
  \setevalue   {Part}{\csname\currentpart\endcsname}
  \setevalue{Chapter}{\csname\currentchapter\endcsname}
  \setevalue{Section}{\csname\currentsection\endcsname}

  %% 9. Some title page stuff that is actually visible. If the volumes
  %%    should carry a title, just make \titlepage monadic and pass the
  %%    argument to \Volume{}. In order to make the title appear, don’t
  %%    forget \setuphead[base_volume][placehead=yes]!
  \page[right]
  \Volume{\the\nvolumes} %% <= here
  \starttitlepagemakeup
    \vfill
    \volumetitledisplay{%
      {\sc Volume} \the\nvolumes
    }
    \vfill
  \stoptitlepagemakeup

  %% 10. Typeset the table of contents.
  \title{Contents}%
  \csname place\currentlist\endcsname
}

\protect

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                               usage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\starttext

\titlepage
\startbodymatter
    \Part{Alligators}
        \Chapter{Freshwater}
            \Section{Diet}
            \Section{Habitat}
    \Part{Fish}
\stopbodymatter
\titlepage
\startbodymatter
    \Part{Birds}
    \Part{Snakes}
\stopbodymatter
\titlepage
\startbodymatter
    \Part{Frogs}
\stopbodymatter

\stoptext

答案2

您可以拆分文本并将卷放入单独的文件中。这样,您的文件就会更小,目录也会自动显示当前卷。

要调整页码偏移量,您可以使用

\setcounter[userpage][42]

并调整零件编号

\setstructurenumber{1}{12}

第一个参数是结构层级,一层表示部分,二层表示章节等。第二个参数是增量。它取决于上一卷中部分的数量。

相关内容