Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgfmath and pgfplots enhancements #2237

Merged
merged 18 commits into from
Jan 6, 2024

Conversation

dginev
Copy link
Collaborator

@dginev dginev commented Oct 16, 2023

This is a draft PR, which may already benefit from some visibility/discussion.

I started with a motivating issue ar5iv#390, which caught an important oversight with the perl-eval optimization for pgfmath. Namely, the ^ is a valid char in both pgf and perl, but it means binary-xor in perl, and a classic power in pgf.

I also spotted the reports of the precision errors, where a $T_\x$ was getting typeset as $T_{0.000000}$ instead of $T_0$, where the \x was computed via pgfmathparse. Which lead me down a deeper rabbit hole, and added the falling dominoes test to my tests. That example also revealed that expressions such as 3*sin \x are validly parse-able - here as 3*(sin(\x)) - so I added a grammar case for a function call on a bare argument.

The PR now includes a first pgfmath unit test, which is gradually growing in coverage of the math operators, in order to try and get closer to the precision and eval-accuracy of the native pgf driver.

I have some more work in increasing that test's coverage, and then I'd like to try some more diverse tests, to ensure I didn't cause some unexpected regressions. But the original issue in the ar5iv report should already be patched here.

@dginev dginev marked this pull request as draft October 16, 2023 23:07
@dginev
Copy link
Collaborator Author

dginev commented Oct 17, 2023

Studying some adjacent issues in the ar5iv reports I also spotted a few important discrepancies in our pgfmath bindings as used by pgfplots, specifically in ar5iv#335, which is based on arXiv:2201.11903. The last batch of commits resolves the interpretation issues of the pgf figures there fully - gradually adding some tests as well.

@dginev
Copy link
Collaborator Author

dginev commented Oct 17, 2023

The dominoes test also renders perfectly now. Which allows the distraction of noticing text size (= domino numbers) is a just a little large. That is also the case for the axes labels in the pgfplots examples.

In ar5iv, I currently have a CSS directive anchored at foreignObject .ltx_text and I seem to get really good outcomes for the handful of tests here if I add a property font-size: 0.9em.

But I am recording that only as an informal comment for now, since I am unsure if there is a general sizing distinction, or this is limited to a few special cases of examples.

@dginev
Copy link
Collaborator Author

dginev commented Nov 20, 2023

The last commit ccd423f fixes dginev/ar5iv#318 and dginev/ar5iv#402

Edit: as well as dginev/ar5iv#175 and dginev/ar5iv#149
Edit 2: as well as dginev/ar5iv#139 and dginev/ar5iv#94

@dginev dginev changed the title pgfmath enhancements pgfmath and pgfplots enhancements Nov 20, 2023
<resource src="LaTeXML.css" type="text/css"/>
<resource src="ltx-article.css" type="text/css"/>
<para xml:id="p1">
<picture height="191.5" tex="\hbox to219.56pt{\vbox to138.4pt{\pgfpicture\makeatletter\raise 0.0pt\hbox{%&#10;\hskip 32.25624pt\lower-16.86601pt\hbox to0.0pt{\pgfsys@beginscope%&#10;\pgfsys@invoke{ }\definecolor{pgfstrokecolor}{rgb}{0,0,0}%&#10;\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }\pgfsys@color@rgb@fill{0}{0}%&#10;{0}\pgfsys@invoke{ }\pgfsys@setlinewidth{0.4pt}\pgfsys@invoke{ }\nullfont\hbox&#10;to%&#10;0.0pt{\pgfsys@beginscope\pgfsys@invoke{ }\par{}{{}}{}&#10;{}{}{{}}{}{{&#10;{\pgfsys@beginscope\pgfsys@setlinewidth{0.32pt}\pgfsys@setdash{}{0.0pt}%&#10;\pgfsys@roundcap\pgfsys@roundjoin{}&#10;{}{}{}&#10;{}{}{}&#10;\pgfsys@moveto{-1.19998pt}{1.59998pt}\pgfsys@curveto{-1.09998pt}{0.99998pt}{0.%&#10;0pt}{0.09999pt}{0.29999pt}{0.0pt}\pgfsys@curveto{0.0pt}{-0.09999pt}{-1.09998pt%&#10;}{-0.99998pt}{-1.19998pt}{-1.59998pt}\pgfsys@stroke\pgfsys@endscope}}&#10;}{}{}{{}}\pgfsys@moveto{0.0pt}{0.0pt}\pgfsys@lineto{170.25656pt}{0.0pt}%&#10;\pgfsys@stroke\pgfsys@invoke{ }{{}{{}}{}{}{{}}{{{}}{{{}}{\pgfsys@beginscope%&#10;\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1.0}{170.25656pt}{0.0pt}%&#10;\pgfsys@invoke{ }\pgfsys@invoke{ \lxSVG@closescope }\pgfsys@invoke{%&#10;\lxSVG@closescope }\pgfsys@endscope}}{{}}}}\hbox{\hbox{{\pgfsys@beginscope%&#10;\pgfsys@invoke{ }{{}{}{{&#10;{}{}}}{&#10;{}{}}&#10;{{}{{}}}{{}{}}{}{{}{}}&#10;{&#10;}{{{{}}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1%&#10;.0}{157.46713pt}{-11.033pt}\pgfsys@invoke{ }\hbox{{\definecolor{pgfstrokecolor%&#10;}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }%&#10;\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{ }\hbox{{$f/f_{N}$}}&#10;}}\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;{}{{}}{}{{}}{}{{}}{}{{}}{}{{}}{}{{}}{}\pgfsys@moveto{0.0pt}{0.0pt}%&#10;\pgfsys@moveto{56.90552pt}{0.0pt}\pgfsys@moveto{113.81104pt}{0.0pt}%&#10;\pgfsys@stroke\pgfsys@invoke{ }\hbox{\hbox{\hbox{\hbox{{\pgfsys@beginscope%&#10;\pgfsys@invoke{ }{{}{}{{&#10;{}{}}}{&#10;{}{}}&#10;{{}{{}}}{{}{}}{}{{}{}}&#10;{&#10;}{{{{}}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1%&#10;.0}{-2.5pt}{-9.97743pt}\pgfsys@invoke{ }\hbox{{\definecolor{pgfstrokecolor}{%&#10;rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }%&#10;\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{ }\hbox{{0}}&#10;}}\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}\hbox{{\pgfsys@beginscope%&#10;\pgfsys@invoke{ }{{}{}{{&#10;{}{}}}{&#10;{}{}}&#10;{{}{{}}}{{}{}}{}{{}{}}&#10;{&#10;}{{{{}}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1%&#10;.0}{54.40552pt}{-9.97743pt}\pgfsys@invoke{ }\hbox{{\definecolor{pgfstrokecolor%&#10;}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }%&#10;\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{ }\hbox{{1}}&#10;}}\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}\hbox{{\pgfsys@beginscope%&#10;\pgfsys@invoke{ }{{}{}{{&#10;{}{}}}{&#10;{}{}}&#10;{{}{{}}}{{}{}}{}{{}{}}&#10;{&#10;}{{{{}}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1%&#10;.0}{111.31104pt}{-9.97743pt}\pgfsys@invoke{ }\hbox{{\definecolor{%&#10;pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }%&#10;\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{ }\hbox{{2}}&#10;}}\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;{}{{}}{}{{}}{}{{}}{}{{}}{}\pgfsys@moveto{28.45276pt}{99.58466pt}\pgfsys@moveto%&#10;{113.81104pt}{99.58466pt}\pgfsys@stroke\pgfsys@invoke{ }\hbox{\hbox{\hbox{{%&#10;\pgfsys@beginscope\pgfsys@invoke{ }{{}{}{{&#10;{}{}}}{&#10;{}{}}&#10;{{}{{}}}{{}{}}{}{{}{}}&#10;{&#10;}{{{{}}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1%&#10;.0}{7.5305pt}{97.15411pt}\pgfsys@invoke{ }\hbox{{\definecolor{pgfstrokecolor}{%&#10;rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }%&#10;\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{ }\hbox{{{\scriptsize Constant %&#10;flux}}}&#10;}}\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}\hbox{{\pgfsys@beginscope%&#10;\pgfsys@invoke{ }{{}{}{{&#10;{}{}}}{&#10;{}{}}&#10;{{}{{}}}{{}{}}{}{{}{}}&#10;{&#10;}{{{{}}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1%&#10;.0}{89.2624pt}{97.83466pt}\pgfsys@invoke{ }\hbox{{\definecolor{pgfstrokecolor}%&#10;{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }%&#10;\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{ }\hbox{{{\scriptsize Field %&#10;weakening}}}&#10;}}\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\par{}{{}}{}&#10;{}{}{{}}{}{}{}{}{{}}\pgfsys@moveto{0.0pt}{0.0pt}\pgfsys@lineto{0.0pt}{113.3510%&#10;4pt}\pgfsys@stroke\pgfsys@invoke{ }{{}{{}}{}{}{{}}{{{}}{{{}}{%&#10;\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{0.0}{1.0}{-1.0}{0.0}{0.%&#10;0pt}{113.35104pt}\pgfsys@invoke{ }\pgfsys@invoke{ \lxSVG@closescope }%&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}{{}}}}\hbox{\hbox{{%&#10;\pgfsys@beginscope\pgfsys@invoke{ }{{}{}{{{}{}}}{{}{}}&#10;{{}{{}}}{{}{}}{}{{}{}}&#10;{&#10;}{{{{}}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1%&#10;.0}{-28.92323pt}{111.3666pt}\pgfsys@invoke{ }\hbox{{\definecolor{%&#10;pgfstrokecolor}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }%&#10;\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{ }\hbox{{$U_{s},\varPsi_{s}$}}&#10;}}\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;{}{{}}{}&#10;{}{}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@setdash{0.4pt,2.0pt}{0.0pt}%&#10;\pgfsys@invoke{ }{}\pgfsys@moveto{56.90552pt}{0.0pt}\pgfsys@lineto{56.90552pt}%&#10;{113.81104pt}\pgfsys@stroke\pgfsys@invoke{ }&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope\par{}{{}}{}&#10;{}{}&#10;{}{}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@setlinewidth{0.8pt}%&#10;\pgfsys@invoke{ }{}\pgfsys@moveto{0.0pt}{0.0pt}\pgfsys@lineto{56.90552pt}{56.9%&#10;0552pt}\pgfsys@lineto{170.71655pt}{56.90552pt}\pgfsys@stroke\pgfsys@invoke{ }&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope{}{{}}{}{{}}{}\pgfsys@moveto%&#10;{28.45276pt}{42.67914pt}\pgfsys@stroke\pgfsys@invoke{ }\hbox{\hbox{{%&#10;\pgfsys@beginscope\pgfsys@invoke{ }{{}{}{{&#10;{}{}}}{&#10;{}{}}&#10;{{}{{}}}{{}{}}{}{{}{}}&#10;{&#10;}{{{{}}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1%&#10;.0}{23.18124pt}{39.86525pt}\pgfsys@invoke{ }\hbox{{\definecolor{pgfstrokecolor%&#10;}{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }%&#10;\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{ }\hbox{{$U_{s}$}}&#10;}}\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\par{}{{}}{}&#10;{}{}{}{{}{}}{{}{}{{{}{}{}}}}\pgfsys@beginscope\pgfsys@invoke{ }%&#10;\pgfsys@setlinewidth{0.8pt}\pgfsys@invoke{ }\pgfsys@setdash{3.0pt,3.0pt}{0.0pt%&#10;}\pgfsys@invoke{ }{}\pgfsys@moveto{0.0pt}{85.35828pt}\pgfsys@lineto{56.90552pt%&#10;}{85.35828pt}\pgfsys@curveto{69.7096pt}{72.5542pt}{113.81104pt}{28.45276pt}{17%&#10;0.71655pt}{28.45276pt}\pgfsys@stroke\pgfsys@invoke{ }&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope{}{{}}{}{{}}{}\pgfsys@moveto%&#10;{71.1319pt}{85.35828pt}\pgfsys@stroke\pgfsys@invoke{ }\hbox{\hbox{{%&#10;\pgfsys@beginscope\pgfsys@invoke{ }{{}{}{{&#10;{}{}}}{&#10;{}{}}&#10;{{}{{}}}{{}{}}{}{{}{}}&#10;{&#10;}{{{{}}\pgfsys@beginscope\pgfsys@invoke{ }\pgfsys@transformcm{1.0}{0.0}{0.0}{1%&#10;.0}{65.9305pt}{82.54439pt}\pgfsys@invoke{ }\hbox{{\definecolor{pgfstrokecolor}%&#10;{rgb}{0,0,0}\pgfsys@color@rgb@stroke{0}{0}{0}\pgfsys@invoke{ }%&#10;\pgfsys@color@rgb@fill{0}{0}{0}\pgfsys@invoke{ }\hbox{{$\varPsi_{s}$}}&#10;}}\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope}}}&#10;\par&#10;\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope{}{}{}\hss}%&#10;\pgfsys@discardpath\pgfsys@invoke{\lxSVG@closescope }\pgfsys@endscope\hss}}%&#10;\lxSVG@closescope\endpgfpicture}}" width="303.8" xml:id="p1.pic1">
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While studying the XML in the tests here, I have been wondering if we should add a switch to disable the tex attribute in the <picture> element, especially when they come from some pgf/tikz source.

The expanded low-level pgf instructions get overwhelming quite quickly, and contain LaTeXML-only macros (such as \lxSVG@close) so they won't be reusable in other, non-latexml, contexts.

But even if we keep them in general, I can imagine various spurious diffs in these tests later on, e.g. if we refactor internal macro names.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, interesting: all the more so since the exact source snippets differ between texlives. I generated the tests on texlive 2022, and our 2018-2021 CI versions all failed on the source line.

@dginev dginev requested a review from brucemiller December 27, 2023 17:36
@dginev dginev marked this pull request as ready for review December 27, 2023 17:37
@dginev
Copy link
Collaborator Author

dginev commented Dec 27, 2023

@brucemiller the newly added pgf and tikz tests are now part of the extratest target and only run with:

CI=true make extratest

That should allow some freedom to move until we have figured out how to make the XML easy to regenerate when texlives switch. The current XML was generated under texlive 2022.

Also, here is a shortlist of notes that are still not fully polished in the Silviu unit test, which some of us may return to when we re-focus on Tikz again:

  • t/tikz/unit_tests_by_silviu.t
    • 4 Paths, pgfclosepath, left triangle should have a sharp top end
    • 5 Decorations, first example should be fully wavy
    • 8 Nodes, Use Case, width of "Use Case" should match circle width (too narrow)
    • 8 Nodes, 2nd example, "qe", "qb" etc text should be centered in their circles (currently close to top)
    • 8 Nodes, "More: [integral]" width should match red rectangle width (other nodes have same problem)
    • 11 Patterns, missing stars
    • 14 Shadings, 3 square "applications" examples, inner shapes should be centered.
    • 16 Transparency - red rectangle background shouldn't be visible
    • 18 Fun Stacking - the black line isn't inside its square?

I have rebased to master, and am largely out of time to keep fine-tuning here, so please consider this ready for review.

Copy link
Owner

@brucemiller brucemiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scary, but seems right. Thanks!!

@brucemiller brucemiller merged commit 6ee12be into brucemiller:master Jan 6, 2024
13 checks passed
@brucemiller brucemiller deleted the tikzmath-patch branch January 6, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants