3

This code, found at How to define items appearing in a list, which appears somewhere else in the document in ConTeXt?, allows users to add items to a list by using the code \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

Sometimes my source code calls for the same information to be added to a list, multiple times, e.g.:

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

   \definetopic{This is about birds.}

   \definetopic{This is about rabbits.}

In such a case, I don't want the item to appear twice when calling \placelist[topics]. Is there any way to remove duplicate items from this list?

2
  • 2
    Sounds more like you want a register rather than a list. Aug 20, 2018 at 1:23
  • Okay, I've tried changing to a register, but it adds page numbering to the left and other formatting? Is there a way to remove that so it is just plain text appearing in the document, e.g. to be put inside \startitemize and \enditemize?
    – Village
    Aug 21, 2018 at 14:26

1 Answer 1

5
+500

You tried to change the list to a register and asked in the comments whether one can remove the additional formatting added by the register. This is easily possible as I show in this example. Furthermore, the register will be sorted alphabetically.

\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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .