Conflict: onlyamsmath and TikZ

The two packages are indeed incompatible, as onlyamsmath changes $ into an active character in order to check whether $$...$$ is used.

This conflicts heavily with the workings of tikz. However, the things checked by the package are

eqnarray
eqnarray*
displaymath
$$

so it doesn't seem to be really necessary. However, the following code

\usepackage{etoolbox}
\preto\tikzpicture{\catcode`$=3 }
\preto\tikz{\catcode`$=3 }

inserted after loading TiKZ may solve the incompatibility.


You could adjust the catcode of the $ within the tikzpicture environment as follows:

\documentclass{article}
\usepackage[all,warning]{onlyamsmath}
\usepackage{tikz}
\usetikzlibrary{calc}

\makeatletter
\let\@@tikzpicture\tikzpicture
\def\tikzpicture{\catcode`\$=3 \@@tikzpicture}
\makeatother

\begin{document}
\begin{tikzpicture}
\draw [red,ultra thick] (0,0) -- ($(2,0)+(2,2)$);
\end{tikzpicture}
\end{document}

I have tested this solution (as well as @egreg's) with your MWE and both solutions seem to work fine.


TikZ 3.0.0 has a babel library intended for compatibility with the babel package, that fixes catcodes within tikzpicture, and seems to also solve the onlyamsmath compatibility issue for me.

Note: as cfr points out, this does of course still disable onlyamsmath checking within TikZ pictures

\documentclass{article}
\usepackage[all,warning]{onlyamsmath}
\usepackage{tikz}
\usetikzlibrary{calc, babel}

\begin{document}
\begin{tikzpicture}
  \draw (0,0) coordinate (A) node[below] {inline equation: $a^b$} -- 
        (4,0) coordinate (B) node[below, text width=3cm] {
          Checking does still occur within nodes, so this produces a warning:
          $$a^b$$
        } --  
        ($ (A)!0.5!(B)!sin(60)*2!90:(B) $) node[above] {calculated point} -- cycle;
\end{tikzpicture}
\end{document}

From the TikZ manual:

12.2.3 Handling Catcodes and the Babel Package

Inside a TikZ picture, most symbols need to have the category code 12 (normal text) in order to ensure that the parser works properly. This is typically not the case when packages like babel are used, which change catcodes aggressively.

To solve this problem, Tik Z provides a small library also called babel (which can, however, also be used together with any other package that globally changes category codes). What it does is to reset the category codes at the beginning of every {tikzpicture} and to restore them at the beginning of every node. In almost all cases, this is exactly would you would expect and need, so I recommend to always load this library by saying \usetikzlibrary{babel}. For details on what, exactly, happens with the category codes, see Section 43.