# Understanding what contour package does

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:

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

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}


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}


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}


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

-
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

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}

-
What would be the advantage of so doing? –  egreg Jul 12 '14 at 16:43
Did you see this answer? tex.stackexchange.com/a/64759/4427 If you're interested into understanding \rlap and \llap it's very good. –  egreg Jul 12 '14 at 17:03
@egreq: I know what \rlap and \llap does. I was just confused because of the strange behavior of e-tex; please see tex.stackexchange.com/questions/191222/… –  user56799 Jul 13 '14 at 3:41