10

I was going to write along an arc some math expression with curly brackets. Somehow the following snippet causes pdflatex to freeze.

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

\begin{document}

\begin{tikzpicture}

\draw[->,blue,
 postaction={decorate,decoration={text along path, raise=4pt,
  text={ $\{ hello \}${} },text color=blue,
 text align={align=center}}}] (0,5) arc (90:0:5);

\end{tikzpicture}

\end{document}

How can I do it otherwise?

1 Answer 1

16

One way to do is to use {$\lbrace$} and the corresponding {$\rbrace$}:

text={{$\lbrace$}hello{$\rbrace$}}

which yields:

enter image description here

Alternatively you could use:

text={{\textbraceleft}hello{\textbraceright}}

Notes:

  • Note the additional set of braces.

  • The TikZ/PGF manual states for text deocrations:

    • Each character in the text is typeset in a separate \hbox...

      ...

    • It is only possible to typeset text in math mode under considerable restrictions. Math mode is entered and exited using any character of category code 3 (e.g., in plain TEX this is $). Math subscripts and superscripts need to be contained within braces (e.g., {^y_i}) as do commands like \times or \cdot. However, even modestly complex mathematical typesetting is unlikely to be successful along a path (or even desirable).

Code:

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

\begin{document}

\begin{tikzpicture}

\draw[->,blue,
 postaction={decorate,decoration={text along path, raise=4pt,
  text={{$\lbrace$}hello{$\rbrace$}},text color=blue,
 text align={align=center}}}] (0,5) arc (90:0:5);

\end{tikzpicture}

\end{document}

Bizarre Behavior:

Using text={$hello$}, I get:

enter image description here

5
  • 4
    I noticed that bizarre behavior too. You can prevent it by adding {} after $.
    – mlt
    Commented Oct 4, 2012 at 6:42
  • @mlt Thanks, I was currently stuck with that same problem. Has this ever been reported as a bug in TikZ? Commented Mar 2, 2015 at 15:51
  • 3
    Also worth noting: if you want to use a macro inside the math text (within the decoration), you will need an extra pair of brackets encompassing that macro. For example: decoration={text along path, text align=center, text={${\overline{s}}${}}, raise=18pt} Commented Mar 2, 2015 at 16:05
  • 1
    Another note on the bizarre behavior: adding a subscript to the math can throw an error (e.g. {$T_r${}}). Instead, try: {{$T_r$}{}}. Commented Apr 19, 2017 at 8:00
  • @RicoPicone: Interesting. Seems that using math mode is a real issue, but at least there are workarounds that allow you to achieve the desired functionality. Commented Apr 19, 2017 at 8:10

You must log in to answer this question.

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