# Modifying \everydisplay causes the align* environment to stop working

I want all displayed mathematics in my document to be typeset in the style of inline mathematics. In his answer to this question, Matthew Leingang explains how to do the opposite (typeset all inline mathematics in the style of displayed mathematics) by carefully modifying the \everymath token list. Reasoning by analogy I figured that the following test document ought to work:

\documentclass[a4paper,reqno]{amsart}

\usepackage{amssymb,amsmath,amsthm,fullpage}

\everydisplay=\expandafter{\the\everydisplay\textstyle}

\begin{document}

\begin{align*}x
&=\sum_{i=1}^{10}i^2\\
&=t^3+\int_3^9y^a\,\mathrm{d}y\end{align*}

\end{document}


But it does not. When trying to compile this document, TeXWorks gives the following error:

! Improper \halign inside 's. <recently read> \halign  The code it displays, as though to draw my attention to a mistake, is the code in the vicinity of \end{align*}. This error does not appear if the line in the preamble modifying \everydisplay is commented out. Why doesn't this work? - ## 2 Answers Internall, align uses alignment displays, described p. 190 of the TeXbook as follows: TeX also allows "alignment displays" [...] An alignment display is created by commands of the general form  <assignments> \halign{ <alignment> } <assignments> 


where the <assignments> [...] do not produce any math lists.

But \textstyle is not an assignment: in fact, it starts a math list. So \halign is not alone in that equation anymore, and TeX complains.

Now a solution: since align builds a construction like $\displaystyle ...$ internally, we can redefine the size using \let\displaystyle\textstyle.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\let\displaystyle\textstyle

An example of aligned equations,
\begin{align}
\sum_{i=1}^N \frac{x^2}{2} + \frac{y^2}{2} &= \frac{\sqrt{z^{\frac{2}{3}}}}{2}
&\frac{\sqrt{z^{\frac{2}{3}}}}{2} &= \sum_{i=1}^N \frac{x^2}{2} + \frac{y^2}{2}
\\
\frac{\sqrt{z^{\frac{2}{3}}}}{2} &= \sum_{i=1}^N \frac{x^2}{2} + \frac{y^2}{2}
&\sum_{i=1}^N \frac{x^2}{2} + \frac{y^2}{2} &= \frac{\sqrt{z^{\frac{2}{3}}}}{2}
\end{align}
which seem to work.

But the \verb|equation| environment won't:
$$\frac{\sqrt{z^{\frac{2}{3}}}}{2} = \sum_{i=1}^N \frac{x^2}{2} + \frac{y^2}{2}$$

\end{document}


You might prefer saving the definition before using \let\olddisplaystyle\displaystyle in case you need it.

-
Ah, also a good idea. But can you explain why the code in the OP doesn't compile? – Hendrik Vogt Feb 23 '11 at 14:31
@Hendrik: I added something, but I'm not quite sure why alignment displays are useful, rather than just using an \halign outside a display. – Bruno Le Floch Feb 23 '11 at 15:08
Thanks! I wouldn't have guessed that reason. – Hendrik Vogt Feb 23 '11 at 15:13
Thank you very much for the explanation and the suggested workaround, much appreciated. – Hammerite Feb 23 '11 at 16:54

A partial workaround is to define some macros that can be used to replace the $...$ and align* environments. Regard the following:

\documentclass[a4paper,reqno]{amsart}

\usepackage{amssymb,amsmath,amsthm,fullpage}

\newcommand{\t}{\textstyle}
\newcommand{\blob}[1]{$\t#1$}
\newcommand{\calc}[2]{\begin{align*}\t#1&\t#2\end{align*}}
\newcommand{\nl}{\\&\t}

\begin{document}

\calc{x}{
=\sum_{i=1}^{10} i^2 \nl
\leq t^3 + \int_3^9y^a\,\mathrm{d}y
}

\end{document}


This gives displayed mathematics typeset as inline maths, and provides commands that do pretty much what I want and make for readable enough code. For unusual cases where \blob and \calc are not good enough, at least \t is reasonably concise, even if it does have to be just about everywhere.

This isn't a real answer to my question, though. I'd still like to know what the deal is with the original problem...

-