# TikZ: Bend text that has macros e.g., superscripts

I am a new TikZ user and I started using the package to create FSMs. It all worked fine until I came across the issue of naming edges that are bent.

There is a relevant question for text on edges here. But when I try to adapt it to my problem, namely to use it as

\documentclass{article}

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

\begin{document}

\begin{tikzpicture}

\node (One) at (-3,0) [shape=circle,draw] {$One$};
\node (Two) at ( 3,0) [shape=circle,draw] {$Two$};

\def\myshift#1{\raisebox{-2.5ex}}
\draw [->,
thick,
postaction={decorate,
decoration={text along path,
text align=center,
text={|\sffamily\myshift|SUPERSCRIPT^{TEST}}
}
}
] (One) to [bend right=45]  (Two);

\end{tikzpicture}

\end{document}



It will not work. The SUPERSCRIPT^{TEST} causes an error. And I have not found a way to use text that has no superscripts in that way. Is there a work-around for this?

You're trying to use ^ which is a math mode command in text mode which is why you get the error. If you want to superscript regular text, you should use \textsuperscript instead of ^. Inside the text argument of the decoration, however, the macro needs to be protected with {...}. You are also missing the \end{tikzpicture} line. So the following works.

Also, the \myshift macro from the original answer isn't needed; instead you can use the raise key inside the decoration.

\documentclass{article}

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

\begin{document}

\begin{tikzpicture}
\node (One) at (-3,0) [shape=circle,draw] {$One$};
\node (Two) at (3,0) [shape=circle,draw] {$Two$};
\draw [->,thick,postaction={decorate,decoration={text along path,
text align=center,raise=-2.5ex,
text={|\sffamily|SUPERSCRIPT{\textsuperscript{TEST}}}}}]
(One) to [bend right=45]  (Two);
\end{tikzpicture}
\end{document}


This is not a perfect solution, since the material you put in the {...} will be treated as a single unit with respect to the path, and if it is long, you will get very unwelcome results:

\documentclass{article}

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

\begin{document}

\begin{tikzpicture}
\node (One) at (-3,0) [shape=circle,draw] {$One$};
\node (Two) at (3,0) [shape=circle,draw] {$Two$};
\def\myshift#1{\raisebox{-2.5ex}}
\draw [->,thick,postaction={decorate,decoration={text along path,
text align=center,raise=-2.5ex,
text={|\sffamily|SUPERSCRIPT{\textsuperscript{REALLY LONG TEST}}}}}]
(One) to [bend right=45]  (Two);
\end{tikzpicture}
\end{document}


The defined but not used macro \myshift gave me an idea to come away from \textsuperscript und change the font size and amount of "raise" in the middle of the given text. I must admit that I guessed the difference, so it is probably not the best possible answer:

\documentclass{article}

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

\begin{document}

\begin{tikzpicture}
\node (One) at (-3,0) [shape=circle,draw] {$One$};
\node (Two) at (3,0) [shape=circle,draw] {$Two$};
\def\myshift#1{\raisebox{-2.5ex}}
\draw [->,thick,postaction={decorate,decoration={text along path,
text align=center,raise=-2.5ex,
text={|\sffamily|SUPERSCRIPT{\textsuperscript{REALLY LONG TEST}}}}}]
(One) to [bend right=45]  (Two);
\end{tikzpicture}

Alternative:
\bigskip

\begin{tikzpicture}
\node (One) at (-3,0) [shape=circle,draw] {$One$};
\node (Two) at (3,0) [shape=circle,draw] {$Two$};
\def\myshift#1{\raisebox{1.5ex}}
\draw [->,thick,postaction={decorate,decoration={text along path,
text align=center,raise=-2.5ex,
text={|\sffamily|SUPERSCRIPT\ |\sffamily\tiny\myshift|REALLY LONG TEST}}}]
(One) to [bend right=45]  (Two);
\end{tikzpicture}

\end{document}