28

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}
4
  • 2
    This will be tricky. PDF and PostScript have features to draw outlines around text glyphs (which is how contour does its thing). But the lines are not drawn as PDF or PostScript glyphs, so they would have to be treated differently.
    – Lev Bishop
    Commented Jan 10, 2011 at 1:22
  • Thanks, Lev. Would you happen to know what kind of objects the lines are? If they are a kind of vector image inserted into the pdf output, maybe there is a way of adding a frame around them using pdf commands?
    – Jake
    Commented Jan 10, 2011 at 15:46
  • 2
    A non-solution: I usually just put a bit of white (or some other appropriate color) background behind labels to make them readable.
    – Caramdir
    Commented Jan 10, 2011 at 22:46
  • they are hrules. See the TeXBook, appendix G. Rule 15d for example covers the fraction.
    – Lev Bishop
    Commented Jan 15, 2011 at 0:11

2 Answers 2

22
+100

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!

3
  • 6
    That is exactly what the contour package does without the outline option. The package manual briefly describes how to switch between the "copy" and the "outline" mode. You can use "outline" for most of your labels, and switch to the "copy" mode for the labels for which the outline mode does not work. Commented Jan 14, 2011 at 20:05
  • Thanks Yiannis and Jan. It looks like switching between copy and outline is indeed what I will have to do. Frustrating to have to resort to the "poor man's bold" when the proper thing is almost within reach.
    – Jake
    Commented Jan 16, 2011 at 21:21
  • 1
    One can create a macro that lets them switch between the two modes seamlessly: \makeatletter\newcommand{\contourCopy}[2]{\con@outlinefalse\contour*{#1}{#2}\con@outlinetrue}\makeatother, using 32 copies as default.
    – Atcold
    Commented Apr 18, 2023 at 21:24
3

If you can use ConTeXt to draw the labels (depends on how the figure is generated), then you can access the path of the label in metapost and manipulate it as you want. For example, look at the metafun manual, section 8.6 (in particular pages 367 and 369.

4
  • Can LuaTeX typeset into memory? What I mean is can you make LuaTeX to create a pdf output of a piece of TeX code in memory, and hand it over to Lua which would then process it further? Commented Jan 12, 2011 at 1:37
  • I have no experience at all with ConTeXt, but it sounds interesting. The figures are generated with PgfPlots, the labels are Tikz nodes. I compile my documents with LuaLaTeX because of memory issues with complex plots.
    – Jake
    Commented Jan 12, 2011 at 15:07
  • @Jake: Tikz is compatible with context, but I do not know about pgfplots. It should be possible to create the labels by metapost as a node in tikz. But I cannot get a minimal example to work. The graphictext macro relies on pstoedit to convert the pdf file to a metapost path...and on my computer the generated metapost file is invalid. I don't really know how to debug pstoedit.
    – Aditya
    Commented Jan 13, 2011 at 6:05
  • @Jan Hlavacek: AFAIU, it is not possible to manipulate PDF output with Lua; but you can intercept the TeX node list before boxes are shipped out to pdf, manipulate the node list, and continue with the shipout.
    – Aditya
    Commented Jan 13, 2011 at 6:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .