2

In TeX by Topic, chapter 25.3.2, “Brace counting in preambles”, states that “Alignments can be nested”. Probably because of the braces of the preamble.

How can I nest two \halign?

This doesn't work:

\halign {% started in vertical mode
  {\halign {#\cr δ\cr }}& #\cr % preamble
  ε& ζ\cr } % spaces after & are discared

\halign {#& #\cr % simple preamble
  {\halign {#\cr δ\cr }}ε& ζ\cr }

You can see above how I would like to nest \halign. If that's not clear, just explain chapter 25.3.2 and give an example or two.

Note: I know that this can be done with a \vbox like below but this is not my question. I want to understand this chapter of the book, not to solve a problem of alignment.

\everycr = {}
\tabskip = 0 pt plus 1 fill
\halign to \hsize {#\cr
                   outer text\cr
                   \vbox {\halign to \hsize {#\cr inner text\cr }}\cr }

Side question: will your code work in LaTeX? in XeLaTeX?

3
  • that section is telling you that you can have an halign in the body of an halign not that you can have an halign in an halign preamble (although you can do that as well) but \halign has to appear in vmode so you need a vbox somewhere. Commented Jun 28, 2018 at 11:54
  • I don't think you can have \halign in the preamble of another \halign, even if hidden in a \vbox. TeX exits with “Emergency stop”.
    – egreg
    Commented Jun 28, 2018 at 13:52
  • @David Carlisle, egreg: Thanks. Can you give me an example of an \halign inside the preamble of another \halign? And inside the body of another \halign? What about the brace count the section is speaking about?
    – user73438
    Commented Jun 28, 2018 at 16:24

1 Answer 1

2

I think that to nest an \halign in the preamble f an outer \halign you need to hide the \halign from the scanner, most easily by using an extra macro expansion (\zz here) you also need a \vbox to get back to vertical mode.

This takes the first cell of each row of the outer \halign and uses it as the first row of an inner \halign, centering it over x.

enter image description here

\def\zz#1{\vbox{\halign{\strut\hss##\hss\cr#1\cr x\cr}}}

\halign {% started in vertical mode
  \zz{#}& #\cr % preamble
  aaaa& b\cr
  zzzzz& c\cr 
}


\bye

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .