From 328bd8e6cdd2a738c1ce553d2c958e998cbfe85d Mon Sep 17 00:00:00 2001 From: Bruce Miller Date: Fri, 29 Nov 2024 14:23:52 -0500 Subject: [PATCH] Have \hskip revert back to a common command, when possible --- lib/LaTeXML/Engine/TeX_Glue.pool.ltxml | 30 ++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/LaTeXML/Engine/TeX_Glue.pool.ltxml b/lib/LaTeXML/Engine/TeX_Glue.pool.ltxml index 7e8223c06..7aa00e393 100644 --- a/lib/LaTeXML/Engine/TeX_Glue.pool.ltxml +++ b/lib/LaTeXML/Engine/TeX_Glue.pool.ltxml @@ -26,20 +26,21 @@ use LaTeXML::Package; # \vskip c inserts vertical glue in a vertical list. # \unskip c removes a glue item from the current list. -our @spaces = ( # Spaces to fake spacing, with width in ems - [0.100, "\x{200A}"], # Hair space (thinner than thin space) - [0.167, "\x{2006}"], # six-per-em - [0.200, "\x{2009}"], # five-per-em, thin space - [0.250, "\x{2005}"], # four-per-em, mid space - [0.333, "\x{2004}"], # three-per-em, thick space - [0.500, "\x{2002}"], # en-quad, "nut" - [1.000, "\x{2003}"], # em-quad, "mutton" +our @spaces = ( # Spaces to fake spacing, with width in ems, along with the common command + [0.100, "\x{200A}"], # Hair space (thinner than thin space) + [0.167, "\x{2006}"], # six-per-em + [0.200, "\x{2009}", T_CS('\thinspace')], # five-per-em, thin space + [0.250, "\x{2005}", T_CS('\>')], # four-per-em, mid space + [0.333, "\x{2004}", T_CS('\;')], # three-per-em, thick space + [0.500, "\x{2002}", T_CS('\enspace')], # en-quad, "nut" + [1.000, "\x{2003}", T_CS('\quad')], # em-quad, "mutton" + [2.000, "\x{2003}\x{2003}", T_CS('\qquad')], ); # String of spacing chars with width roughly equivalent to $dimen sub DimensionToSpaces { my ($dimen) = @_; - my $fs = LookupValue('font')->getSize; # 1 em + my $fs = LookupValue('font')->getSize; # 1 em my $ems = $dimen->ptValue / $fs; my $s = ''; for (my $i = $#spaces ; ($i >= 0) && ($ems > 0) ; $i--) { @@ -49,6 +50,16 @@ sub DimensionToSpaces { $ems -= $n * $w; $s .= $spaces[$i][1] x $n; } } return $s; } +# Revert a skip to it's (common) command, falling back to a generic \hskip +sub revertSkip { + my ($command, $dimen) = @_; + my $fs = LookupValue('font')->getSize; # 1 em + my $ems = $dimen->ptValue / $fs; + for (my $i = 0 ; ($i <= $#spaces) ; $i++) { + next if ($ems > $spaces[$i][0] + 0.01) || !$spaces[$i][2]; + return $spaces[$i][2] if $ems < $spaces[$i][0] + 0.01; } + return Invocation($command, $dimen); } + # \hskip handled similarly to \kern # \hskip can be ignored in certain situations... DefConstructor('\hskip Glue', sub { @@ -68,6 +79,7 @@ DefConstructor('\hskip Glue', sub { else { # $document->openText(DimensionToSpaces($length), $props{font}); } }, $document->absorb(DimensionToSpaces($length)); } }, + reversion => sub { revertSkip(T_CS('\hskip'), $_[1]); }, properties => sub { my ($stomach, $length) = @_; (width => $length, isSpace => 1, isSkip => 1); });