# How does text styling for synonyms work in ConTeXt?

So I set up synonyms (here abbreviations) similar to the example on the Wiki (and expanded for first use as in this post).

\definesynonyms        [abbreviation][abbreviations][\infull]
\setupsynonyms         [synonymstyle=normal,textstyle=bold]
\def\ac#1{%
\ifcsname ac@firstused@#1\endcsname%
\csname #1\endcsname%
\else%
\csname #1\endcsname\margintext{\infull{#1}}%
\expandafter\def\csname ac@firstused@#1\endcsname{1}%
\fi%
}

\abbreviation{RE}{Regular Expression}
\starttext
\ac{RE}
\blank
\RE\ \infull{RE}
\blank
\ac{RE}
\stoptext


As far as I understand it synonymstyle=normal should cause the abbreviated form to be in text font (which it in fact does) and textstyle=bold should make the long text (got with \infull) bold (which does not work as intended).

As depicted above the long text does not turn bold (if in normal text and does turn bold in the margin, probably due to margin defaults). So how does one influence the text style reliably (so that margin and text both have the same format: the one specified with \setupsynonyms)?

With \setupsynonyms[textstyle=bold] you are overriding the default value of all synonyms. However, strc-syn.mkiv has the following definition:

\definesynonyms
[\v!abbreviation]
[\v!abbreviations]
[\infull]

\setupsynonyms
[\v!abbreviation]
[\c!textstyle=\v!capital]


So, abbreviations has been set to use textstyle=capital. So to override this, you need:

\setupsynonyms[abbreviation][synonymstyle=normal,textstyle=bold]


BTW, ConTeXt has a mechanism for expanding the synonym at first use: pass alternative=first to definesynonym or setupsynonym.

\setupsynonyms[abbreviation]
[
alternative=first,
synonymstyle=normal,
textstyle=bold,
]

\abbreviation{RE}{Regular Expression}

\starttext
Consider a \RE\ \unknown. An \RE\ again.
\stoptext


which gives

Now, you want the full form to appear in the margin. The formatting is controlled by the following code in strc-syn.mkiv

\startsetups[\??simplelistrenderings:\v!synonym:\v!first]
\fastsetup{\??simplelistrenderings::\v!synonym}
\doifelsecurrentsynonymshown \donothing {
\simplelistalternativeparameter\c!inbetween
\simplelistalternativeparameter\c!left
\fastsetup{\??simplelistrenderings::\v!text}
\simplelistalternativeparameter\c!right
}
\stopsetups


So, (as explained by Wolfgang in the comments below), one option is set the left and right keys of the first simplelistalternative so that the text is typeset in the margin:

\define\FirstSynonymEntry{\dowithnextbox{\margintext{\unhbox\nextbox}}\hbox}
\setupsimplelistalternative
[first]
[
left=\FirstSynonymEntry\bgroup,
right=\egroup,
]


An alternative to modifying the first rendering, you can define your own rendering for margins:

\unprotect
\definesimplelistalternative
[\v!margin]

\startsetups[\??simplelistrenderings:\v!synonym:\v!margin]
\fastsetup{\??simplelistrenderings::\v!synonym}
\doifelsecurrentsynonymshown \donothing {
\margintext{\fastsetup{\??simplelistrenderings::\v!text}}
}
\stopsetups
\protect

\setupsynonyms[abbreviation]
[
alternative=margin,
synonymstyle=normal,
textstyle=bold,
]

\abbreviation{RE}{Regular Expression}

\setuplayout[cutspace=2in, backspace=2in, leftmargin=1.5in, width=fit]
\showframe

\starttext
Consider a \RE\ \unknown. An \RE\ again.
\stoptext


which gives

• You don’t have to create a new synonym alternative. When you create the following command \define\FirstSynonymEntry{\dowithnextbox{\margintext{\unhbox\nextbox}}\hbox} you can apply it to the first alternative with \setupsimplelistalternative[first][left=\FirstSynonymEntry\bgroup,right=\egroup]. Sep 13 '18 at 15:46
• @Wolfgang: I'll add your comment to the answer, but I personally prefer defining a new alternative to setting values for left and right. An ideal solution will be to modify the first rendering so that one can say \setupsimplelistalternative[first][command=\margintext] or something similar. Sep 13 '18 at 15:49