# scalebox and equations

I have a big diagram (that I produce with \xymatrix) that I want to rescale to fit the page. Currently, I am using

\resizebox{\columnwidth}{!}{
$\xymatrix{ bigdiagram }$
}


and it produces what I want but I get the error

LaTeX Error: Bad math environment delimiter.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.2366 }


everytime I compile my tex file. What is the proper way to resizing an equation?

• Instead of $...$, try with $...$.
– Werner
Aug 30 '19 at 23:51
• … or, perhaps better, with $$\displaystyle ...$$ (or $\displaystyle ...$, for that matter).
– GuM
Aug 30 '19 at 23:58
• Could you post a MWE? It would be interesting to see the code for the bigdiagram, too: perhaps somebody would be able to suggest you a better solution than simply (and crudely) scaling it down.
– GuM
Aug 31 '19 at 0:29

I see essentially two sources of trouble:

1. LaTeX allows “Display math mode”, which is the math mode implied by the $...$ syntax, only inside the so-called “paragraph mode” (the name was chosen by Leslie Lamport himself), which is, roughly speaking, the mode LaTeX is in when it is typesetting ordinary paragraphs. Unfortunately, the main argument of a \resizebox command is typeset in a different mode (Lamport calls it “left-to-right mode”, or “LR mode” for short), that does not allow displayed equations. See p. 36 of the 2nd edition of Lamport’s manual (L. Lamport, LaTeX: A Document Preparation System, second edition) for more information.

2. If your bigdiagram is typeset using an environment that needs to change \catcodes, like the tikzcd environment defined by the tikz-cd package, than (usually) you cannot put it inside the argument of another command. It seems, though, that you are using the xy (Xy-Pic) package: I cannot recollect for sure, off the top of my head, that this environment too needs to change \catcodes (I used the Xy-Pic package some twenty years ago, and only sometimes), but it’s very likely it does, hence suffering from the same problem.

You can obviate the first problem by substituting in-line math mode for display math mode, possibly using \displaystyle to get symbols in the same size as if they were displayed, as in the following code excerpt:

\resizebox{\linewidth}{!}{%
$$\displaystyle \sum_{i=1}^{n} x_{i} + \frac{y}{2} = z$$%
}


To circumvent the second, you can use the lrbox environment to save the typeset diagram in a temporary storage box, and than use that box in the argument of \resizebox, as in

\newsavebox{\tempDiagram}
\begin{lrbox}{\tempDiagram}
$$% "\displaystyle" doesn't matter in this case \begin{tikzcd} % example taken from the "tikz-cd" manual A \arrow[rd] \arrow[r,"\phi"] & B \\ & C \end{tikzcd}$$
\end{lrbox}
\resizebox{\linewidth}{!}{\usebox{\tempDiagram}}


Full MWE:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath} % compatibility check
\usepackage{graphics}
\usepackage{tikz-cd}

\begin{document}

\resizebox{\linewidth}{!}{%
$$\displaystyle \sum_{i=1}^{n} x_{i} + \frac{y}{2} = z$$%
}

\newsavebox{\tempDiagram}
\begin{lrbox}{\tempDiagram}
$$% "\displaystyle" doesn't matter in this case \begin{tikzcd} % example taken from the "tikz-cd" manual A \arrow[rd] \arrow[r,"\phi"] & B \\ & C \end{tikzcd}$$
\end{lrbox}
\resizebox{\linewidth}{!}{\usebox{\tempDiagram}}

\end{document}


The picture below shows the full page I get in the output file. For the record, I’m now working on my backup computer, which, unfortunately, is only equipped with the 2016 release of TeXLive; but this shouldn’t have any substantial impact on the output produced. On the other hand, it looks like my installation lacks several fonts that the Xy-Pic package needs to do its job, so I’m not able to experiment with it… :-(

Two final remarks:

1. I recommend that you consider switching to the tikz-cd package for typesetting your diagrams.

2. As you can see, scaling (up or) down a whole math formula can look awful, since the typafaces are scaled too, and in practice it’s a viable solution only if the scaling factor is very close to one; otherwise, you should try really hard to find a different solution.

• The first solution already worked for my example. Thank you! Aug 31 '19 at 20:59