# Automatically resize equations

I want to know if there is a tool to automatically resize the equations if they are longer than \pagewidth.

The whole story is that I am compiling my thesis in b5paper, but I want to also produce a pdf that is more ebook-size-friendly. Therefore, I am compiling the source documents again with a smaller paper size. Long equations that are correctly displayed in b5paper go over the margin in the new smaller paper. I tried to use the breqn package, but as soon as I load it, the compiler never ends compiling.

Any other idea?

Scaling elements which contain text is usually a bad idea, see Why not scale elements that contain text

I suggest to use a smaller font size or split the equations over multiple lines instead.

\begingroup
\scriptsize%
$$x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x$$
\endgroup


If you must scale them, you could try \resizebox:

\documentclass{article}

\usepackage{graphicx}

\begin{document}

$$\resizebox{.9\textwidth}{!}{ x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x }$$

\end{document}


Or if you also want to apply it to short equations which don't need to be scaled:

\documentclass{article}

$$\adjustbox{max width=.9\textwidth}{ x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x }$$
$$\adjustbox{max width=.9\textwidth}{ x x x x x x x x x x x x x x x x x x x x }$$