[Tex/LaTex] How to put a coloured outline around fraction lines

colordecorationstikz-pgf

I use the contour package to put thick white outlines around labels in graphs, so they remain readable above the grid lines without taking up too much space.

Unfortunately, the package is not able to draw outlines of the horizontal lines used in fractions or root symbols when the [outline] option is active (which is used to generate 'proper' outlines instead of multiple copies of the text).

Is there a different way to generate coloured outlines of equations? Maybe something using pgf?

This is what happens with the contour package:

sqrt{\frac{a}{b}} with red contour. The contour around the horizontal lines is missing.

Generated with this minimal working example:

\documentclass{minimal}
\usepackage[outline]{contour}
\usepackage{amsmath}

\contourlength{.6pt}
\begin{document}
\contour{red}{$\sqrt{\dfrac{A}{B}}$}
\end{document}

Best Answer

Knuth in the TeXBook gave an example of "poor man's bold," (The TeXbook, p. 386) which can be typeset obtained by overprinting the normal weight symbol with slight offsets.

As he says:

The results are somewhat fuzzy, and they certainly are no match for the real thing if it's available; but poor man's bold is better than nothing, and once in a while you can get away with it.

Here, one can use a similar technique and the code is shown below:

\documentclass{article}
\usepackage{graphicx,xcolor} 
\usepackage{amsmath}
\def\PoorManContour#1#2#3{\leavevmode
    \setbox0=\hbox{{#1}}%
    \color{#3}\kern-.002em\copy0\kern-\wd0
    \color{#3}\raise-.04em\copy0\kern-\wd0
    \color{#3}\lower.04em\copy0\kern-\wd0
    \color{#3}\raise0.04em\copy0\kern-\wd0
    \color{#2}\raise-.012em\copy0\kern-\wd0
    \color{#2}\kern.06em\copy0\kern-\wd0
    \color{blue}\kern-.020em\lower.003em\box0
}
\begin{document}
\colorbox{gray!5}{\scalebox{5}{\PoorManContour{$\sqrt{\dfrac{A^3_i}{B^2}}$}{gray!60}{gray!60}}}
\end{document}

To achieve the best results possible one has to kern in small steps for possibly twenty steps or so. For simplicity, I have not done that. In the final version, you need to adjust the colors to suit, possibly changing the shading to white.

alt text

Edit

After reading Jan's comment below I read the manual and true, as the commenter said the easiest way to achieve what the OP wanted is to include the package without an option i.e., \usepackage{contour}. Helps to RFM!

Related Question