Underlining With TextBackgrounds

From ConTeXt wiki

< Main Page | Visuals >

Underlining is generally frowned upon by experienced TeXnicians. Occasionally, however, it is necessary and \ul doesn't work quite right. In those cases using \definetextbackground for the underlining may also be tried.

\definetextbackground[underline]
  [location=text,alternative=1,background=,frame=off]
\definestartstop[underline]
  [before={\starttextbackground[underline]},
   after=\stoptextbackground]
An example with \startunderline underlined\stopunderline\ text.

If desired, the location of the line can also be adjusted.

\startuseMPgraphic{mpos:par:columnset} % Shift underlining down a touch
   \iftracepositions show_multi_pars \else draw_multi_pars \fi ;
   path p ; p := boundingbox currentpicture ;
   currentpicture := currentpicture shifted (0,-StrutDepth/3) ;
   setbounds currentpicture to p ;
\stopuseMPgraphic
\definetextbackground[underline]
  [location=text,alternative=1,background=,frame=off]
\definestartstop
  [underline]
  [before={\starttextbackground[underline]},
   after=\stoptextbackground]
An example with \startunderline underlined\stopunderline\ text.