Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use the code provided in this question to draw a text spiral and now I want to highlight each chunk separated with a comma in a different color. Is there a way to achieve that?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}

\makeatletter

\let\pgf@lib@dec@text@dobox@original=\pgf@lib@dec@text@dobox%

\def\pgf@lib@dec@text@dobox{%
    \pgf@lib@dec@text@dobox@original%
    \ifpgfdecorationtextalongpathscaletext%
    \pgfmathparse{\pgf@lib@dec@text@endscale+(\pgf@lib@dec@text@startscale-\pgf@lib@dec@text@endscale)*\pgfdecoratedremainingdistance/\pgfdecoratedpathlength}%
    \setbox\pgf@lib@dec@text@box=\hbox{\scalebox{\pgfmathresult}{\box\pgf@lib@dec@text@box}}%
    \fi%
}
\newif\ifpgfdecorationtextalongpathscaletext
\def\pgf@lib@dec@text@startscale{1}
\def\pgf@lib@dec@text@endscale{1}

\pgfkeys{/pgf/decoration/.cd,
    text path start scale/.code={%
        \pgfdecorationtextalongpathscaletexttrue%
        \def\pgf@lib@dec@text@startscale{#1}%
    },
    text path end scale/.code={%
        \pgfdecorationtextalongpathscaletexttrue%
        \def\pgf@lib@dec@text@endscale{#1}%
    }
}
\begin{document}    
\begin{tikzpicture}[
    decoration={
    reverse path,
    text along path,
    text path start scale=1.5,
    text path end scale=0,
    text={Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua, 
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
    nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
    reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
    pariatur, Excepteur sint occaecat cupidatat non proident, sunt
    inculpa qui officia deserunt mollit anim id est laborum}}
]
\draw [decorate] 
    (0,0) 
    \foreach \i [evaluate={\r=(\i/2000)^2;}] in {0,5,...,2880}{ -- (\i:\r)}; 
\useasboundingbox (-2.75,-2.75) rectangle (2.75,2.75); 
\end{tikzpicture}    
\end{document}

I could not find an image that I have in mind but something similar to the below diagram, but there should be also text in the color blocks. I do not care about the arrow like decoration.

share|improve this question
add comment

1 Answer 1

up vote 11 down vote accepted

I'm not sure I understood the question but this does something with commas and colours enter image description here

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text}

\makeatletter

\def\zr{red}
\def\zy{yellow}
\def\zcomma{,}
\let\z\zr
\let\pgf@lib@dec@text@dobox@original=\pgf@lib@dec@text@dobox%

\def\pgf@lib@dec@text@dobox{%
\ifx\zcomma\pgf@lib@dec@text@char
\ifx\z\zr\let\z\zy\else\let\z\zr\fi
\fi
    \pgf@lib@dec@text@dobox@original%
    \ifpgfdecorationtextalongpathscaletext%
    \pgfmathparse{\pgf@lib@dec@text@endscale+(\pgf@lib@dec@text@startscale-\pgf@lib@dec@text@endscale)*\pgfdecoratedremainingdistance/\pgfdecoratedpathlength}%
    \setbox\pgf@lib@dec@text@box=\hbox{\scalebox{\pgfmathresult}{\fboxsep\z@\colorbox{\z}{\box\pgf@lib@dec@text@box}}}%
    \fi%
}
\newif\ifpgfdecorationtextalongpathscaletext
\def\pgf@lib@dec@text@startscale{1}
\def\pgf@lib@dec@text@endscale{1}

\pgfkeys{/pgf/decoration/.cd,
    text path start scale/.code={%
        \pgfdecorationtextalongpathscaletexttrue%
        \def\pgf@lib@dec@text@startscale{#1}%
    },
    text path end scale/.code={%
        \pgfdecorationtextalongpathscaletexttrue%
        \def\pgf@lib@dec@text@endscale{#1}%
    }
}
\begin{document}    
\begin{tikzpicture}[
    decoration={
    reverse path,
    text along path,
    text path start scale=1.5,
    text path end scale=0,
    text={Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua, 
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
    nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
    reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
    pariatur, Excepteur sint occaecat cupidatat non proident, sunt
    inculpa qui officia deserunt mollit anim id est laborum}}
]
\draw [decorate] 
    (0,0) 
    \foreach \i [evaluate={\r=(\i/2000)^2;}] in {0,5,...,2880}{ -- (\i:\r)}; 
\useasboundingbox (-2.75,-2.75) rectangle (2.75,2.75); 
\end{tikzpicture}    
\end{document}

You can smooth it off a bit with a strut and some kerns:

    \setbox\pgf@lib@dec@text@box=\hbox{\scalebox{\pgfmathresult}{\fboxsep\z@
\kern-.7pt\colorbox{\z}{\kern.7pt\strut\box\pgf@lib@dec@text@box\kern.7pt}\kern-.7pt}}%

enter image description here

share|improve this answer
    
This is very close but not exactly what i wanted. I mean to highlight in continuous blocks, that do not only follow the text but also provide smooth edges, if that makes sense, including the whitespaces. –  Basak Jan 27 '13 at 13:02
1  
I had another idea, but lack the skills to implement it. The idea is to draw the text without colored background and, when detecting the comma, store the value of \i in a list. Once the text has ben typeset, a double spiral is drawn in the background filled with a color which changes at the values of \i stored in the list. –  JLDiaz Jan 27 '13 at 14:58
    
Yay! another tikz answer! –  hpesoj626 Jan 28 '13 at 1:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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