Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Some people have asked about how to add multiple paragraphs (when \intertext and \shortintertext no longer work), a fix was proposed by Peter Grill here:

He wrote:

My first thought was to hack apart the result of an align and dole out the lines one-by-one wherever you want them. Alas, align produces a list of considerable complexity and it is not worth the effort to unravel it (if that's even possible).

So I made my own alignment environment that, as far as I can tell, does what you'd want align* to do but produces a very simple list. My macro \ALineAgain then picks that list apart and drops the lines one at a time wherever you ask.

Because the lines are not printed where the alignment is actually given, it makes no sense to have an AlignAgain*; it never prints equation numbers. Instead, the \ALineAgain macro takes a star that suppresses the addition of an equation number.

The problem with this code is that the equation numbers seem to be messed up once you try referencing them. Below, I've added only a few lines to Peter's code (notably: \numberwithin{equation}{section}, two section commands, and then a single line at the very end that attempts to reference the two equations).

Rather than printing (1.1) and (1.2), it prints (1.1) and (1.1). There seems to be something wrong with the equations portion of the code. Can anybody spot the problem?

\documentclass{article}
% \usepackage{showframe}
\usepackage{amsmath}

\numberwithin{equation}{section}

% It's like {align}, but simple!
\newenvironment{SimpleAlign}
{%
 \let\\=\cr
 \tabskip 0pt plus 1fil\relax
 \halign\bgroup
  &\hfil$\displaystyle ##$\tabskip 0pt\relax
  &$\displaystyle {}##$\hfil\tabskip 0pt plus 1fil\relax\cr
}
{%
 \crcr\egroup
}

% Saves its contents typeset like SimpleAlign.  You can give it a name.
\newenvironment{AlignAgain}[1][AlignBox]
{%
 \expandafter\let\expandafter\AlignAgainBox\csname #1\endcsname
 \setbox\AlignAgainBox=\vbox\bgroup\SimpleAlign
}
{%
 \endSimpleAlign\egroup
 \ReBox\AlignAgainBox
}
\newbox\AlignBox

% Prints the lines from {AlignAgain} one-by-one, with or without equation numbers as starred.  If you named the {AlignAgain}, use it here.
\makeatletter
\newcommand\ALineAgain{%
 \@ifstar
  {\AlignAgainStartrue\@ALineAgain}
  {\AlignAgainStarfalse\@ALineAgain}%
}
\newcommand\@ALineAgain[1][AlignBox]{%
 \expandafter\let\expandafter\AlignAgainBox\csname #1\endcsname
 \begin{equation*}
  \PutFirstBox\ifAlignAgainStar\AlignAgainBox
 \end{equation*}
}
\makeatother
\newif\ifAlignAgainStar

% Reboxes a box in the format: {[1][2]...[n]} -> {[1]{[2]{...}[n]}}
% {...} = \hbox
\newcommand{\ReBox}[1]
{%
 % To enter internal vertical mode, where \lastbox is valid
 \setbox0=\vbox{%
  \unvbox#1\relax
  \global\setbox#1=\hbox{\hbox{}}
  \loop
   \unskip
   %\box0 is the box currently at the end of #1
   \setbox0=\lastbox
  \ifvoid0\relax
  \else
   \global\setbox#1=\hbox{\box0\box#1}%
  \repeat
 }%
}

% Puts the first box in a nested-box list into the display, saving the rest back in #1
% Optionally places an equation number
\newcommand{\PutFirstBox}[2]{%
 \hbox to \displaywidth{%
  \unhbox#2\relax
  \global\setbox#2=\lastbox
  \setbox0=\lastbox
  \unhbox0%
  #1\else\refstepcounter{equation}\llap{(\theequation)}\fi
 }%
}

\begin{document}

\section{First section}
\subsection{A subsection}
Hello
\begin{AlignAgain}
 a &= b & c &= d \label{firsteqn} \\
 f(x) &= g(x) & h(x) &= e^{-1/x^2} \label{myeqn} \\
\end{AlignAgain}

This is a paragraph with a lot of redundant words whose only purpose is to extend it onto a new line or two so it's dramatic when I display this equation:
\ALineAgain
and then follow it with a bunch more text.

And also a new paragraph, just for good measure.  I wonder if the two equations will line up?  I sure hope so!
\ALineAgain
This is sort of fun. 

Can we reference equations by section? Try (\ref{firsteqn}) and (\ref{myeqn}).

\end{document}
share|improve this question

1 Answer 1

up vote 13 down vote accepted

enter image description here

There's no problem in having multiple paragraphs in \intertext you just can't have a \par or blank line, \endgraf is OK though:

\documentclass{article}
\usepackage{amsmath}

\def\a{One two three four. }
\def\b{\a\a\a\a}
\def\stuff{\b\b}
\begin{document}

\begin{align}
1&=222\\
\intertext{%
para 1 \stuff
\endgraf
Followed by para 2 \stuff}
33&=44\\
555&=6
\end{align}

\end{document}
share|improve this answer
    
This works very well, so I've accepted the answer. However, can you add in a word (for future reference by others) as to why \endgraf works within the intertext? –  TSGM Jun 14 '12 at 15:21
    
The primitive check on "runaway arguments" built into TeX really checks for tokens called \par so LaTeX (following Plain TeX) defined \endgraf by \let\endgraf\par so it is the same as \par but with a different name. –  David Carlisle Jun 14 '12 at 16:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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