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.

I was trying to figure out an automatic answer to Sharing alignment between equations in two different items by way of typesetting an {align} inside a \vbox and then using \unvbox and \lastbox repeatedly to get the lines of the alignment. Alas, this does not work, as this session with latex shows:

>latex
**\relax
*\documentclass{article}\usepackage{amsmath}\begin{document}

*\setbox0=\vbox{\begin{align*} a&=b \end{align*}}

*\tracingonline=1

*\showbox0
> \box0= []

! OK.
<*> \showbox0

? 

*

*\unvbox0

*\unskip

*\setbox1=\lastbox

*\showbox1
> \box1=void

! OK.
<*> \showbox1

? 

How can there be nothing in the box? Doesn't TeX typeset something? This is surely a mathmode thing, except that the following does work:

> tex
**\relax

*\setbox0=\vbox{$$\eqalign{a&=b}$$}

*\tracingonline=1

*\showbox0
> \box0=
\vbox(22.5+0.0)x469.75499
.\hbox(0.0+0.0)x469.75499, glue set 449.75499fil
..\hbox(0.0+0.0)x20.0
..\penalty 10000
..\glue(\parfillskip) 0.0 plus 1.0fil
..\glue(\rightskip) 0.0
.\penalty 10000
.\glue(\abovedisplayshortskip) 0.0 plus 3.0
.\glue(\baselineskip) 3.5
.\hbox(8.5+3.5)x26.24402, shifted 221.7555
..\hbox(0.0+0.0)x0.0
..\glue 1.66663
..\vbox(8.5+3.5)x22.91077
...\hbox(8.5+3.5)x22.91077 []
..\glue 1.66663
.etc.

! OK.
<*> \showbox0

? 

*

(\eqalign is the TeX version of {align}, to some extent). Perhaps it is more that the AMS environments do what the TikZ documentation refers to as "wicked things", but I don't see how they could trick TeX itself into thinking the box were empty. I do notice that even in the \eqalign example, the innermost box of the alignment is \hbox(8.5+3.5)x22.91077 []; going by the dimensions \hbox(0.0+0.0)x469.75499, glue set 449.75499fil, this is the text (i.e. a = b) but the empty brackets indicate that there is nothing inside the box. So maybe it is a mathmode thing after all and the AMS' wickedness is just hiding the surrounding material as well?

So, is there any way to unwrap an {align}?

share|improve this question
    
In your solution to that question, you use \intertext. amsmath uses \noalign to solve the problem. I think it is the right way. –  Leo Liu Oct 13 '11 at 15:32
    
@Leo: There was a further question, though, about how to align not only between different \items but between different paragraphs. \noalign won't work for that. –  Ryan Reich Oct 13 '11 at 16:00
    
If all else fails, you could always "mark" the alignment places in the PDF, saving them in the aux file, and read in the coordinates on the next TeX run. –  Andrew Stacey Oct 13 '11 at 16:07
    
@Andrew: I was actually considering a TikZ solution to get the coordinates, but I was curious if simply saving the lines one at a time could work. Now I'm just puzzled by the behavior in the question. –  Ryan Reich Oct 13 '11 at 16:11
add comment

2 Answers

The column width in an align are kept in the macro \maxcolumn@widths that's set after the first pass over the environment's contents: in your case

> \maxcolumn@widths=macro:
-> \or 5.28589pt \or 17.62488pt \or 0.0pt.

One can access to the values with \ifcase. Of course it's necessary to "export" the macro, which can be done by saying in any of the cells

\ifmeasuring@
  \global\let\lastmaxcolumn@width\maxcolumn@widths
\fi

(maybe this can be added to the code for \end{align*}, but I'm not sure).

share|improve this answer
add comment
up vote 0 down vote accepted

Turns out that the main thing I was asking about is the result of a misunderstanding: if you set \showboxdepth large enough, then everything will be displayed as expected. No empty boxes.

As for unwrapping an {align}: Presumably some combination of \unskip and \unpenalty will reveal the actual list of lines, after which \lastbox will work. See my second answer to Sharing alignment between equations in two different items for the easy version of this.

share|improve this answer
    
You can't access the \halign via \lastbox, because align and align* add a final \mathoff node that you can't remove. Unwrapping the \halign must be done before math mode is closed. –  egreg Oct 17 '11 at 10:19
    
@egreg: I knew there was a reason I did it the other way! –  Ryan Reich Oct 17 '11 at 15:33
add comment

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.