Skip to content

Commit 0cb41c2

Browse files
authored
Better \kern in svg (#2533)
* 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 * Add an xy test case * Fix xytest requires xy.sty to run
1 parent 8575159 commit 0cb41c2

File tree

8 files changed

+206
-18
lines changed

8 files changed

+206
-18
lines changed

MANIFEST

+3
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,9 @@ t/graphics/picture.xml
13991399
t/graphics/xcolors.pdf
14001400
t/graphics/xcolors.tex
14011401
t/graphics/xcolors.xml
1402+
t/graphics/xytest.pdf
1403+
t/graphics/xytest.tex
1404+
t/graphics/xytest.xml
14021405
t/grouping/mathgroup.pdf
14031406
t/grouping/mathgroup.tex
14041407
t/grouping/mathgroup.xml

lib/LaTeXML/Engine/TeX_Box.pool.ltxml

+3-7
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

+6-5
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

+5-5
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]); } },

t/65_graphics.t

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ use LaTeXML::Util::Test;
66

77
latexml_tests("t/graphics",
88
requires=>{colors=>'dvipsnam.def',
9-
xcolors=>'dvipsnam.def'});
9+
xcolors=>'dvipsnam.def',
10+
xytest=>'xy.sty'});

t/graphics/xytest.pdf

41.5 KB
Binary file not shown.

t/graphics/xytest.tex

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
\documentclass{article}
2+
\usepackage{xcolor}
3+
\usepackage[arrow,curve,matrix]{xy}
4+
\begin{document}
5+
6+
\xy (3,0)*{A} ; (20,6)*+{B}*\cir{} **\dir{-} \endxy
7+
8+
\xymatrix{
9+
U \ar@/_/[ddr]_y \ar[dr] \ar@/^/[drr]^x\\
10+
& X \times_Z Y \ar[d]^q \ar[r]_p
11+
& X \ar[d]_f \\
12+
& Y \ar[r]^g & Z }
13+
14+
\end{document}

0 commit comments

Comments
 (0)