[Tex/LaTex] How to get multiline outlined/shaded text in LaTeX

highlightingwrap

How can I get multiline text highlighted by means of outlining or shading? I found some solutions (contour, shadowtext, pdf-trans) but none able to wrap multiline text.

Some examples of outlined and shaded text:

enter image description here

enter image description here

OUTLINED TEXT FOLLOW UP

See below for solution.

SHADED TEXT FOLLOW UP (STILL SEEKING FOR A DEFINITIVE SOLUTION)

Possible solution #1

A promising solution for people like me compiling with pdflatex (and -shell-escape option) looks this one (MWE adapted from Herbert's nice answer, here implementing a user-defined shadetext command):

\documentclass[a5paper]{article}

\usepackage[pdf]{pstricks}
\usepackage{pst-text,pst-blur}

\newcommand{\shadetext}[1]{% compile with pdflatex -shell-escape
\begin{postscript}
\pscharpath[
      shadow=true,
      shadowsize=.1em,
      shadowangle=-40,
      shadowcolor=gray,
      fillstyle=solid,
      fillcolor=black,
      linestyle=none,
      linecolor=black,
      linewidth=0pt
]{\parbox{\linewidth}{#1}}
\end{postscript}
}

\begin{document}
\shadetext{Text to be shaded.} Unshaded text.
\end{document}

Such solution has multiline wrapping and hypenation too, but has got a major (at least for me) and a minor problem. The big problem is that it does not compile if you use the babel package (I have \usepackage[greek,italian]{babel} in my preamble), preventing you from using it altoghether. The small problem is that if you mix shaded and normal text, the result is far from perfect (and sometimes even messy, it depends on how you mix shaded and normal text):

enter image description here

Possible solution #2

I got somewhat closer to solution for shaded text, using shadowtext package and the following code (adapted from here) in the preamble, to automatically apply shadow (through newly defined command \wordshadow) to each single word of the argument ( is to be replaced by a space char):

\makeatletter
\def\wordshadow#1{\expandafter\wordshadow@i#1 \@nil}
\def\wordshadow@i#1 #2\@nil{%
  \shadowtext{#1}\␣
  \ifx\relax#2\relax\else\wordshadow@i#2\@nil\fi}
\makeatother

but the result, although better than no wrap at all, is not perfect, as you can see below:

enter image description here

Any clue?

Best Answer

Package pdfrender is able to "highlight" text (except for PK fonts) that can be broken across lines and even pages:

\documentclass[a5paper]{article}
\usepackage{xcolor}
\usepackage{pdfrender}
\usepackage{lipsum}
\begin{document}
\textpdfrender{
  TextRenderingMode=FillStroke,
  FillColor=red,
  LineWidth=.07ex,
}{\lipsum[2]}
\end{document}

Result