7

I'd like to achieve such a result, like when you apply a glowing effect to a text in an image editor. enter image description here


As I am already using tikz package in my document, it would be prefferable to use tikz's library.

I found out, that there is a shadows.blur one which would create a soft shadow. Then I would shift it so that it looks like a glowing effect.

However, unfortunately, this attempt makes a rectangle rather than the text's shadow.

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\begin{document}

\begin{tikzpicture}
\node[preaction={blur shadow={shadow xshift=-.5mm,shadow yshift=.5mm}}] at (1,1) {Test};
\end{tikzpicture}

\end{document}

enter image description here

5
  • 1
    You could try tikz shadow or contour package. tex.stackexchange.com/questions/227375/…
    – rakatex
    Commented May 23, 2020 at 21:05
  • @rakatex could you tell more about shadows tiks library?
    – antshar
    Commented May 23, 2020 at 21:26
  • This link might be of good help to you. tex.stackexchange.com/questions/184897/…
    – rakatex
    Commented May 23, 2020 at 21:28
  • @rakatex unfortunately, the author attaches the image with the desired smooth shadow, but doesn't provide the code and asks rather about embossing.
    – antshar
    Commented May 23, 2020 at 21:34
  • Is there a way to do it also on pictures ? In Word, I can insert a picture, say a PNG with alpha layer, right click, Format Picture..., Effects (pentagon), Glow (presets), it will follow the contour of the picture (orange) not just create a rectangle around it (green). ![enter image description here](i.sstatic.net/dI63h.png)
    – Kochise
    Commented Oct 16, 2020 at 16:23

2 Answers 2

14

You could use a combination of tikz and contour package.

\documentclass[12pt,border=12pt]{standalone}
\usepackage[outline]{contour}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\def\mycontour#1{\textcolor{black}{\contour{green!20}{#1}}}
\node (1) at (0cm, 0cm) {};
\node (2) at (2cm,0cm) {};   
\draw[
decoration={text effects along path,
text={Text},
text align=center,
text effects/.cd,
text along path, scale text to path,
characters={font=\Huge,character command=\mycontour},
},decorate,
]  (1) to (2);
\end{tikzpicture}
\end{document}

or just

\documentclass{article}
\usepackage{xcolor}
\usepackage[outline]{contour}
\contourlength{1pt}
\contournumber{27}
\newcommand{\mycontour}[2][green!20]{\textcolor{black}{\contour{#1}{#2}}}
\begin{document}
\Huge\mycontour{Text}
\end{document}

enter image description here

8
  • @Schrödinger's cat, yes. I have edited the answer.
    – rakatex
    Commented May 23, 2020 at 21:26
  • @Schrödinger's cat, sometimes its not working without decorations.text. Could you tell me why?
    – rakatex
    Commented May 23, 2020 at 21:32
  • @Schrödinger'scat yes, your code is more simpler and straightforward. \documentclass[12pt,border=12pt]{standalone} \usepackage{xcolor} \usepackage[outline]{contour} \newcommand{\mycontour}[2][green!20]{\textcolor{black}{\contour{#1}{#2}}} \begin{document} \Huge\mycontour{Text} \end{document}
    – rakatex
    Commented May 23, 2020 at 21:43
  • 2
    Just add it as an alternative to your answer, if you like.
    – user194703
    Commented May 23, 2020 at 21:44
  • 1
    I just added it. Then you do not need to reintroduce the line breaks.
    – user194703
    Commented May 23, 2020 at 21:48
9

Just one step further from the previous answer. This one uses the idea of Faded or blurred lines

\documentclass{article}
\usepackage{tikz}
\usepackage[outline]{contour}

\begin{document}

\Huge

Assume pdf\TeX

\def\exText{LIPSUM}

\makeatletter

    Reverse engineer the contour package.

    Here is an MWE
    \leavevmode
    \begingroup
        \color{green}%
        \con@coloroff
        \pdfliteral{%
            q % enter a scope
            1 j % Set line join style
            1 J % Set line cap style
            1 Tr % Set text rendering mode
            2.5 w % Set line width (in PostScript Point)
        }%
        \rlap{\exText}%
        \pdfliteral{%
            Q % leave the scope
        }%
    \endgroup
    \mbox{\exText}


    Now use TikZ.
    \leavevmode
    \pgfsys@beginscope% = pdf literal q
    \pgfsetroundjoin% = 1 J
    \pgfsetroundcap% = 1 j
    \pdfliteral{1 Tr}% no pgf alternative
    \foreach\ind in{10,...,1}{%
        \pgfmathsetmacro\per{(11-\ind)*5}%
        \color{green!\per}%
        \pgfsetlinewidth{\ind/2}%
        \rlap{\exText}%
    }%
    \pgfsys@endscope % = pdf literal Q
    \exText

\makeatother

\end{document}

13
  • Maybe, maybe not. I think that one can use the trick of superimposing relatively shifted characters for the contour, but there will be limits. I played some time ago with copy shadow and the problem was that it depends on the path whether it looks good. But yes, for these characters the results are good.
    – user194703
    Commented May 24, 2020 at 6:49
  • @Schrödinger'scat Also try this ``` Right arrows? \def\exText{$\rightarrow\Rightarrow$} \pdfliteral{q 1 j 1 J 1 Tr}\foreach\per in{5,10,...,50}{\color{green!\per}\pgfsetlinewidth{(50-\per)/10}\rlap{\exText}}\pdfliteral{Q}\exText ```
    – Symbol 1
    Commented May 24, 2020 at 6:52
  • I am always wondering why it is that asymptote and pstricks can access the path of glyphs but TikZ has such a hard time. I know your nice solutions of "decomposing the world in triangles" but I am always hoping that one day TikZ will know what the path for a glyph for an A, say, of a given point is. And as for your last point, can't one use copy shadow to do that for an arbitrary content? But yes, it looks good!
    – user194703
    Commented May 24, 2020 at 6:53
  • I have no idea why pstricks has access to so much things, this and z-sorting of 3D objects. Asymptote can do more because it's standalone. But pstricks...? I don't understand.
    – Symbol 1
    Commented May 24, 2020 at 6:55
  • 1
    @geodude Like this? gist.github.com/Symbol1/625d06d848c441c28d3053e975172d5d
    – Symbol 1
    Commented Jun 4, 2021 at 18:13

You must log in to answer this question.

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