29

How could I produce characters which are outlined when the character itself is in some color. A picture to illustrate what I'm after:
enter image description here

The problems with the above are that:

  • the outline is of no consistent width around the letter.
  • the way I've done it (using tikz with a upscaled black node below the colored one), there is no easy way to control the width of the outline.

Do you know of a way to accomplish this with TeX? I am using plain-format with XeTeX, but I'm interested in all ways to accomplish this.

morbusg
  • 25,490
  • 4
  • 81
  • 162

4 Answers4

28

The contour package can do this, too. You'll need to use Type 1 fonts (check the documentation); here is sample code

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{pslatex}
\usepackage{contour}
\usepackage{color}
\pagestyle{empty}
\begin{document}
\contourlength{2pt} %how thick each copy is
\contournumber{20}  %number of copies
\contour{red}{\Huge \textcolor{green}{This is the text.}}\\
\end{document}

The output is: enter image description here Changing the contourlength to 1pt will give a less pronounced outline.

David Carlisle
  • 757,742
DJP
  • 12,451
  • What did the log file say was the problem? – DJP Aug 11 '11 at 04:33
  • With a minimal: \input eplain \beginpackages\usepackage{contour}\endpackages bar\bye, I get: Undefined control sequence. \newlength – morbusg Aug 11 '11 at 05:05
  • When I put "minimal" into the documentclass, instead of "article" I get an "Undefined control sequence" error. It was fixed by removing "\Huge" from the code. If that doesn't work, maybe try to find a minimal example that doesn't work and repost as question? – DJP Aug 11 '11 at 05:35
  • Oh, right, so... There is the language TeX, and then there are macro-packages which build up on the primitives provided by the language: plain-tex, latex, and context, for example. I am using the plain-tex macro-package, for which there exists a macro-collection called eplain which allows loading some macro-packages designed to work with latex, to be loaded in plain-tex. I didn't realize you could load eplain with latex. – morbusg Aug 11 '11 at 06:04
  • You should specify \textcolor{}{} outside the contour, at least in Beamer. See http://tex.stackexchange.com/questions/78386/outlined-characters-in-beamer. – Mechanical snail Oct 23 '12 at 02:03
  • Very nice, but I don't get word wrap when applied to multiline text, am I missing something? – mmj Apr 15 '13 at 13:57
  • "Minimal" document class is designed for testing class loading dependencies: it defines page size and normal font size, and that's it, nothing else. It is not intended for Minimal Working Examples. For MWEs, use a normal class, like 'article', or whatever is relevant to the question. – Cicada Nov 16 '19 at 11:16
17

The pst-text package can do this.

\documentclass{minimal}
\usepackage{pst-text}
\DeclareFixedFont{\RM}{T1}{ptm}{b}{n}{2cm}

\begin{document}
  \pscharpath[fillstyle=solid,fillcolor=magenta!50]{\RM TeXnik}
\end{document}

Perhaps you can migrate this to plain (Xe)TeX.


enter image description here

15

Package pdfrender for pdfTeX or LuaTeX (newer versions require package luatex85) allows to configure the outline with many parameters as fill color, stroke color, or line width for stroking.

Because of pdfTeX's colorstacks, page breaks are supported as for color settings.

Example:

\documentclass[12pt]{article}
% \usepackage{luatex85} % for LuaTeX
\usepackage{xcolor}
\usepackage{pdfrender}
\definecolor{CharFillColor}{rgb}{1,.8,.8}
\begin{document}
  \sffamily
  \textpdfrender{
    TextRenderingMode=FillStroke,
    LineWidth=.2pt,
    FillColor=CharFillColor,
  }{Lorem ipsum.}
\end{document}

Result

Heiko Oberdiek
  • 271,626
  • I have found that for some fonts such as \usepackage{Oswald}, when outlining large bold characters some lines get "overdrawn", which I was able to solve by setting MiterLimit=1 reference image. No clue what it does tho, the option is not further explained in the package documentation. – Hyperplane Mar 25 '21 at 21:38
  • @Hyperplane "Miter Limit" is explained in the PDF reference, see section "Details of Graphics State Parameters". – Heiko Oberdiek Mar 26 '21 at 18:27
10

Some years later, in a file I found called “Practical use of special commands in DVIPDFMx” by Jin-Hwan Cho (TUG2005), I found information on the low-level PDF command for use with dvipdfmx:

\special{pdf:bcolor [.8 0 .8] [0]} % two arrays: first defines fill, second the stroke.
% If array has one entry, it's meaning grayscale, if three: RGB, if four: CMYK.
\special{pdf:literal direct .4 w 2 Tr} % .4 here is the stroke width
F
\bye

enter image description here

cfr
  • 198,882
morbusg
  • 25,490
  • 4
  • 81
  • 162
  • Do you know any good resources where I can learn more about these PDF literals? – Henri Menke Jan 30 '15 at 13:45
  • 1
    @Henri: You can find the document I'm talking about in the answer here, and for the PDF reference, you can see here. I think I also remember some talks related to PStricks which also cover some of the PDF subset, but I don't have any links for you now; sorry. – morbusg Jan 30 '15 at 17:38