如何创建带有“ " format in ConTeXt?

如何创建带有“ " format in ConTeXt?

我正在制作一本书,其中章节标题为“第 1 周”、“第 2 周”、“第 3 周”等,部分标题为“活动 1”、“活动 2”、“活动 3”等,其他部分标题为“演示 1”、“演示 2”、“演示 3”等。

  • 不使用前面的数字,例如“1.1 活动 1”。
  • 文本中没有出现其他文本,例如“第 1 周主题”。
  • 各部分的数字永不重置。

以下是一个示例目录,展示了我希望它出现的样子:

 ______________________
|                      |
|      Contents        |
|                      |
| Week 1               |
|     Activity 1       |
|     Activity 2       |
|     Presentation 1   |
| Week 2               |
|     Activity 3       |
|     Activity 4       |
|     Presentation 2   |
|______________________|

文档偶尔也会有其他原始章节和节标题。这些标题应采用相同的字体格式,但除此之外,不得修改,并且不带任何数字,例如,使用章节标题“前言”、“结论”和节标题“注释”:

 ______________________
|                      |
|      Contents        |
|                      |
| Forward              |
| Week 1               |
|     Activity 1       |
|     Activity 2       |
|     Presentation 1   |
| Week 2               |
|     Activity 3       |
|     Notes            |
| Conclusion           |
|______________________|

我尝试过自己的解决方案,通过使用删除前面的数字\setuphead[chapter][number=no],创建计数器,例如\definenumber[weekcount],然后定义调用章节标题使用这些计数器的自定义宏,但是,我的解决方案不起作用:

\definenumber[weekcount]
\definenumber[activitycount]
\definenumber[presentationcount]
\setnumber[weekcount]{1}
\setnumber[activitycount]{1}
\setnumber[presentationcount]{1}
\define\week{\chapter{Week~\getnumber[weekcount]}\incrementnumber[weekcount]}
\define\activity{\section{Activity~\getnumber[activitycount]}\incrementnumber[activitycount]}
\define\presentation{\section{Presentation~\getnumber[presentationcount]}\incrementnumber[presentationcount]}
\setuphead[chapter][number=no]
\setuphead[section][number=no]
\starttext
    \week
        \activity
            This is some text.
        \activity
                This is some text.
        \presentation
            This is some text.
    \week
        \activity
            This is some more text.
        \activity
            This is some more text.
        \presentation
            This is some more text.
\stoptext

结果是:

 ______________________
|                      |
|      Contents        |
|                      |
| Week                 |
|     Activity         |
|     Activity 1       |
|     Presentation     |
| Week                 |
|     Activity         |
|     Activity 1       |
|     Presentation     |
|______________________|

如果删除\setuphead[chapter][number=no],结果也会不寻常:

 ______________________
|                      |
|      Contents        |
|                      |
| 1. Week 1.           |
|  1.1 Activity 1.     |
|  1.2 Activity 1.1    |
|  1.2 Presentation 1. |
| 2. Week 2.           |
|  2.1 Activity 2      |
|  2.2 Activity 2.1    |
|  2.3 Presentation 2. |
|______________________|
  • 为什么在章节标题中使用计数器的编号时会以这种方式出现?
  • 如何使用“周”格式创建自定义章节标题以及类似格式的章节标题?

答案1

我同意你的观点,利用文档结构是实现这一目的的便捷选择:它提供了高度的可配置性,并附带了默认的列表(阅读:目录)构建等简洁的附加功能。因此,以下将是基于结构解决方案,将基于枚举的方法留给其他人。


诀窍是自己的号码结构标头的关键。它允许精确控制每个标头的计数器机制。使用 定义的标头ownnumbers=yes采用强制性的第一个参数,通过该参数可以明确设置其计数器值。由以下对象创建的计数器\definecounter每个创建的计数器都有自己的方式允许对重置进行细粒度控制的键,或者根据本问题的要求禁用它(way=text)。

一旦计数器到位,剩下的就是抑制结构标题元素的放置。这分为两个部分:首先,所有标题都定义为仅隐式访问。用户级宏和\week是包装器,它们同时向标题传递其“自己的编号”和一个空的标题字符串。其次,定义放置方法,从标签映射中选择显示字符串,完全忽略结构标题。\activity\presentation\activityhead

(为了保持一致性,编码风格为 mkiv,因为\defineheadplacement不支持命名参数。)

\unprotect
%% (1) define the base commands. Notice the “ownnumber” key in
%%     \base_presentation and \base_activity. This lets us supply an
%%     independent numbering scheme.
\definehead [base_week]         [chapter]
\definehead [base_activity]     [section]
\definehead [base_presentation] [section]

\setuphead [part]
           [sectionresetset=default]
\setuphead [base_week]
           [number=yes,alternative=activityhead,
            sectionsegments=chapter]
\setuphead [base_activity]
           [number=yes,alternative=activityhead,
            sectionsegments=section,ownnumber=yes,
            before={\blank[line]\incrementcounter[activity]},]
\setuphead [base_presentation]
           [number=yes,alternative=activityhead,
            sectionsegments=section,ownnumber=yes,
            before={\blank[line]\incrementcounter[presentation]},]

%% (2) define a placement method for headings that omits the title.
\defineheadplacement[activityhead][vertical]#1#2{%
  \labeltext{\currenthead}\hskip\numberheaddistance #1%
}

%% (3) heading text is static so we use labels.
%%     The following line is cramped due to an exception in option
%%     parsing.
%%     Cf. http://archive.contextgarden.net/message/20120611.090327.dd9b1347.en.html
\setuplabeltext[base_week=Week,base_activity=Activity,base_presentation=Presentation]

%% (4a) define counters for use with the “presentation” and “activity”
%%      heads.
\definecounter [presentation] [start=0,way=text]
\definecounter [activity]     [start=0,way=text]
%% (4b) define a reset trigger for the part structural.
\definestructureresetset [default] [0] [0]

%% (5) define a set of wrappers. These compensate for the fact that you
%%     can’t have a simple structure head without the mandatory
%%     argument. We start with a plain one.
\define    \week{\base_week{}}
%%     The “\presentation” and “\activity” macros need special treatment
%%     to make it respect the separate counter.
\define    \activity{\base_activity    {\rawcountervalue[activity]}    \empty}
\define\presentation{\base_presentation{\rawcountervalue[presentation]}\empty}

%% (6) side effect: the table of contents needs a placement method on
%%     its own in order to conform with the requirements. This step is
%%     optional if you don’t care for a toc.
\unexpanded\def\week_list#1#2#3{%
  \blank[line]%
  {\tfa\word\sc\labeltext{\currentlist}}%
  \space#1\hfill#3\par
}   
\unexpanded\def\activity_list#1#2#3{%
  \hskip\emwidth 
  \labeltext{\currentlist}%
  \space#1\hfill#3\par
}       

\setuplist [base_week]         [alternative=command,command=\week_list]
\setuplist [base_activity]     [alternative=command,command=\activity_list]
\setuplist [base_presentation] [alternative=command,command=\activity_list]
\protect

\starttext
\placelist[base_week, base_activity, base_presentation]\page
\part {My Life ...}
    \week
        \activity
            Dear diary. Today I was pompous and my sister was crazy.
        \activity
                This is some text.
        \activity
            This is some text.
    \week
        \activity
            This is some more text.
        \presentation
            This is some more text.
        \activity
            This is some more text.
        \activity
            This is some more text.
    \part{... the Exciting Story of a Great Man}
    \week
       \activity
            This is yet some more text.
        \presentation
            This is yet some more text.
        \activity
            This is yet some more text.
\stoptext

例子

相关内容