6

In contour package, the macro \con@put is defined as:

\newcommand*\con@put[3]{%
  \rlap{\hskip#1\raisebox{#2}[0pt]{#3}}%
}

But if one changes that \rlap to \llap, then you no longer get contour. For instance, try

\documentclass{article}
\usepackage{contour}
\makeatletter
\renewcommand*\con@put[3]{%
  \llap{\hskip#1\raisebox{#2}[0pt]{#3}}%
}
\makeatother
\begin{document}
\colorbox{black}{This text is not visible
\contour{white}{but this is.}}
\end{document}

This is what you get:

enter image description here

Why this does not work? What is the special effect of that \rlap that makes contour? and if one decides to go with \llap instead \rlap in the example above, what changes are required so you still get contour?

  • \llap would print the box on the wrong side. – egreg Jul 12 '14 at 15:25
5

Package contour sets the text many times: First the text is set in the specified color several times, slightly moved horizontally and vertically. Then the "inner" part is printed in black. The result is a "contour" in the specified color. Changing the background color makes it a little visible:

\documentclass{article}
\usepackage{contour}
\begin{document}
\colorbox{red}{This text is not visible
\contour{white}{but this is.}}
\end{document}

Result

The default of package contour is to put 16 copies in the specified color first. The star form uses 32 copies, or the number of copies can be specified in the optional argument of \contour.

Changing \rlap to \llap puts the first text prints to the left instead to the right. The final text in black is put to the right, invisible with black background. Again with changed background to red:

\documentclass{article}
\usepackage{contour}
\makeatletter
\renewcommand*\con@put[3]{%
  \llap{\hskip#1\raisebox{#2}[0pt]{#3}}%
}
\makeatother
\begin{document}
\colorbox{red}{This text is not visible
\contour{white}{but this is.}}
\end{document}

Result \llap


Just for fun: An alternative to contour is package pdfrender, which can set the contour using PDF features of vector fonts:

\documentclass{article}
\usepackage{pdfrender}
\usepackage{color}
\begin{document}
\colorbox{black}{This text is not visible
\textpdfrender{
  TextRenderingMode=Stroke,
  StrokeColor=white,
  LineWidth=.25pt,
}{but this is.}}

\colorbox{red}{This text is not visible
\textpdfrender{
  TextRenderingMode=FillStroke,
  FillColor=red,
  StrokeColor=white,
  LineWidth=.25pt,
}{but this is.}}
\end{document}

Result pdfrender

Also package contour can use this PDF feature, if option package option outlines is given. Then \con@put is not used.

| improve this answer | |
  • pdfrender does not work with xetex. If you are using \pdfliteral primitive of PDFTeX for this, then you can use \special{pdf:code ...} for dvipdfmx driver. – user56799 Jul 13 '14 at 12:51
0

Using Heiko's explanation, the answer to my last question would be:

\documentclass{article}
\usepackage{contour}
\makeatletter
\renewcommand*\con@put[3]{%
  \llap{\raisebox{#2}[0pt]{#3}\hskip-\dimexpr\wd0+#1\relax}%
}
\makeatother
\begin{document}
\setbox0\hbox{but this is.}

\colorbox{black}{This text is not visible
\contour{white}{but this is.}}
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy