2

I have an itemized list like this:

\starttext
    \startitemize[n]
         \item This is some text.
         \item This is some more text.
         \item This is some yet more text text.
    \stopitemize
\stoptext

How can I assign a custom macro to surround all of the text in the list, it would be equivalent to this:

\define[1]\mymacro{Do some stuff #1}

\starttext
    \startitemize[n]
         \item \mymacro{This is some text.}
         \item \mymacro{This is some more text.}
         \item \mymacro{This is some yet more text text.}
    \stopitemize
\stoptext

Basically I need to do some settings to the itemize such that the equivalent of placing \mymacro{} around every item in the itemized list.

How can I get a macro to surround \item's text in ConTeXt?

4
  • 2
    Use the \startitem…\stopitem syntax instead of plain \item and then use the usual hooks.
    – TeXnician
    Aug 10, 2021 at 15:57
  • @TeXnician what hooks do you mean?
    – Village
    Aug 10, 2021 at 18:15
  • 1
    Sorry, can't elaborate right now. Other approach: wiki.contextgarden.net/Command/item (there's an example by Wolfgang using a custom item command).
    – TeXnician
    Aug 10, 2021 at 20:01
  • See the first example in tex.stackexchange.com/a/463045 for how to wrap an item. It requires a different syntax though. Aug 12, 2021 at 13:53

1 Answer 1

2

Following the advice by TeXnician and the correction by Henri Menke, this seems to work in your case:

\define[1]\mymacro{Do some stuff #1 Do some more stuff}

\setupitemize[command=\mymacro]

\starttext
    \startitemize[n]
         \item{This is some text.}
         \item{This is some more text.}
         \item{This is some yet more text text.}
    \stopitemize
\stoptext

It might be better to define your own itemization, not to change the default one if you want to use that one as well. This could work:

\define[1]\mymacro{Do some stuff #1 Do some more stuff}

\defineitemgroup[myitems]
\setupitemgroup[myitems][each][n]
\setupitemgroup[myitems][each][command=\mymacro]

\starttext
    \startitemize[n]
     \item This is some text.
     \item This is some more text.
     \item This is some yet more text text.
    \stopitemize

    \startmyitems
     \item{This is some text.}
     \item{This is some more text.}
     \item{This is some yet more text text.}
    \stopmyitems
\stoptext
2
  • 1
    You'll still need braces around each \item. To see what I mean try \define[1]\mymacro{before #1 oeps} Aug 12, 2021 at 13:51
  • Thanks, updated. (I first wanted to add an answer just to have an answer. I make this community wiki...)
    – mickep
    Aug 12, 2021 at 17:47

You must log in to answer this question.

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