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

use RTL to shift \llap content and fix \llap, \rlap extreme wrapping #2475

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xworld21
Copy link
Contributor

@xworld21 xworld21 commented Jan 3, 2025

Fix #2474 (?), unless you object to \@ADDCLASS here.

Edit: it's not enough if \llap is used at the beginning of a line. That requires something different. No, I was fooled by the mathtools test. The problem with mathtools is that the ltx_llap class is lost when replacing ltx:text with mpadded, along with the inner wrapper. If you add the class manually, it works exactly as it should. Loss of classes is a separate bug.

@xworld21 xworld21 marked this pull request as draft January 3, 2025 20:28
@dginev dginev requested a review from brucemiller January 3, 2025 20:42
@dginev
Copy link
Collaborator

dginev commented Jan 3, 2025

@xworld21 I am not sure the RTL trick doesn't stray a bit too far from its original CSS purpose. I have recently been playing around with the float: property, which may be a little closer to the TeXbook description:

‘\llap{something}’ creates a box of width zero,
with ‘something’ extending just to the left of that box.

This indeed works on all kinds of content, including tables and equations.

I tried a simple TeX snippet:

testing some \llap{llap} and \rlap{rlap} text here.
\bye

and hand-crafted some HTML using float: and your class-based approach. This result appears to match the PDF perfectly:

<html>
  <style>
    .llap-container,
    .rlap-container {
      width: 0;
      display: inline-block;
      vertical-align: bottom;
    }
    .llap {
      float: right;
    }
    .rlap {
      float: left;
    }
  </style>
  <body>
    <p>testing some <span class="llap-container"><span class="llap">llap</span></span> 
and <span class="rlap-container"><span class="rlap">rlap</span></span> text here.
    </p>
    </body>
</html>

That said, I suspect the usual way of applying these macros will be really bad for accessible outcomes (especially screen readers), as the CSS trickery never carries to the accessibility tree. So I would also discourage basing any important new work on these macros...

@dginev
Copy link
Collaborator

dginev commented Jan 3, 2025

A related aside to my last comment: being able to deduce the context of \hss use and map that to a class attribute that floats the outcome left/right, or centers it (for \hss #1 \hss), also seems to me to be as useful as having functional \llap and \rlap.

@xworld21
Copy link
Contributor Author

xworld21 commented Jan 4, 2025

    .llap {
      float: right;
    }

That is infinitely better, thanks!

I am wondering if we should just promote \llap to an inline-block constructor with sizer => 0 and let XSLT create the wrappers when it sees ltx_[lr]lap. It should solve multiple problems at once – no need to hack around with the zero-width space, the inline width can be moved to the class, and it is more semantic.

That said, I suspect the usual way of applying these macros will be really bad for accessible outcomes (especially screen readers), as the CSS trickery never carries to the accessibility tree. So I would also discourage basing any important new work on these macros...

The tests include a few legit cases about preserving alignment (and, well, I bumped into this with the raw beamer stuff) which should work fine with screen readers I think. I assume screen readers read floats in a sensible way. I'll check. As to using \llap for e.g. creating new symbols, yeah, the output won't make sense accessibility wise.

@xworld21
Copy link
Contributor Author

xworld21 commented Jan 4, 2025

That is infinitely better, thanks!

Oh, I take that back. Vertical alignment changes with float, and if you add text-decoration: underline the difference is quite visible. The rtl trick has the advantage of keeping the text on the same line.

@dginev
Copy link
Collaborator

dginev commented Jan 4, 2025

I am not sure I follow. Adding text-decoration: underline; to the example I shared seems to display well? As in, it matches a PDF where \underline was used in the source.

Maybe it wasn't obvious - I had added vertical-align: bottom; to restore the alignment. There could be trickier cases, would be nice to translate those into tricky tests.

@xworld21
Copy link
Contributor Author

xworld21 commented Jan 4, 2025

Maybe it wasn't obvious - I had added vertical-align: bottom; to restore the alignment. There could be trickier cases, would be nice to translate those into tricky tests.

I... I did get two misaligned underlines before, but I can't reproduce it again! I guess I must have changed the inline block size accidentally (most likely with some debug border), and that would have the same effect on direction:rtl, most likely. Back to floats it is until we find an actual reproducible problem.

<xsl:with-param name="context" select="$innercontext"/>
</xsl:apply-templates>
</xsl:element>
<xsl:variable name="content">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just proof of concept, this would have to be implemented for ltx:inline-block and ltx:p too (the other possible constructors from \hbox).

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.

\llap does not shift to the left, creates newlines
2 participants