Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\unvbox and friends request a block unwrap #2459

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dginev
Copy link
Collaborator

@dginev dginev commented Dec 27, 2024

Fixes #2458 .

Copy link
Contributor

@xworld21 xworld21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three quick comments related to the originating issue:

  • could there be any data in the wrapper box that gets lost in this way? in TeX, a box is merely a box, but is that true for LaTeXML?
  • \unvbox and \unvcopy must also switch to vertical mode, or it will cause other unintended side effects (per TeX book 'The vertical list inside that box is appended to the current vertical list, without changing it in any way')
  • the \un.(copy|box) commands should error out if the box is of the wrong horizontal/vertical type

@dginev
Copy link
Collaborator Author

dginev commented Dec 27, 2024

@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.

@xworld21
Copy link
Contributor

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.

@dginev
Copy link
Collaborator Author

dginev commented Dec 27, 2024

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 dginev marked this pull request as draft December 27, 2024 18:25
@dginev dginev marked this pull request as ready for review December 28, 2024 00:11
@dginev dginev changed the title unlist Whatsit recurses into content_box \unvbox and friends request a block unwrap Dec 28, 2024
@dginev
Copy link
Collaborator Author

dginev commented Dec 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

\unvbox does not unbox the box
2 participants