# How to make a fancy rule under a line of text in ConTeXt

I've (mis)used LaTeX on and off for the past 10 years and am now trying out ConTeXt, mostly because it allows alignment to a baseline grid. I'd like to produce a rule (line) below some text such that the rule:

• is some distance (1pt, let's say) below the baseline of the text (assume the text fits on one line),
• is as wide as the text area (\textwidth), and
• terminates on the right end with a small black square vertically centered on the rule.

In LaTeX, I can do something like this:

\documentclass{article}
\usepackage{calc}

\begin{document}
\makebox[0pt][l]{%
\rule[-1pt]{\textwidth-4pt}{.4pt}%
\rule[-2.6pt]{4pt}{4pt}
}%
This text sits on the fancy rule.
\end{document}


Which gives me this:

How can I do something similar in ConTeXt? I've tried overlays and \blackrule, but I don't know how to move a \blackrule vertically. I'm open to any solution whether it involves overlays and \blackrules or something else, but I would like the text to align to the baseline grid if possible.

There are many other ways to do this in ConTeXt, but a literal translation of your method will be the following:

\starttext

\dontleavehmode
\rlap{\lower 1pt \blackrule[width=\dimexpr\textwidth-4pt\relax, height=0.4pt]%
\lower 2.6pt \blackrule[width=4pt, height=4pt]}%
This text sits on the fancy rule.

\stoptext


which gives

• And what would be best practice? The ConTeXt way of doing it?
– DG'
Jun 9 '15 at 7:23
• @DG' see metafox's solution. Jun 9 '15 at 14:04

You can use the \framed command to draw the line as a background graphic for your text. When you create a new \framed command with \defineframed you have to apply all the settings only once.

\startuseMPgraphic{fancyrule}
draw (0,StrutDepth)--(OverlayWidth,StrutDepth) withpen pensquare scaled .4pt ;
drawdot (OverlayWidth,StrutDepth) withpen pensquare scaled 4pt ;
setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic

\defineoverlay[fancyrule][\useMPgraphic{fancyrule}]

\defineframed
[FancyRule]
[frame=off,
offset=0pt,
strut=yes,
width=max,
align=flushleft,
background=fancyrule]

\starttext
\FancyRule{This text sits on the fancy rule.}
\stoptext


• Thanks, this method has a definite elegance to it. Is there an easy way to make it align to the baseline grid? Is it possible to separate the rule from the baseline of the text by 1 pt? Jun 9 '15 at 13:25
• @lefthander: Change StrutDepth to StrutDepth -1pt Jun 9 '15 at 14:11