0

Is it possible to have a hook in every display math mode, before and after the formula?

For example: if I would like to make every display formula 50% smaller, I would ask the hook on entering the $$ formula to be \scalebox{.5}\bgroup\ensuremath\bgroup and the one on leaving the formula would be \egroup\egroup.

It should work both with $$...$$, \[...\] and with \begin{equation}...\end{equation}.

In other words, writing

\def\beginDisplayMathHook{\scalebox{.5}\bgroup\ensuremath\bgroup}
\def\endDisplayMathHook{\egroup\egroup}
$$ x^2+y^2=1 $$

should be equivalent to

$$\scalebox{.5}{\ensuremath{x^2+y^2=1}}$$

Is this possible?

yannis
  • 2,013
  • 19
  • 18

2 Answers2

4

enter image description here

may the gods of math typesetting forgive me.

\documentclass{article}
\usepackage{graphicx}
\def\z#1{\par\hrule$$#1$$\[#1\]\begin{equation}#1\end{equation}\hrule}

\setlength\textwidth{4cm}

\makeatletter
\everydisplay{%
\setbox0\hbox\bgroup
\global\setbox1\box\voidb@x 
\def\eqno#1$${\global\setbox1\hbox{#1}$$}%
$\displaystyle\def\]{$$}\aftergroup\foo}
\def\foo${\egroup
\ifdim\dimexpr\wd0+\wd1>\textwidth
  \resizebox{\dimexpr\textwidth-\wd1\relax}{!}{\box0}%
\else
  \box0
\fi
\ifvoid1
\else
\eqno\box1
\fi
$$}
\makeatother

\begin{document}

\z{x+y+z}

\z{\frac{111}{2222}+\sqrt{x^2-y^2}}

\z{\frac{111}{2222}+\sqrt{x^2-y^2}+a+b}


\z{\cos\theta - \frac{t^5}{s^4}+\sqrt{x^2-y^2}+a+b}

\z{\cos\theta +\sin\phi + \tan\sigma - \frac{t^5}{s^4}+\sqrt{x^2-y^2}+a+b}

\end{document}
David Carlisle
  • 757,742
1

There already exists the nccmath package, which defines ‘medium-maths’ commands and environments you might be interested in: they scale to ~ 80 % of \displaystyle.

Here is an example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{nccmath}

\begin{document}
\[ a^2 + b^2 = 1,\quad \int_a^b \frac{f(x)}{g(x)}\,\mathrm d\mkern1mu x, \quad\begin{bmatrix}x & y\\u & v\end{bmatrix}\]%

\[ \medmath{ a^2 + b^2 = 1}, \quad \medint\int_a^b \mfrac{f(x)}{g(x)}\,\mathrm d\mkern1mu x \quad\left[\begin{mmatrix}x & y\\u & v\end{mmatrix}\right] \]%

 \end{document} 

enter image description here

Bernard
  • 271,350