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 does not unbox the box #2458

Open
xworld21 opened this issue Dec 26, 2024 · 3 comments · May be fixed by #2459
Open

\unvbox does not unbox the box #2458

xworld21 opened this issue Dec 26, 2024 · 3 comments · May be fixed by #2459

Comments

@xworld21
Copy link
Contributor

Couldn't let it sit until after the bank holidays for obvious reasons.

The implementation of the \un*box commands is wrong at

DefPrimitive('\unvbox Number', sub {
my $box = 'box' . $_[1]->valueOf;
my $stuff = LookupValue($box);
adjustBoxColor($stuff);
AssignValue($box, undef);
(defined $stuff ? $stuff->unlist : List()); });

They should replace the boxes with their contexts, but $stuff->unlist is typically a one element list consisting of the <ltx:block> wrapper. The difference is visible here:

\documentclass{article}
\newbox\mybox
\begin{document}
  Vertical box below.

  \setbox\mybox=\vbox spread 3cm{This box is 3cm high}\box\mybox

  Another vertical box below, or is it?

  \setbox\mybox=\vbox spread 3cm{This box should be 3cm high.}\unvbox\mybox

  Was it 3cm?
\end{document}

The XML output may look the same (LaTeXML won't save the height), but the @vattach attribute is the visible symptom that the box has not been unwrapped.

A hasty workaround is to call $whatsit->getArg(2) instead of ->unlist, and to stick some kind of newline (\nointerlineskip?). A proper solution should at least involve some error checking (TeX throws an error when the box types are mismatched, e.g. \mybox=\hbox{}\unvbox\mybox) and some thinking about the type of newline required. I haven't checked the TeX book for the details.

(Raw beamer uses a lot of \unvbox and it creates nested blocks like there's no tomorrow. ->getArg(2) flattens the output nicely which suggests I am generally right.)

@dginev dginev added this to the LaTeXML-0.8.9 milestone Dec 26, 2024
@dginev
Copy link
Collaborator

dginev commented Dec 27, 2024

This may have to do with latexml's still evolving model of how a \vbox is represented at the digestion stage. Currently the contents are stored inside a Whatsit property, called content_box. I recall Bruce and I discussed that at times earlier in 2024, but can't recall too many of the details at present...

But a thought that comes to mind is that if the box contents are in that property, we may want to upgrade the Whatsit::unlist method to recurse into those. As in:

# in lib/LaTeXML/Core/Whatsit.pm
sub unlist {
  my ($self) = @_;
  if (my $box = $self->getProperty('content_box')) {
    return $box->unlist; }
  else {
    return ($self); } }

I am not quite confident that this is correct, so adding it as a comment for now.

Edit: If this approach is deemed reasonable, I made PR #2459 for an easy resolution.


Aside 1: latexml also stores the spread of a \vbox in the whatsit height attribute, but that doesn't appear to be added to a ltx:para. In my mind that also ties into other discussions about absolute widths and heights reaching the HTML, and thinking of ways to preserve that information while allowing responsive CSS styling.

Aside 2: Interpreting beamer raw sounds a little bit too low-level @xworld21 . Are you starting a new beamer binding from scratch, or are you thinking of upgrading the beamer.cls.ltxml that was contributed in #1652 ?

@dginev dginev linked a pull request Dec 27, 2024 that will close this issue
@xworld21
Copy link
Contributor Author

Aside 2: Interpreting beamer raw sounds a little bit too low-level @xworld21 . Are you starting a new beamer binding from scratch, or are you thinking of upgrading the beamer.cls.ltxml that was contributed in #1652 ?

I am not sure where I am going with this, yet. I thought I would read raw the TODO items of the existing binding, but I discovered that raw beamer is feasible (except it takes 30 seconds to load beamer! :( ). Also, I am strongly interested in visual accuracy over e.g. responsiveness, at least in the very short term.

@dginev
Copy link
Collaborator

dginev commented Dec 27, 2024

Studying the markup problem, I found an example:

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

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

Which in the PDF simply has 4 lines (two pairs of two) on top of each other.
In the XML, today's latexml creates:

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

Is the main request of this issue to reduce that to:

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

If so, I can see how this could also be done as a DefRewrite ...

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

Successfully merging a pull request may close this issue.

2 participants