Gerion Entrup schrieb am 25.06.2024 um 08:41:
Am Dienstag, 25. Juni 2024, 00:09:09 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 24.06.2024 um 23:57:
Am Montag, 24. Juni 2024, 21:20:19 MESZ schrieb Aditya Mahajan:
On Mon, 24 Jun 2024, Gerion Entrup wrote:

Hi,

I was in the process to convert an itemize part to a description and wanted to 
simplify the code in the same move.
I discovered headcommand for that, but struggled to set the text in an 
highlight _and_ make a colon at the end.
Not sure what exactly you want, but how about:

\definehighlight[hl][style={\m{>}\,\switchtobodyfont[tt]}]
% This is the wrong way to define such a command as '>' is not part of the 
style. I have left this definition just for comparison with the soln below.
Is there a better way to define a highlight that sets a style (color, font) 
_and_ a prefix (symbol)?
Another way, I know of, would be just a plain def, something like 
\def{\hl}{\groupedcommand{>\,\switchtobodyfont[tt]}{}}, but actually I want to 
define a highlight (just with an additional prefix).

1. ConTeXt already uses \hl as name for a existing command.

2. Use \definestartstop:

\definestartstop [gerion] [style=mono,left={›\thinspace}]

\starttext

text

\gerion{text}

\stoptext

\definedescription[category][
        alternative=top,
        headstyle=bold,
        width=broad,
]

\definedescription[desc][
        width=fit,
        distance={\widthofstring{~}},

distance=\spaceamount,

Wolfgang

This seems to be much better but does not lead to the wanted result. The full 
example now is:
```
\definestartstop[myhl][style=mono,left={›\thinspace}]

\definedescription[categorie][
        alternative=top,
        headstyle=bold,
        width=broad,
]

\definedescription[desc][
        width=broad,
        distance=\spaceamount,
        headcommand={\groupedcommand{\startmyhl}{\stopmyhl :}},
        headstyle=,
        before={\startpacked},
        after={\stoppacked},
        alternative=hanging
]

\starttext

This is a \myhl{highlight}.

Some listings

\startcategorie{Itemize}
        \startitemize[packed]
                \item \myhl{first}: one
                \item \myhl{second}: two
        \stopitemize
\stopcategorie

Now the same as desc:
\startcategorie{Desc}
        \startdesc{first} one \stopdesc
        \startdesc{second} two \stopdesc
\stopcategorie

\stoptext
```

This adopts the correct style in \startdesc \stopdesc and sets the colon but 
omits the › (the left part).

You can do the following in the next version.

1. Add "arguments=yes" to \definestartstop to enable the optional argument for the new command.

2. Use the new commands with the "headcommand" key and apply ":" as right delimiter for the content of \Highlight.

\definestartstop
  [Highlight]
  [arguments=yes,
       style=mono,
        left={›\thinspace}]

\definedescription
  [description]
  [      width=broad,
      distance=\spaceamount,
   headcommand=\Highlight[right=:],
   alternative=hanging]

\starttext

This is a \Highlight{highlight}.

\startdescription[title={Lorem ipsum}]
\samplefile{lorem}
\stopdescription

\stoptext

Wolfgang

Attachment: Highlight.pdf
Description: Adobe PDF document

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to