14

This problem occurs when I am trying to improve my answer in this question.


You can compile this code very well

\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text align=center,text={multiply by 100}}}] (a) to[out=60,in=120] (b);
\end{tikzpicture}
\end{document}

enter image description here

but don't compile this code!

\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text align=center,text={multiply by 100\%}}}] (a) to[out=60,in=120] (b);
\end{tikzpicture}
\end{document}

I have been waiting for more than 200 seconds

enter image description here

Why? I just want to add a percent symbol (\%)!

I think TikZ understood my \% as %, but removing the \ throws many errors.

I even used siunitx, but got the same result.

\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text align=center,text={multiply by \SI{100}{\percent}}}}] (a) to[out=60,in=120] (b);
\end{tikzpicture}
\end{document}

So, what's going on?

Dancrumb
  • 103
  • 1
    Very nice your 2nd image: How do I find the compilation time? Do you have any specific software where you can see the build time? My regards. – Sebastiano Mar 28 '19 at 16:22
  • @Sebastiano I use VS Code. The LaTeX Workshop extension gives me a link to see the compilation process, which I don't use really often, but it is very useful in strange situations, like this situation. –  Mar 28 '19 at 16:24
  • Is this :-)? https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop – Sebastiano Mar 28 '19 at 16:28
  • @Sebastiano Yes, that's it. –  Mar 28 '19 at 16:28
  • 2
    The infinite loop is triggered by any unexpandable control sequence token, even by \relax (except implicit character tokens that raise errors). Bracing the token is the right way to go. – egreg Mar 28 '19 at 17:03
  • A similar problem is described in https://tex.stackexchange.com/q/21589/4427 – egreg Mar 28 '19 at 21:13

2 Answers2

12

You can make this work by changing the % character to not be the comment character anymore using \catcode:

\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\begin{scope}
\catcode`\%=12
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text
align=center,text={multiply by 100%}}}] (a) to[out=60,in=120] (b);
\end{scope}
\end{tikzpicture}
\end{document}
Skillmon
  • 60,462
  • 1
    Thanks, it solved the problem. However, could you please add some explanation about why \% doesn't work? –  Mar 28 '19 at 16:07
  • 4
    @JouleV for that I'd have to dig through the internals of TikZ, which isn't something I feel like right now, sorry. – Skillmon Mar 28 '19 at 16:10
12

You only need to wrap \% into {...}.

\documentclass[tikz]{standalone}
\usetikzlibrary{bending,decorations.text}
\begin{document}
\begin{tikzpicture}
\sffamily
\node (a) at (-2,0) {probability};
\node[align=center] (b) at (2,0) {percent\\change};
\draw[-latex,postaction={decorate,decoration={raise=1ex,text along path,text
align=center,text={multiply by 100{\%}}}}] (a) to[out=60,in=120] (b);
\end{tikzpicture}
\end{document}

enter image description here