TransWikia.com

Why is leavevmode required in this example?

TeX - LaTeX Asked on March 29, 2021

In the following mwe, If I comment out leavevmode in the redefinition of the equation* environment, the proof title disappears

documentclass{article}
usepackage{amsmath}
usepackage{amsthm}

% from https://tex.stackexchange.com/a/59955/172923
makeatletter
newcommand{settowidthofalign}[2]{%
  setboxz@=vbox{
    begin{align*}
    #2
    ifmeasuring@elsegloballetgot@maxcolwdmaxcolumn@widthsfi
    end{align*}
  }%
  begingroup
  defor{+}edefx{endgroup#1=dimexprgot@maxcolwdrelax}x}
makeatother

ExplSyntaxOn

dim_new:N l_eqn_width_dim

cs_set_eq:cc { oldequation* }{ equation* }
cs_set_eq:cc { endoldequation* }{ endequation* }

RenewDocumentEnvironment{ equation* }{ +b }
  {
    %leavevmode
    settowidthofalign{ l_eqn_width_dim } { #1 }
    begin{oldequation*} #1 end{oldequation*}
  }{}

ExplSyntaxOff

begin{document}
begin{proof}
  begin{equation*}
    a + b = c
  end{equation*}
end{proof}
end{document}

without leavevmode:

enter image description here

with leavevmode:

enter image description here

What is the cause of this behaviour?

One Answer

When you say begin{proof}, the label “Proof” is obtained with item[...] and it's a standard feature of trivlist (that's used for implementing proof) that the typesetting of the label is delayed when the first text following it is scanned and typeset.

In your case this happens when begin{align*} inside the vbox is executed, so the label is lost together with the box.

You need leavevmode at the beginning of settowidthofalign. Just for safety: starting a proof with a display is not the best thing to do anyway.

Correct answer by egreg on March 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP