Skip to content

Commit 969fbd9

Browse files
committed
When in svg: Create new svg:g for \kern when already have siblings; But, make \hbox close to the appropriate svg:g; And make auto opened svg:g able to auto close
1 parent 3c7b20d commit 969fbd9

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

lib/LaTeXML/Engine/TeX_Box.pool.ltxml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ DefConstructor('\hbox BoxSpecification HBoxContents', sub {
270270
no warnings 'recursion';
271271
my ($document, $spec, $contents, %props) = @_;
272272
my $model = $document->getModel;
273-
my $context = $document->getElement;
274-
my $current = $context;
273+
my $current = $document->getElement;
275274

276275
# What is the CORRECT (& general) way to ask whether we're in "vertical mode"??
277276
# my $vmode = $tag eq 'ltx:inline-block'; # ie, explicitly \vbox !?!?!?!
@@ -281,13 +280,10 @@ DefConstructor('\hbox BoxSpecification HBoxContents', sub {
281280
my $newtag = ($issvg ? 'svg:g' : ($vmode ? ($inline ? 'ltx:inline-block' : 'ltx:p') : 'ltx:text'));
282281
my $node = $document->openElement($newtag, _noautoclose => 1, width => $props{width});
283282
$document->absorb($contents);
284-
if (!$issvg) {
283+
if (!$issvg) { # If not directly svg, but nested within closeable (???)
285284
while (!$document->getElement()->hasAttribute('_beginscope') && $document->maybeCloseElement('svg:g')) { }
286285
$document->maybeCloseElement('svg:svg'); }
287-
if ($issvg) { # ODDLY, svg:g isnt necessarily balanced in tikz?
288-
$document->maybeCloseElement('svg:g'); }
289-
else {
290-
$document->maybeCloseNode($node); }
286+
$document->maybeCloseNode($node);
291287
},
292288
mode => 'text', bounded => 1,
293289
sizer => '#2',

lib/LaTeXML/Engine/TeX_Kern.pool.ltxml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ use LaTeXML::Package;
2727
# \lastkern iq is 0.0 pt or the last kern on the current list.
2828

2929
# \kern is heavily used by xy.
30-
# Completely HACK version for the moment
3130
# Note that \kern should add vertical spacing in vertical modes!
3231
DefConstructor('\kern Dimension', sub {
3332
my ($document, $length, %props) = @_;
3433
my $parent = $document->getNode;
3534
if ($document->getNodeQName($parent) eq 'svg:g') {
3635
if (my $x = $length->pxValue) {
37-
# HACK HACK HACK
38-
my $transform = $parent->getAttribute('transform');
39-
$parent->setAttribute(transform => ($transform ? $transform . ' ' : '') . "translate($x,0)");
40-
} }
36+
my $shift = "translate($x,0)";
37+
if($parent->childNodes){ # If already have positioned children, new svg:g
38+
$document->openElement('svg:g', _autoclose=>1, transform => $shift); }
39+
else {
40+
my $prev = $parent->getAttribute('transform');
41+
$parent->setAttribute(transform => ($prev ? "$prev $shift" : $shift)); } } }
4142
elsif (inSVG()) {
4243
Warn('unexpected', 'kern', $_[0], "Lost kern in SVG " . ToString($length)); }
4344
elsif ($props{isMath}) {

lib/LaTeXML/Package/pgfsys-latexml.def.ltxml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ DefConstructor('\lxSVG@drawpath@clipped{}{}',
340340
. '<svg:path id="pgfpath#obj" d="#1" />'
341341
. '</svg:clipPath>'
342342
. '<svg:use xlink:href="##pgfpath#obj" style="#2" />'
343-
. '<svg:g clip-path="url(##pgfcp#obj)">',
343+
. '<svg:g clip-path="url(##pgfcp#obj)" _autoclose="1">',
344344
reversion => '', sizer => 0,
345345
properties => { obj => sub { SVGNextObject(); } });
346346

@@ -363,7 +363,7 @@ DefConstructor('\lxSVG@discardpath@clipped{}',
363363
'<svg:clipPath id="pgfcp#obj">'
364364
. '<svg:path d="#1" />'
365365
. '</svg:clipPath>'
366-
. '<svg:g clip-path="url(##pgfcp#obj)">',
366+
. '<svg:g clip-path="url(##pgfcp#obj)" _autoclose="1">',
367367
reversion => '', sizer => 0,
368368
properties => { obj => sub { SVGNextObject(); } });
369369

@@ -387,8 +387,8 @@ DefConstructor('\lxSVG@begingroup@ RequiredKeyVals', sub {
387387
# Special case check: if we are in a latexml context, move up to parent svg:g
388388
if ($doc->getNodeQName($this) =~ /^ltx:/
389389
&& (my $g = $doc->findnode("ancestor::svg:g[position()=1]", $this))) {
390-
$doc->openElement('svg:svg', _autoopened => 1); }
391-
$doc->openElement('svg:g', $kv->getHash); },
390+
$doc->openElement('svg:svg', _autoopened => 1, _autoclose => 1); }
391+
$doc->openElement('svg:g', $kv->getHash, _autoclose => 1); },
392392
reversion => '', sizer => 0);
393393

394394
#=====================================================================
@@ -534,7 +534,7 @@ DefConstructor('\lxSVG@setpatternuncolored@{}{}{}{}',
534534
. '<svg:use xlink:href="##pgfsym#1"/>'
535535
. '</svg:g>'
536536
. '</svg:pattern></svg:defs>'
537-
. '<svg:g fill="url(##pgfupat#obj)">',
537+
. '<svg:g fill="url(##pgfupat#obj)" _autoclose="1">',
538538
properties => {
539539
obj => sub { SVGNextObject(); },
540540
color => sub { Color('rgb', $_[2], $_[3], $_[4]); } },

0 commit comments

Comments
 (0)