From cdf3a80bd61c06b1d703a562435dc0c4ed7cf180 Mon Sep 17 00:00:00 2001 From: Vincenzo Mantova Date: Mon, 6 Jan 2025 21:31:49 +0000 Subject: [PATCH] implement TikZ/PGF baseline support --- lib/LaTeXML/Package/pgfsys-latexml.def.ltxml | 12 ++++++++---- lib/LaTeXML/resources/XSLT/LaTeXML-picture-xhtml.xsl | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/LaTeXML/Package/pgfsys-latexml.def.ltxml b/lib/LaTeXML/Package/pgfsys-latexml.def.ltxml index cb3b86b0d..b562bb2a7 100644 --- a/lib/LaTeXML/Package/pgfsys-latexml.def.ltxml +++ b/lib/LaTeXML/Package/pgfsys-latexml.def.ltxml @@ -77,13 +77,15 @@ DefConstructor('\lxSVG@insertpicture{}', sub { if ($document->getNodeQName($current) =~ /^svg:/) { # Already in svg:svg ? # Seemingly this positioning is correct; otherwise inherit from context my ($x, $y) = (-$props{minx}, -$props{miny}); + $y -= $props{depth}->pxValue if $props{depth}->pxValue; my $gnode = $document->openElement('svg:g', transform => "matrix(1 0 0 1 $x $y)", _scopebegin => 1, class => 'ltx_nestedsvg'); $document->absorb($content); $document->closeElement('svg:g'); } else { - $document->openElement('ltx:picture'); + my $picture = $document->openElement('ltx:picture'); + $document->setAttribute($picture, 'imagedepth', $props{depth}->pxValue) if $props{depth}->pxValue; $document->openElement('svg:svg', version => "1.1", width => $props{pxwidth}, height => $props{pxheight}, @@ -114,12 +116,13 @@ DefConstructor('\lxSVG@insertpicture{}', sub { my $miny = LookupRegister('\pgf@picminy'); my $width = LookupRegister('\pgf@picmaxx'); my $height = LookupRegister('\pgf@picmaxy'); + my $depth = Dimension(Expand(T_CS('\pgf@shift@baseline'))); my $w = max($width->pxValue, 1); my $h = max($height->pxValue, 1); my $content = $whatsit->getArg(1); my ($cwidth, $cheight, $cdepth) = $content->getSize; - Debug("TIKZ size: " . ToString($width) . " x " . ToString($height)) if $LaTeXML::DEBUG{pgf}; - Debug("TIKZ pos: " . ToString($minx) . " x " . ToString($miny)) if $LaTeXML::DEBUG{pgf}; + Debug("TIKZ size: " . ToString($width) . " x " . ToString($height) . " + " . ToString($depth)) if $LaTeXML::DEBUG{pgf}; + Debug("TIKZ pos: " . ToString($minx) . " x " . ToString($miny)) if $LaTeXML::DEBUG{pgf}; Debug("TIKZ BODY: " . ToString($cwidth) . " x " . ToString($cheight) . " + " . ToString($cdepth)) if $LaTeXML::DEBUG{pgf}; Debug("BODY is " . ToString($content)) if $LaTeXML::DEBUG{pgf}; @@ -130,7 +133,7 @@ DefConstructor('\lxSVG@insertpicture{}', sub { $whatsit->setProperty(miny => 0); $whatsit->setProperty(width => $width); $whatsit->setProperty(height => $height); - $whatsit->setProperty(depth => Dimension(0)); + $whatsit->setProperty(depth => $depth->add($miny->negate)); $whatsit->setProperty(pxwidth => $w); $whatsit->setProperty(pxheight => $h); # or tikz macro (see corescopes) @@ -756,6 +759,7 @@ DefMacro('\pgfsys@shadingoutsidepgfpicture{}', <<'EoTeX'); \pgf@picminy=0pt% \pgf@picmaxx=\pgf@x% \pgf@picmaxy=\pgf@y% + \def\pgf@shift@baseline{0pt}% \pgfsys@typesetpicturebox{\pgfpic}% \endgroup EoTeX diff --git a/lib/LaTeXML/resources/XSLT/LaTeXML-picture-xhtml.xsl b/lib/LaTeXML/resources/XSLT/LaTeXML-picture-xhtml.xsl index bf2adae2f..c04406002 100644 --- a/lib/LaTeXML/resources/XSLT/LaTeXML-picture-xhtml.xsl +++ b/lib/LaTeXML/resources/XSLT/LaTeXML-picture-xhtml.xsl @@ -95,6 +95,15 @@ + + + + + ; + + + +