LaTeXML icon indicating copy to clipboard operation
LaTeXML copied to clipboard

\unvbox and friends request a block unwrap

Open dginev opened this issue 11 months ago • 4 comments

Fixes #2458 .

dginev avatar Dec 27 '24 12:12 dginev

@xworld21 I am not sure your questions apply to the level of emulation that is in latexml at present. Vertical mode has not been implemented in a "strict" sense, as matching the exact layout algorithm from TeX was never a main latexml goal. This could be contrasted to converters such as tex4ht and rustex, where the emulation follows TeX much more closely.

All of this could evolve of course, but the PR here tries to minimally match the \vbox and \hbox DefConstructors, where the outer whatsit will indeed be lost/unwrapped, while the "content" argument will remain in its place.

dginev avatar Dec 27 '24 15:12 dginev

I am not sure your questions apply to the level of emulation that is in latexml at present

I meant to say it needs to introduce a newline or start a new paragraph. I applied your patch (or rather, a worse version I cooked up before your PR) and you get e.g. consecutive bits of text with no space between them. The \unvbox, \unvcopy constructors must also introduce a newline or close the current paragraph. I figure injecting a \par is close enough.

I'll produce some examples to show the difference.

xworld21 avatar Dec 27 '24 16:12 xworld21

I came up with this curious test, and indeed, the PR should add a vertical annotation of some kind to emulate it correctly:

\documentclass{article}
\newbox\boxA
\newbox\boxB
\newbox\boxC
\newbox\boxD
\begin{document}
  
\setbox\boxA=\vbox spread 1cm{1cm Box}
\setbox\boxB=\vbox spread 2cm{2cm Box}
\setbox\boxC=\vbox spread 3cm{3cm Box}
\setbox\boxD=\vbox{\unvbox\boxA\unvbox\boxB\unvbox\boxC}

combined vbox: \fbox{\box\boxD}
\end{document}

And actually, the master branch of latexml appears to create rather decent XML for it, as in:

    <p>combined vbox: <inline-block framed="rectangle" vattach="bottom">
        <p vattach="bottom">1cm Box</p>
        <p vattach="bottom">2cm Box</p>
        <p vattach="bottom">3cm Box</p>
      </inline-block></p>

So I am also wondering if the lack of an unwrap isn't already handled reasonably enough...

dginev avatar Dec 27 '24 17:12 dginev

New approach ready for review.

Studying a couple of examples more closely, I think the main issue is with having too much verbosity in the XML wrappers, especially as the \un* primitives explicitly are unwrapping requests.

Luckily, the insertBlock utility already has code that smartly unwraps unneeded containers, but it requires that no new properties are required on the container.

So, I added a special property _unwrap_block for the \un* primitives, which \vbox and \vtop consult to call insertBlock without any props. Which in turn leads to no additional container nodes, and no verbosity from vattach="bottom" attributes.

dginev avatar Dec 28 '24 00:12 dginev

Closing in favour of doing TeX right :>

dginev avatar Jun 13 '25 18:06 dginev