Skip to content

Commit

Permalink
reimplement \llap, \rlap using CSS float
Browse files Browse the repository at this point in the history
  • Loading branch information
xworld21 committed Jan 5, 2025
1 parent f82b733 commit 38d0934
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 24 deletions.
5 changes: 2 additions & 3 deletions lib/LaTeXML/Engine/plain.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,8 @@ DefConstructor('\ltx@centerline{}', sub {
alias => '\centerline',
bounded => 1);

# These should be 0 width, but perhaps also shifted?
DefMacro('\llap{}', '\hbox to 0pt{\hss#1}');
DefMacro('\rlap{}', '\hbox to 0pt{#1\hss}');
DefMacro('\llap{}', '\hbox{\@ADDCLASS{ltx_llap}#1}');
DefMacro('\rlap{}', '\hbox{\@ADDCLASS{ltx_rlap}#1}');

DefMacroI('\m@th', undef, '\mathsurround=0pt ');

Expand Down
6 changes: 6 additions & 0 deletions lib/LaTeXML/resources/CSS/LaTeXML.css
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,9 @@ cite { font-style: normal; }

.ltx_overlay {position:relative; }
.ltx_overlay > span:nth-child(2) {position:absolute; left:0; }

/* \llap, \rlap */
.ltx__lap_container {
display:inline-block; vertical-align:bottom; width:0pt; white-space:nowrap; /* width 0pt causes extreme wrapping otherwise */ }
.ltx__lap_container>.ltx_llap { float:right; }
.ltx__lap_container>.ltx_rlap { float:left; }
51 changes: 35 additions & 16 deletions lib/LaTeXML/resources/XSLT/LaTeXML-inline-xhtml.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,41 @@
<xsl:preserve-space elements="ltx:text"/>
<xsl:template match="ltx:text">
<xsl:param name="context"/>
<xsl:element name="span" namespace="{$html_ns}">
<xsl:variable name="innercontext" select="'inline'"/><!-- override -->
<xsl:call-template name="add_id"/>
<xsl:call-template name="add_attributes">
<xsl:with-param name="extra_classes" select="f:if(@width,'ltx_inline-block','')"/>
</xsl:call-template>
<xsl:apply-templates select="." mode="begin">
<xsl:with-param name="context" select="$innercontext"/>
</xsl:apply-templates>
<xsl:apply-templates>
<xsl:with-param name="context" select="$innercontext"/>
</xsl:apply-templates>
<xsl:apply-templates select="." mode="end">
<xsl:with-param name="context" select="$innercontext"/>
</xsl:apply-templates>
</xsl:element>
<xsl:variable name="content">
<xsl:element name="span" namespace="{$html_ns}">
<xsl:variable name="innercontext" select="'inline'"/><!-- override -->
<xsl:call-template name="add_id"/>
<xsl:call-template name="add_attributes">
<xsl:with-param name="extra_classes" select="f:if(@width,'ltx_inline-block','')"/>
</xsl:call-template>
<xsl:apply-templates select="." mode="begin">
<xsl:with-param name="context" select="$innercontext"/>
</xsl:apply-templates>
<xsl:apply-templates>
<xsl:with-param name="context" select="$innercontext"/>
</xsl:apply-templates>
<xsl:apply-templates select="." mode="end">
<xsl:with-param name="context" select="$innercontext"/>
</xsl:apply-templates>
</xsl:element>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(concat(' ',@class,' '),' ltx_llap ')">
<xsl:element name="span" namespace="{$html_ns}">
<xsl:attribute name="class">ltx__lap_container</xsl:attribute>
<xsl:copy-of select="$content" />
</xsl:element>
</xsl:when>
<xsl:when test="contains(concat(' ',@class,' '),' ltx_rlap ')">
<xsl:element name="span" namespace="{$html_ns}">
<xsl:attribute name="class">ltx__lap_container</xsl:attribute>
<xsl:copy-of select="$content" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$content" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- Special case: all OTHER attributes have to be outside the "hidden"
Expand Down
2 changes: 1 addition & 1 deletion t/alignment/halignatt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<td border="l t" class="ltx_nopad_l ltx_nopad_r"/>
<td align="right" border="r t">6</td>
<td align="center" border="r t">51–59</td>
<td align="right" border="r t">.95<text width="0.0pt">*</text></td>
<td align="right" border="r t">.95<text class="ltx_rlap" width="0.0pt">*</text></td>
</tr>
<tr>
<td align="left" border="t" class="ltx_nopad_l ltx_nopad_r" colspan="4">* (first quarter only)</td>
Expand Down
6 changes: 3 additions & 3 deletions t/ams/mathtools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7120,7 +7120,7 @@ Then a switch of tag forms.</p>
<title><tag close=" ">11</tag>Stepped lines</title>
<para xml:id="S11.p1">
<equation xml:id="S11.Ex81">
<Math class="ltx_math_unparsed" mode="display" tex="\begin{gathered}x=1,\quad x+1=2\\&#10;y=2\end{gathered}" text="[1∗  ]@x@=@1@,@quad@x@+@1@=@2@[ over]@[2∗  ]@y@=@2@[ over]" xml:id="S11.Ex81.m1">
<Math class="ltx_math_unparsed" mode="display" tex="\begin{gathered}x=1,\quad x+1=2\\&#10;y=2\end{gathered}" text="[1∗  ]@x@=@1@,@quad@x@+@1@=@2@[ over]@[2∗  ]@y@=@2@[ over]" xml:id="S11.Ex81.m1">
<XMath>
<XMDual>
<XMWrap rule="Anything,">
Expand Down Expand Up @@ -7150,7 +7150,7 @@ Then a switch of tag forms.</p>
<XMTok meaning="equals" role="RELOP" xml:id="S11.Ex81.m1.3">=</XMTok>
<XMApp>
<XMTok meaning="times" role="MULOP">⁢</XMTok>
<XMText xml:id="S11.Ex81.m1.1"><text width="0.0pt">1</text><Math mode="inline" tex="*" text="*" xml:id="S11.Ex81.m1.m1">
<XMText xml:id="S11.Ex81.m1.1"><text class="ltx_llap" width="0.0pt">​<text class="ltx_llap_content">1</text></text><Math mode="inline" tex="*" text="*" xml:id="S11.Ex81.m1.m1">
<XMath>
<XMTok meaning="times" role="MULOP">∗</XMTok>
</XMath>
Expand Down Expand Up @@ -7182,7 +7182,7 @@ Then a switch of tag forms.</p>
<XMTok meaning="equals" role="RELOP" xml:id="S11.Ex81.m1.14">=</XMTok>
<XMApp>
<XMTok meaning="times" role="MULOP">⁢</XMTok>
<XMText xml:id="S11.Ex81.m1.12"><text width="0.0pt">2</text><Math mode="inline" tex="*" text="*" xml:id="S11.Ex81.m1.m2">
<XMText xml:id="S11.Ex81.m1.12"><text class="ltx_llap" width="0.0pt">​<text class="ltx_llap_content">2</text></text><Math mode="inline" tex="*" text="*" xml:id="S11.Ex81.m1.m2">
<XMath>
<XMTok meaning="times" role="MULOP">∗</XMTok>
</XMath>
Expand Down
2 changes: 1 addition & 1 deletion t/structure/plainsample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ finish the remaining cases.</p>
<XMTok role="CLOSE" stretchy="false">)</XMTok>
</XMWrap>
</XMDual>
<XMText width="0.0pt">Draft</XMText>
<XMText class="ltx_rlap" width="0.0pt">Draft</XMText>
</XMApp>
</XMath>
</Math></tag>
Expand Down

0 comments on commit 38d0934

Please sign in to comment.