When TeX shrinks an equation, it only uses the shrink component of glue "at the outer level". For instance, numerator/denominator of fractions are not shrunk, as shown by the example below: first I put the output of the code then the desired output (obtained by scaling \thinmuskip, \medmuskip, \thickmuskip by 0.8, it turns out).

  $${1+2+3\over 2-1}=1+2+3={1+2+3}$$}

Image showing that math groups, fractions, etc. are not shrunk

Is it possible in LuaTeX to make TeX shrink such glue that is in a sublist when necessary? (I don't think it is possible in other TeX engines unless one takes over control of the full math typesetting, like in breqn.)

(This question is inspired by Does TeX use Hookean physical springs to represent positive and negative glue? where it was asked whether TeX could combine boxes in parallel.)

  • You can't shrink the contents of an \hbox, either, at least not without using \hbox to ... – John Kormylo May 25 '17 at 23:24
  • Probably you know about the nodetree package. When I add \input{nodetree.tex}\nodetreeregister{hpack} before your document I can at least see the glue spec inside the hlist. Therefore it should be possible to access it as well. However, I have no idea how. Perhaps drop Hans an email. – Henri Menke May 27 '17 at 4:28
  • By no means an answer, but simply a suggestion for a second illustration of how material in an "inner" atom doesn't get shrunk (squeezed): Change $${1+2+3\over 1}=1+2+3$$ to $$\left.1+2+3\right.=1+2+3$$ and compare the results at widths of 86 and 94. – Mico May 27 '17 at 5:20
  • @HenriMenke thanks for the pointer, this package looks very promising! – Bruno Le Floch May 27 '17 at 19:09

The macro \resizemath computes the stretch factor to be used, while \scalemath applies this factor proportionately inside every box or group as needed.


% shrnk/expand to given width
\newcommand{\resizemath}[2]% #1 = wudth, #2 = contents
{\mathchoice{\resizestyle{#1}{\displaystyle #2}}%
            {\resizestyle{#1}{\textstyle #2}}%
            {\resizestyle{#1}{\scriptstyle #2}}%
            {\resizestyle{#1}{\scriptscriptstyle #2}}%
% apply proportionate stretch
\newcommand{\scalemath}[1]% #1 = contents
{\mathchoice{\scalestyle{\displaystyle #1}}%
            {\scalestyle{\textstyle #1}}%
            {\scalestyle{\scriptstyle #1}}%
            {\scalestyle{\scriptscriptstyle #1}}%
\newcommand{\@stretch}{1}% initialize

\newcommand{\resizestyle}[2]% #1 = contents with style
  \sbox0{\def\@stretch{1}$\m@th #2$}% compute stretch factor
  \hbox to #1{$\m@th #2$}%

\newcommand{\scalestyle}[1]% #1 = contents with style
{\bgroup\sbox0{\def\@stretch{1}$\m@th #1$}\hbox to \@stretch\wd0{$\m@th #1$}\egroup}

\fbox{$\displaystyle \resizemath{100pt}{\frac{\scalemath{1+2+3}}{1} = 1+2+3}$}

\fbox{$\displaystyle \resizemath{86pt}{\frac{\scalemath{1+2+3}}{1} = 1+2+3}$}


|improve this answer|||||
  • This does not answer the question. The question is whether the engine can shrink the sublist without relying on the macro level. – Henri Menke May 27 '17 at 0:13
  • Thanks! (+1) I agree with Henri that this does not really answer the question. Not so much because you require the use of \stretchbox, which could be avoided without much work by redefining \frac, but because you need to choose the \stretchfactor by hand, rather than determining it at the end of a displayed equation depending on the text width. – Bruno Le Floch May 27 '17 at 0:57
  • The problem isn't just \frac. It's EVERY box or group you might use (like \sqrt or \phantom or subscripts and superscripts). The answer to your question is, or course, no. – John Kormylo May 27 '17 at 3:58
  • @JohnKormylo The problem Bruno is trying to solve is that he wants to forward the glue shrinkage in a line into the math sublist in the \over atom. Your solution does not attempt do solve this in any way. (1) You require the width at which the content is to be typeset. (2) You wrap it in a box and make it unbreakable. (3) With LuaTeX you can access the glue in the sublist and probably control the shrinkage of the sublist. Therefore the answer is obviously yes! – Henri Menke May 27 '17 at 4:33
  • @HenriMenke - So do it and I will delete this answer. – John Kormylo May 27 '17 at 4:39

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