Temporarily Change Equation Margin

Let's say I have a document with a narrow text width and lots of margin to spare. If I had a particularly long equation that failed to fit into the given width, the general solution would be to break the equation across multiple lines.

But if a particular equation was not well suited to that approach, is there a convenient way to temporarily change the margins just for a given equation? I provide a kludged approach below, but it requires manually inserted \vspace of an empirically derived magnitude. It just seems that there should be a better way. It also requires a specification of the widened textwidth, but that is OK, since I would prefer some uniformity of expansion, if the technique has to be used more than once in a document.

\documentclass{article}
\usepackage[nopar]{lipsum}
\begin{document}
\lipsum[1]
$$y = mx + b$$
\lipsum[2]
% HERE IS THE KLUDGE
\par\vspace{-.5\topskip}\noindent\makebox[\textwidth]{\begin{minipage}{7in}
$$E = mc^2 + 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{minipage}}\vspace{\topskip}\par
% END KLUDGE
\lipsum[2]
$$\nu = c / \lambda$$
\end{document}


As an afterthought, I would note that \leftskip and \rightskip approaches do not seem to change what happens inside the equation.

-
Please, don't inflict this to your readers. – egreg Jan 12 at 11:29
@egreg I wouldn't do it, but I am trying to help a colleague who does not wish to break his equation across lines. I suppose the "help" you would recommend would be to tell him to not do it this way. – Steven B. Segletes Jan 12 at 11:31

I'd avoid doing this as hard as I can. But…

\documentclass{article}
\usepackage{amsmath,environ}

\usepackage[nopar]{lipsum}

\makeatletter
\NewEnviron{widerequation}{%
\begin{equation*}
\sbox\z@{\let\label\@gobble$\displaystyle\BODY$}
\makebox[\textwidth]{%
\begin{minipage}{\dimexpr\wd\z@+3em}
\vspace{-\baselineskip}
$$\BODY$$
\end{minipage}%
}
\end{equation*}
}

\begin{document}
\lipsum[2]
$$y = mx + b$$
\lipsum[2]
\begin{widerequation}\label{test}
E = mc^2 + 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{widerequation}
\lipsum[2]
$$\nu = c / \lambda$$
See \eqref{test}
\end{document}


-
seems to me that this might allow the equation to go right off the paper. wouldn't a warning be friendly in case the thing gets too wide? – barbara beeton Jan 12 at 17:10
@barbarabeeton My idea would be to add an error message: “Wrong typesetting requested” ;-) – egreg Jan 12 at 17:22
@egreg Can this work for other math environments like align? – EthanAlvaree Mar 29 at 19:23

Here is a solution with the eqparbox package, which allows measurement of tagged boxes. It requires two compilations:

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{mathtools}
\usepackage{eqparbox}

\begin{document}

\lipsum[1]
\noindent\makebox[\textwidth]{\begin{minipage}{\dimexpr\eqboxwidth{Eq}+1Acm\relax}
\medskip
$$\eqmakebox[Eq]{\ensuremath{E = mc^2 + 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{minipage}}\vspace{\belowdisplayskip}
\lipsum[2]
$$\nu = c / \lambda$$

\end{document}


-

It seems that you could also use the adjustwidth environment from the changepage package:

\newenvironment{widerequation}{%
\begin{adjustwidth}{-2cm}{-2cm}$$} {$$\end{adjustwidth}}


Here's a complete MWE:

% arara: pdflatex
\documentclass{article}
\usepackage{amsmath}
\usepackage{changepage}
\usepackage[nopar]{lipsum}

\newenvironment{widerequation}{%
\begin{adjustwidth}{-2cm}{-2cm}$$} {$$\end{adjustwidth}}

\begin{document}
\lipsum[2]
$$y = mx + b$$
\lipsum[2]
\begin{widerequation}\label{test}
E = mc^2 + 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{widerequation}
\lipsum[2]
$$\nu = c / \lambda$$
See \eqref{test}
\end{document}

-
This is a real nice answer, if the adjustment is always to be of fixed width. Thanks! – Steven B. Segletes Jan 12 at 16:53
@cmhughes Can this work for other math environments like align? – EthanAlvaree Mar 29 at 19:24