# TikzPicture error: Missing $inserted I have a code that works on another computer, and on another it is prompting an error: Missing$ inserted. };

This is the .tex :

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}[grow=right]
\node {}
child [sibling distance=20ex] { node {T}
child [sibling distance=10ex] { node {T}
child [sibling distance=5ex]
{ node [anchor=west] { T $\cdots$ (T,T,T)\; $p = \frac{1}{8}$ } }
child [sibling distance=5ex]
{ node [anchor=west] { H $\cdots$ (T,T,H)\; $p = \frac{1}{8}$ } }
}
child [sibling distance=10ex] { node {H}
child [sibling distance=5ex]
{ node [anchor=west] { T $\cdots$ (T,H,T)\; $p = \frac{1}{8}$ } }
child [sibling distance=5ex]
{ node [anchor=west] { H $\cdots$ (T,H,H)\; $p = \frac{1}{8}$ } }
}
}
child [sibling distance=20ex] { node {H}
child [sibling distance=10ex] { node {T}
child [sibling distance=5ex]
{ node [anchor=west] { T $\cdots$ (H,T,T)\; $p = \frac{1}{8}$ } }
child [sibling distance=5ex]
{ node [anchor=west] { H $\cdots$ (H,T,H)\; $p = \frac{1}{8}$ } }
}
child [sibling distance=10ex] { node {H}
child [sibling distance=5ex]
{ node [anchor=west] { T $\cdots$ (H,H,T)\; $p = \frac{1}{8}$ } }
child [sibling distance=5ex]
{ node [anchor=west] { H $\cdots$ (H,H,H)\; $p = \frac{1}{8}$ } }
}
};
\end{tikzpicture}

\end{document}



I get this from a TikzPictures package in Julia to create probability outcome graph. But it can't work in either Julia or LaTeX.

What is the problem with this tex code? On another computer it is working.

• Can you show your .log file? Feb 16 at 12:41
• Works ok in a current TeXLive. So probably a package missing/too old; also probably the error you cite is not the first one (which is the only one that makes sense). Try to report the log part where you have the first error, literally... Feb 16 at 12:41
• Works fine on current MikTex, as pfdlatex, Lualatex, Xelatex. // Nice drawing BTW. Feb 16 at 12:46
• I'd guess that the \; cause this, iirc, those weren't always defined for text mode. Feb 16 at 12:47
• The problem is my old version of LaTex. I have a hardtime using CAELinux to update the LaTex. Thanks that @Skillmon pointed this out. Feb 19 at 5:39

The culprit is most likely \; used in text mode.

See ltnews32 "Spacing commands moved from amsmath to the kernel", this change happened in 2020-10, so I'd guess your LaTeX installation is older than that. Use \usepackage{amsmath} in your preamble to make your code work on the old installation.

• Yes, I asked at Julia Discourse, the tex is produced from Julia using TIkzPictures.jl but it can't produce the pdf. Turns out you are right. Amazing! Thanks a lot. Hopefully you will have a great wealth, abundance, happiness and health for helping others in need!!! Feb 17 at 13:55

Edit:

However,

• I would move all determination for sibling distances and nodes' anchor settings to tikzpicture options,
• remove additional distances \; between terms in parenthesis and probability values. They not contribute much to those distances, but may at older LaTeX installation, as noted @Skillmon in his comment, cause problems.
• If for some reasons this distance is important and you are not able to upgrade LaTeX installation, move \; in math environment. For example:
{ node {T $\cdots$ (H,H,T) $\;p=\frac{1}{8}$ } }


By this changes the code of the tree becomes much shorter and the tree is still looks nice:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}[
every node/.style = {anchor=west},
level 1/.style = {sibling distance=20ex},
level 2/.style = {sibling distance=10ex},
level 3/.style = {sibling distance=5ex},
grow=right
]
\node {}
child { node {T}
child  { node {T}
child { node { T $\cdots$ (T,T,T)  $p = \frac{1}{8}$ } }
child { node { H $\cdots$ (T,T,H)  $p = \frac{1}{8}$ } }
}
child  { node {H}
child { node { T $\cdots$ (T,H,T)  $p = \frac{1}{8}$ } }
child { node { H $\cdots$ (T,H,H)  $p = \frac{1}{8}$ } }
}
}
child { node {H}
child  { node {T}
child { node { T $\cdots$ (H,T,T)  $p = \frac{1}{8}$ } }
child { node { H $\cdots$ (H,T,H)  $p = \frac{1}{8}$ } }
}
child  { node {H}
child { node { T $\cdots$ (H,H,T) $p = \frac{1}{8}$ } }
child { node { H $\cdots$ (H,H,H) $p = \frac{1}{8}$ } }
}
};
\end{tikzpicture}
\end{document} However, I would rather use forest package for drawing this tree. It is powerful package
specialized for drawing trees. Its code syntax enable to write very concise and clear code:

\documentclass[margin=3mm]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
for tree = {
inner sep = 2pt,
child anchor = west,
grow  = east,
l sep = 7 mm,
s sep = 4 mm,
where level = 2{s sep=0mm}{}  % insert different s sep
% at level 2, which then appear
% after each second node in the
% end of the tree
}
[
[T
[T
[{T $\cdots$ (T,T,T)  $p = \frac{1}{8}$}]
[{H $\cdots$ (T,T,H)  $p = \frac{1}{8}$}]
]
[H
[{T $\cdots$ (T,H,T)  $p = \frac{1}{8}$}]
[{H $\cdots$ (T,H,H)  $p = \frac{1}{8}$}]
]
]
[H
[T
[{T $\cdots$ (H,T,T)  $p = \frac{1}{8}$}]
[{H $\cdots$ (H,T,H)  $p = \frac{1}{8}$}]
]
[H
[{T $\cdots$ (H,H,T) $p = \frac{1}{8}$}]
[{H $\cdots$ (H,H,H) $p = \frac{1}{8}$}]
]
]
];
\end{forest}
\end{document} 