如何从 ConTeXt 中的章节本地列表中删除重复项?

如何从 ConTeXt 中的章节本地列表中删除重复项?

此代码位于如何定义列表中出现的项目,这些项目出现在 ConTeXt 文档的其他地方?,允许用户使用以下代码将项目添加到列表中\definetopic{}

\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

有时我的源代码需要将相同的信息多次添加到列表中,例如:

\chapter{One}
   \definetopic{This is about rabbits.}

   \definetopic{This is about birds.}

   \definetopic{This is about rabbits.}

在这种情况下,我不希望在调用时该项目出现两次\placelist[topics]。 有什么方法可以从此列表中删除重复的项目?

答案1

您尝试将 更改为listregister并在评论中询问是否可以删除 由 增加的额外格式register。正如我在此示例中所展示的那样,这很容易实现。此外, 将按register字母顺序排序。

\defineregister
  [topics]
  [criterium=chapter,
   pagenumber=no,
   indicator=no,
   before=,
   n=1]

\def\definetopic{\topics}

\starttext

\startchapter[title=Foo]
  This chapter will talk about:
  \placeregister[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:
  \placeregister[topics]

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

\stoptext

相关内容