The discussion focuses on the challenge of expanding the expression (a+b)^n in LaTeX without using explicit whitespace commands. Participants explore various methods to align the components of the expression, noting the difficulty of achieving vertical alignment of the "+" signs due to the asymmetry introduced by the exponent. They highlight the limitations of MathJax and MiKTeX in parsing certain LaTeX commands, such as \makebox and the tabular environment. Additionally, the concept of "glue" in TeX is discussed as a means to manage spacing dynamically. Overall, the conversation emphasizes the complexities of formatting mathematical expressions in LaTeX.
First of all, I must apologize for not checking if my solution works on this site. Apparently, it does not, but it is nevertheless normal LaTeX.
Mark, this is also nice, and formally it satisfies the description. One drawback is that "$(a$" on one line cannot vertically overlap with "$(a$" on the following line since they belong to different columns.
There is a trick in TeX (which uses one of the core features) that allows doing this very easily and flexibly so that the width of the line can be arbitrary.
By the way, I don't think one needs to put LaTeX output inside a spoiler since the code is not visible without additional manipulation (right-clicking and selecting "Show Math As" or responding with a quote).
#6
Opalg
Gold Member
MHB
2,778
13
This is harder than it looks! I think that a good solution ought to have these two features: (1) the + signs must be exactly aligned vertically, (2) there should be exactly the same amount of white space on each side of the +. The reason this is hard to achieve is that the expression $(a+b)^n$ is not symmetric about the + (the exponent ^n makes the right side wider than the left side).
I can't find any way to do this using commands that MathJax will accept. Using TeXShop (which automatically centres displayed equations), the input:
Latex Code:
It is strange that this code works in MathJax. In regular LaTeX it produces an error due to the presence of &. Indeed, "a & + & b" is supposed to make three columns, while the preamble of the array environment declares only one.
I did not intend for the lines to be aligned on +. That would be nice, but I don't know how to do it using my idea. I used glue, which is a really fundamental part of TeX. In fact, it is more like a spring because it can both shrink and expand. When specifying whitespace, one can provide not only its natural width, but also the ability of the space to shrink and stretch. For example,
[latexs]
1cm plus .2cm minus .1cm
[/latexs]
denotes a glue whose natural width is 1 cm and which can shrink by at most .1 cm. In contrast, it can stretch arbitrarily much, but stretching beyond .2 cm will be assigned a high score of "badness". This score is used in deciding how to split a paragraph into lines, and the goal is to minimize badness in the whole paragraph.
In more detail, if a box has total stretchability (the sum of "plus" components of all spaces) of $x$, but it has to be stretched by $y$, then the glue set ratio is defined as $r=y/x$. Then each space that has the plus component $x_i$ is stretched by $rx_i$. The badness of $r$ is defined as $\min(100r^3,10000)$. For example, if a space is stretched twice its plus component, the badness is 800.
Mathematical glue is measured in mu, which is $1/18$ of em (approximately the width of M or an em-dash). For example, thin space \, medium space \: and thick space \; equal 3, 4 and 5 mu, respectively. more precisely, medium space is
[latexs]
4mu plus 2mu minus 4mu.
[/latexs]
Each symbol in math has one of several categories (ordinary symbol, binary operator, etc.), and spacing between symbols is based by their categories. In particular, TeX inserts medium space between $a$ (ordinary symbol) and $+$ (binary operator). In my LaTeX setup, 1 em equals 10 points, so the stretchability of the medium space is $(2/18)\cdot10=10/9$ of a point.
The LaTeX commands for creating horizontal boxes (LR-boxes in LaTeX terminology or hboxes in plain TeX terminology) are \mbox and \makebox (Wikibooks). The latter command takes two optional arguments: width and position. Thus, it is possible to specify a larger than natural width and make the box stretch. This also requires giving s (spread) as the position argument. For example,
[latexs]
\makebox[3cm]{$(a+b)^n$}
[/latexs]
produces a box 3 cm wide.
Plain TeX analogs are
[latexs]
\hbox to dimen { contents of box }
\hbox spread dimen { contents of box }
[/latexs]
The first specifies the total box width, while the second specifies by how much the box must be stretched. For example,
[latexs]
\hbox spread 10pt {$(a+b)^n$}
[/latexs]
adds an additional em to the natural width. There are two medium spaces (no space is inserted before the exponent), so the glue set ratio is $\dfrac{10}{2(10/9)}=\dfrac{9}{2}=4.5$, so each space becomes $\dfrac{9}{2}\cdot\dfrac{10}{9}=5$ pt. This is confirmed by the trace that one can print in the log file.
Code:
\hbox(7.5+2.5)x45.02081, glue set 4.5001
.\mathon
.\OT1/cmr/m/n/10 (
.\OML/cmm/m/it/10 a
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OT1/cmr/m/n/10 +
.\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
.\OML/cmm/m/it/10 b
.\OT1/cmr/m/n/10 )
.\hbox(3.01389+0.0)x5.44333, shifted -3.62892
..\OML/cmm/m/it/7 n
.\mathoff
It shows that the glue set ratio is 4.5, and each of the two \medmuskip's is multiplied by this value. The badness of this box is $100(4.5)^3\approx9113$, which is close to the maximum 10,000. For some reason, LaTeX wrote
Code:
Underfull \hbox (badness 10000) detected at line 14
probably because badness calculation is approximate.
All in all, my code was
[latexs]
\begin{tabular}{c}
\makebox{$(a+b)^n$}\\[2ex]
\makebox[2cm]{$(a+b)^n$}\\[2ex]
\makebox[3cm]{$(a+b)^n$}\\[2ex]
\makebox[4cm]{$(a+b)^n$}
\end{tabular}
[/latexs]
All in all, my code was
[latexs]
\begin{tabular}{c}
\makebox{$(a+b)^n$}\\[2ex]
\makebox[2cm]{$(a+b)^n$}\\[2ex]
\makebox[3cm]{$(a+b)^n$}\\[2ex]
\makebox[4cm]{$(a+b)^n$}
\end{tabular}
[/latexs]
Your code does not parse in MiKTeX due to badness 10000.
It cannot parse in a math environment like MathJax.
What does it take to parse it?
Edit: Hmm, after some twiddling with MiKTeX (that I had just installed), it did parse.
Not sure why though.
#12
Evgeny.Makarov
Gold Member
MHB
2,434
4
I like Serena said:
Your code does not parse in MiKTeX due to badness 10000.
But an underfull hbox is a warning, not an error. It does not stop compilation. Overfulls and underfulls happen all the time (though the latter are more rare). What output do you get from LaTeX?
I like Serena said:
It cannot parse in a math environment like MathJax.
Yes, because MathJax does not recognize the \makebox command. It does accept \hbox{...}, but not "\hbox to 1cm {...}".
But an underfull hbox is a warning, not an error. It does not stop compilation. Overfulls and underfulls happen all the time (though the latter are more rare). What output do you get from LaTeX?
I didn't get any output from MiKTeX.
Not even from a simple text line.
That is, until I parsed an old document that used a couple of packages.
That triggered MiKTeX to download and install a series of packages.
After that everything worked.
So it appears it was only some sort of configuration issue.
I still get the warnings though. :)
Yes, because MathJax does not recognize the \makebox command. It does accept \hbox{...}, but not "\hbox to 1cm {...}".
MathJax also does not accept the tabular environment.
I guess we need an array instead.