3

I have this MWE which work fine with pdflatex

\documentclass[border=3mm]{standalone}
\usepackage{xcolor}
\usepackage[outline]{contour}
\contourlength{1.2pt}

\pagecolor{blue!30}

\begin{document}

\contour{yellow}{\Huge This is a sample text}\par

\end{document}  

How can I do the same with xelatex?

enter image description here

2 Answers 2

5

Add packages 'bidicontour' and 'bidi' (in that order) and prefix the contour macros with 'bidi':

\documentclass[border=3mm]{standalone}
\usepackage{xcolor}
\usepackage{bidicontour}
\usepackage{bidi}

\bidicontourlength{1.2pt}
\pagecolor{blue!30}

\begin{document}
\bidicontour{yellow}{\Huge This is a sample text}\par
\end{document} 
0
3

This is not a solution, but a workaround.

It seems that what contour does is somewhat exclusive to pdf, and apparently XeTeX does not support that. e.g. this, this, and this.

Apparently the way to make contours in XeTeX is to use low-level pdf commands, like the ones showed in the answers linked above (P.S.: At the time I was writing this, remco proved otherwise. Anyway...).

I merged the solutions to a few other questions and made a macro that simulates the \contour:

\fillstroke{<fill color>}{<contour color>}{<stroke width>}{<text>}

where <fill color> and <contour color> are valid color names, <stroke width> is a number, NOT a dimension, so no units allowed, and <text> is the text (wow).

Here are the macros:

\usepackage{xcolor}
\def\rgbtoarray#1,#2,#3\null{[#1 #2 #3]}
\def\csvtoarray#1{%
  \expandafter\rgbtoarray#1\null%
}
\newcommand{\extractrgb}[2]{%
  \extractcolorspecs{#1}{\model}{\mycolor}%
  \convertcolorspec{\model}{\mycolor}{rgb}{\printcol}%
  \edef#2{\printcol}%
}
\newcommand*{\fillstroke}[4]{%
  \extractrgb{#1}{\colorvector}%
  \extractrgb{#2}{\strokevector}%
  \special{pdf:bcolor \csvtoarray{\colorvector} \csvtoarray{\strokevector}}%
  \special{pdf:literal direct #3 w 2 Tr}%
  #4%
  \special{pdf:ecolor}%
  \special{pdf:literal direct 0 Tr}%
}

The only required package is xcolor.

And here is your MWE:

\documentclass[border=3mm]{standalone}
\usepackage{xcolor}

\pagecolor{blue!30}

\def\rgbtoarray#1,#2,#3\null{[#1 #2 #3]}
\def\csvtoarray#1{%
  \expandafter\rgbtoarray#1\null%
}
\newcommand{\extractrgb}[2]{%
  \extractcolorspecs{#1}{\model}{\mycolor}%
  \convertcolorspec{\model}{\mycolor}{rgb}{\printcol}%
  \edef#2{\printcol}%
}
\newcommand*{\fillstroke}[4]{%
  \extractrgb{#1}{\colorvector}%
  \extractrgb{#2}{\strokevector}%
  \special{pdf:bcolor \csvtoarray{\colorvector} \csvtoarray{\strokevector}}%
  \special{pdf:literal direct #3 w 2 Tr}%
  #4%
  \special{pdf:ecolor}%
  \special{pdf:literal direct 0 Tr}%
}

\begin{document}

\fillstroke{black}{yellow}{0.5}{\Huge This is a sample text}\par

\end{document}

enter image description here

4
  • The outline produced are much nicer than those of the accepted answer. Maybe it just needs a font more adapted to the purpose, so that the outline can have a more uniform separation.
    – thymaro
    Mar 19, 2018 at 13:08
  • @thymaro One thing I noticed is that the outline produced by remco's answer produces an effect similar to setting a negative stroke width in my answer... Maybe the bidi package does something like this internally... Mar 19, 2018 at 13:14
  • I think bidicontour prints the (yellow) outline first, and then the 'normal' text on top of that (hint: comment out the bidi packageand ignore the errors). Which means that you add an outline around the normal glyphs. With the low-level pdf commands, it looks to me you print the outline of the normal glyphs in a colour, and fill the remaining space with (here) black.
    – remco
    Mar 19, 2018 at 13:19
  • @remco Yes. The contour method overlaps two slightly differently-sized copies of the text (with \rlap) and the PDF literal method works directly on the glyphs. (I did an experiment at tex.stackexchange.com/questions/464402/…).
    – Cicada
    Nov 17, 2019 at 10:03

You must log in to answer this question.

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