\documentclass{article} \usepackage{etoolbox} \usepackage{tikz} \makeatletter \let\mathdollar=$%$ \newif\if@mathchoice \protected\long\def\wlog@math#1{% \ifmeasuring@ \else \if@mathchoice \else \wlog{MATH: \detokenize{#1}}% \fi \fi } \begingroup \catcode`\$=\active \protected\gdef ${%$ \@ifnextchar$%$ {\grabdisplaymath} {\grabinlinemath}% } \protected\gdef\grabinlinemath#1${%$ \wlog@math{#1}% \mathdollar #1\mathdollar } \protected\gdef\grabdisplaymath$#1$${%$