如何定义列表中出现的项目,这些项目出现在 ConTeXt 文档的其他地方?

如何定义列表中出现的项目,这些项目出现在 ConTeXt 文档的其他地方?

我有一份文件,每章前面都会显示一个摘要。摘要将列出后面段落中出现的重要点。

例如:

This chapter will talk about:
\printtopics

Section 1
Building a bridge is very easy. First start with some stones. Then,
\definetopic{How to build a temporary bridge from stones.}
find a narrow area in a river. Throw the stones into the river
until the river has completely stopped.
...

这将产生:

This chapter will talk about:
1. How to build a temporary bridge from stones.
2. How to hunt for rabbits.
3. How to find firewood.

Section 1
Building a bridge is very easy. First start with some stones. Then,
find a narrow area in a river. Throw the stones into the river
until the river has completely stopped.
...

使用\definetopic{How to build a temporary bridge from stones.}意味着将这些单词添加到列表中,并出现在章节开头的摘要中。

在 ConTeXt 中,如何定义要添加到列表中、出现在章节开头的项目,但在文档文本中定义它们?

答案1

您可以为此目的定义一个章节本地列表。

\definelist
  [topics]
  [criterium=chapter,
   headnumber=always,
   pagenumber=no]

\definecounter
  [topic]
  [way=bychapter]

\define[1]\definetopic{%
  \incrementcounter[topic]%
  \writetolist[topics]{\rawcountervalue[topic]}{#1}}

\starttext

\startchapter[title=Foo]
  This chapter will talk about:
  \placelist[topics]

  \startsection[title=Bar]
    \definetopic{How to build a temporary bridge from stones.}%
    \input knuth
    \definetopic{How to hunt for rabbits.}%
    \input knuth
    \definetopic{How to find firewood.}%
    \input knuth
  \stopsection
\stopchapter

\startchapter[title=Foo]
  This chapter will talk about:
  \placelist[topics]

  \startsection[title=Bar]
    \definetopic{How to hunt for rabbits.}%
    \input knuth
  \stopsection
\stopchapter

\stoptext

在此处输入图片描述

相关内容