# Hooking into $$and$$

Joseph Wright mentions in an comment to this tex.SE answer that it is possible to “hook into” the $$ and $$ commands to change their behaviour. Say that I'd like to force a cramped style on all inline equations by e.g. wrapping them in \cramped (from the mathtools package) by hooking into the $$ and $$ commands. How would I do that? Or is there perhaps an easier way to force a cramped style?

I would say

\def$$#1$${$\cramped{#1}$}


Perhaps too simplistic, but it should work.

• That seems to do the trick!
– You
Jul 19 '11 at 19:26
• Nifty! Is there somebody who's willing to explain how the same result might be obtained with some of the commands provided by the etoolbox package? The package's documentation lists plenty of definitions of commands but, disappointingly, doesn't provide a single example. :-(
– Mico
Jul 20 '11 at 0:21
• This will break down with nested math mode, won’t it? (IIRC \def scans its definition tokens greedily without parsing) Jul 20 '11 at 7:14
• @Konrad Yes, it has no check like the default $$...$$. Jul 20 '11 at 7:38