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

antshar
  • 4,238
  • 9
  • 30
  • 1
    You could try tikz shadow or contour package. https://tex.stackexchange.com/questions/227375/why-cant-contour-text-along-curve-path – rakatex May 23 '20 at 21:05
  • @rakatex could you tell more about shadows tiks library? – antshar May 23 '20 at 21:26
  • This link might be of good help to you. https://tex.stackexchange.com/questions/184897/tikz-better-raised-text-effect – rakatex May 23 '20 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 May 23 '20 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 – Kochise Oct 16 '20 at 16:23

2 Answers2

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

rakatex
  • 489
  • 2
  • 13
  • @Schrödinger's cat, yes. I have edited the answer. – rakatex May 23 '20 at 21:26
  • @Schrödinger's cat, sometimes its not working without decorations.text. Could you tell me why? – rakatex May 23 '20 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 May 23 '20 at 21:43
  • 2
    Just add it as an alternative to your answer, if you like. –  May 23 '20 at 21:44
  • How to do that, I edit my answer? – rakatex May 23 '20 at 21:46
  • 1
    I just added it. Then you do not need to reintroduce the line breaks. –  May 23 '20 at 21:48
  • @Schrödinger'scat change the text "Some text" to "Text" – rakatex May 23 '20 at 21:50
  • @Schrödinger'scat Since the arrow is just a glyph, maybe this question is related to q/543952 – Symbol 1 May 24 '20 at 06:45
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}

Symbol 1
  • 36,855
  • 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. –  May 24 '20 at 06: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 May 24 '20 at 06: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! –  May 24 '20 at 06: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 May 24 '20 at 06:55
  • copy shadow is O(m). Glowing by varying line width is O(n). Combining copy shadow and varying line width is O(mn). The hight complexity keeps m and n small, which is bad. The triangulation trick is the worst because it alone is O(mn). I only do them for the mere possibility. – Symbol 1 May 24 '20 at 07:03
  • But why do you need both? Isn't contour just a large number of copy shadows in TikZ terminology? (Things which do not look great according to my experience are e.g. spirals with varying distances between the lines.) –  May 24 '20 at 07:05
  • contour is not a large number of copy shadow in this answer. Notice the 1 Tr command. This pdf literal draws the glyph (treated as bezier curves) instead of filling it. – Symbol 1 May 24 '20 at 07:09
  • Yes, that's a fair point. –  May 24 '20 at 07:10
  • This is great. I'm a year late here, but is there any way to turn this into a TikZ command? – geodude Jun 03 '21 at 23:06
  • @geodude I hope so! But it what way you want to use it? Make any node text glowing? – Symbol 1 Jun 04 '21 at 00:57
  • yes, exactly. It would be nice to have a compact command that does it. – geodude Jun 04 '21 at 08:32
  • 1
    @geodude Like this? https://gist.github.com/Symbol1/625d06d848c441c28d3053e975172d5d – Symbol 1 Jun 04 '21 at 18:13
  • Yes, very nice! – geodude Jun 05 '21 at 11:54