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?

  • 1
    possibly it's possible but that would also have other bad effects eg making it inline math not display math, a more robust alternative would be to specify smaller math fonts with (for example) \DeclareMathSizes rather than use scaling – David Carlisle Oct 12 '16 at 21:57
  • 1
    See tex.stackexchange.com/a/5152/36296 – user36296 Oct 12 '16 at 21:59
  • Well in fact what I want to do is a \resizebox{\textwidth}{!}{...} whenever the formula is larger than \textwidth – yannis Oct 12 '16 at 22:02
  • 1
    @yannis that's so evil but if it has to be done.... – David Carlisle Oct 12 '16 at 22:04
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}
  • 2
    No, they won't. :P – egreg Oct 12 '16 at 22:46
  • 1
    @egreg that's what I fear – David Carlisle Oct 12 '16 at 22:59
  • Great, thanks!! Don't worry about the gods, this is for private use only, no book carrying the trace of your sin will ever be published (except perhaps the next edition of the Necronomicon, but this even the gods cannot read without going insane). – yannis Oct 13 '16 at 9:56
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.