7

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?

  • In its current form, your question might not receive many answers. Please take a look at the How to Ask-page and try to improve your question according to the guidance found there. This may require you to show some effort on your part in terms of attempting a solution. If you have questions about what to do or if you don't quite understand what this means, please ask for clarification using the add comment function. – jub0bs Apr 15 '13 at 15:26
  • Answer might be difficult but I think the question is simple and clear. I can only add an example of outlined and shaded text, although I think it does not add any information. – mmj Apr 15 '13 at 15:32
  • Have you seen this : tex.stackexchange.com/questions/5959/… ? – percusse Apr 15 '13 at 15:35
  • @percusse Yes, but I'm interested only in outlined and shaded text. For other types of highlighting multiline wrapping works. – mmj Apr 15 '13 at 15:38
  • I think what percusse is saying is that the solution to the linked question could be adapted to this question. – Matthew Leingang Apr 15 '13 at 15:41
14

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

  • Wonderful, exactly what I was looking for, and pdflatex compiles it as I need. Thanks! Hope someone comes out with a solution for shaded text too. – mmj Apr 15 '13 at 16:31
5

it cannot have a pagebreak and works only with latex->dvips->ps2pdf. XeTeX cannot handle blurred shadows:

\documentclass[a5paper]{article}
\usepackage{pst-text,pst-blur}
\usepackage{lipsum}
\begin{document}
\pscharpath[shadow,blur]{%
  \parbox{\linewidth}{%
    \section{foo}
    \large\lipsum[2]}}
\end{document}

or for pdflatex --shell-escape use

\documentclass[a5paper]{article}
\usepackage[pdf]{pstricks}% for pdflatex --shell-escape
\usepackage{pst-text,pst-blur}
\usepackage{lipsum}
\begin{document}
\begin{postscript}% for pdflatex --shell-escape
\pscharpath[shadow,blur]{%
  \parbox{\linewidth}{%
    \section{foo}
    \large\lipsum[2]}}
\end{postscript}% for pdflatex --shell-escape
\end{document}

enter image description here

  • I currently compile using pdflatex, since I'm not an expert can you explain me better the steps I need to take to use your solution? – mmj Apr 19 '13 at 17:38
  • see my edit. The second example can be run with pdflatex --shell-escape <file>. But it takes some time to run. – user2478 Apr 19 '13 at 17:58
  • Nice one, it works (almost) great, but I have still some issues, the biggest one seems to be an incompatibility with babel package, see my follow up in the question. – mmj Apr 19 '13 at 23:29
  • that looks like a problem with the italian language and the defined shorthand of " – user2478 Apr 20 '13 at 6:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.