The solutions from Peter Grill and egreg and jofel involve turning off onlyamsmath
s checking in either a tikzpicture
(Peter Grill and egreg) environment or the whole document (jofel). However, assuming that one wants to use the full capability of onlyamsmath
in the entire document, none of these solutions is quite right.
The problem is that onlyamsmath
changes the catcode of $
at \begin{document}
. So when TikZ is loaded it doesn't know that $
will change its catcode later and so merrily sets up stuff matching $
with its current catcode, namely 3.
Now, because TikZ relies a lot on special symbols (;
is only the start of it), it generally is quite robust against catcode changes. If you look at the source of tikz.code.tex
you'll see a lot of \ifnum\catcode`\;=\active
and similar (robust but not steadfast: it only checks for a change between whatever-was-in-use-at-load-time and active). It doesn't do this for $
, though. Perhaps it should. One possibility would be to add the necessary checks. This wouldn't be hard since, despite egreg's assertion, $
s are not heavily used in TikZ so there would only need to be a few changes made. However, a quicker alternative is to ensure that the right catcode is in place when TikZ is loaded. This can be done with:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\edef\dolcat{\the\catcode`\$}
\catcode`\$=13
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\catcode`\$=\dolcat\relax
\usepackage[all,warning]{onlyamsmath}
\begin{document}
\begin{tikzpicture}
\node (node1) [] {Box 2 text};
\node (node2) [right=of node1] {Box 3 text};
\draw[->] (node2.north) -- ++(0,0.5) -| ($ (node1.east) + (0.25,0)
$);
\end{tikzpicture}
\end{document}
which works with your MWE and also complains about $$
in TikZ nodes.
(Whilst I agree with egreg about the necessity of onlyamsmath
there are plenty of packages that mess with catcodes of symbols of significance and I think that adjusting TikZ - or faking it - to play nicely is the better route to take when conflicts arise.)
\documentclass
so that those trying to help don't have to recreate it.