如何定義清單中出現的項目,該項目出現在 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

在此輸入影像描述

相關內容