如何让 ConTeXt 在目录和页脚中显示带有章节的页码?

如何让 ConTeXt 在目录和页脚中显示带有章节的页码?

我希望页码出现在目录和页脚中,就像 Digital Equipment Corporation 的旧手册一样。即 Chapter#--Page#,其中每章的页码都从 1 重新开始。这是我能做到的最好的:

\setuppagenumbering[alternative=doublesided,location=]
\starttext

% with \headnumber[chapter], page number in TOC appears as "-1".
% with \determineheadnumber[chapter]\currentheadnumber, page numbers in
%   TOC appear as "0-1"
\define[1]\addchapterprefix{\headnumber[chapter]--#1}
\defineconversion[addchapterprefix][\addchapterprefix]
\definestructureconversionset[frontpart:pagenumber][][romannumerals]
\definestructureconversionset[bodypart:pagenumber][][addchapterprefix]
\setuppagenumber[way=bychapter,numberconversionset=pagenumber]

\setuplist[chapter][alternative=f,style=\ssb]
\setuplist[section][alternative=c,pageconversionset=pagenumber]
\setupfootertexts%
    [{{\bf\userpagenumber}~~\getmarking[chapter][first]}]%
    []%
    []%
    [{\getmarking[chapter][first]~~{\bf\userpagenumber}}]

\setuphead[chapter][page=right]
\setuphead[section][number=no,style=\ssb]

% with \startsectionblockenvironment[frontpart] ConTeXt fails to produce
%   any output, or error message.
\startfrontmatter
\startchapter[list=Table of Contents]
\setupinterlinespace[small]
\placecontent[criterium=all]
\startsection[title=Preface]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter
\stopfrontmatter

\startbodymatter
\setcounter[userpage][1]

\startchapter[title=This is my chapter title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\startsection[title=This is my section title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter

\startchapter[title=This is another chapter title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\startsection[title=This is another section title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter

\stopbodymatter
\stoptext

我使用了\startfrontmatter\startsectionblockenvironment[frontpart]因为 ConTeXt 与后者循环一次,并且不产生任何输出或错误消息。页面转换的调用似乎与 一起工作\startfrontmatter,只是我在生成目录时找不到定义章节编号的任何地方。

在 macOS 10.14.6 上使用 ConTeXt 版本 2019.03.21 21:39、LuaTeX 版本 1.10.0(Tex Live 2019)。

答案1

您混淆了以下两个命令:

  • \startsectionblock[⟨NAME〉] ... \stopsectionblock
  • \startsectionblockenvironment[⟨NAME〉] ... \stopsectionblockenvironment

环境sectionblock与环境相同,bodypart但您传递了节块作为启动命令的参数。sectionblockenvironment环境用于设置在某个特定命令开始时使用的选项节块并将其放在文档的序言中。

为了获得章节页码前面的值,您必须启用字首对于userpagenumber(该\setuppagenumber命令是的同义词\setupuserpagenumber)。

\setupuserpagenumber
  [way=bychapter,
   prefix=yes,
   prefixset=chapter,
   prefixsegments=chapter]

\setuppagenumbering
  [alternative=doublesided,
   location=none]

\setupfootertexts
  [{\prefixedpagenumber\hspace[medium]\getmarking[chapter][first]}]
  []
  []
  [{\getmarking[chapter][first]\hspace[medium]\prefixedpagenumber}]

\setuplist
  [chapter]
  [alternative=f]

\setuplist
  [section]
  [alternative=c,
   pageprefix=yes,
   pageprefixsegments=chapter]

\defineconversionset [frontpart:pagenumber] [] [i]
\defineconversionset  [bodypart:pagenumber] [] [n]

\setuphead
  [section]
  [number=no]

\starttext

\startfrontmatter

\completecontent

\stopfrontmatter

\startbodymatter

\dorecurse{2}
  {\chapter{Chapter \convertnumber{word}{#1}}
   \dorecurse{4}
     {\section{Section ##1}
      \dorecurse{3}{\samplefile{weisman}}}}

\stopbodymatter

\stoptext

答案2

回答我自己的问题(尽管我不完全确定为什么这样做有效)。它依赖于\setupuserpagenumber[ prefixsegments=chapter ]大多数文档中缺少的内容:

\setuppagenumbering[alternative=doublesided,location=]
\starttext

\definestructureprefixset[pageprefix][chapter][] % ch--pg in \userpage footers
\setuplist[chapter][alternative=f,style=\ssb]
\setuplist[section][alternative=c,pageconversionset=pagenumber]
\setupfootertexts%
    [{{\bf\userpagenumber}~~\getmarking[chapter][first]}]%
    []%
    []%
    [{\getmarking[chapter][first]~~{\bf\userpagenumber}}]

\setuphead[chapter][page=right]
\setuphead[section][number=no,style=\ssb]

\startfrontmatter
\setupuserpagenumber[numberconversion=romannumerals]

\startchapter[list=Table of Contents]
\setupinterlinespace[small]
\placecontent[criterium=all]
\startsection[title=Preface]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter
\stopfrontmatter

\startbodymatter
\setupuserpagenumber[way=bychapter,prefix=yes,
            prefixsegments=chapter, % ch--pg in ToC
            prefixset=pageprefix,   % ch--pg in \userpage footers
            numberconversion=numbers]
\setcounter[userpage][1]

\startchapter[title=This is my chapter title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\startsection[title=This is my section title]
\dorecurse{10}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter

\startchapter[title=This is another chapter title]
\dorecurse{20}{The quick brown fox jumps over the lazy dog.\par}
\startsection[title=This is another section title]
\dorecurse{20}{The quick brown fox jumps over the lazy dog.\par}
\stopsection
\stopchapter

\stopbodymatter
\stoptext

相关内容