PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
266 stars 209 forks source link

Mathtools/extpfeil and latex-images #1035

Open alexjbest opened 5 years ago

alexjbest commented 5 years ago

This is a little specialist, but I don't think I'm doing anything too weird/unusual here so I figured I'd make an issue.

Currently I have some images included via latex-image in my html version using the mbx script (I use pgfplots but thats not relevant here). Unfortunately I got some weird bugs where there would be spurious output at the top of my images. I traced this through and it turned out it was due to a macro I have \DeclarePairedDelimiter\ceil{\lceil}{\rceil} (which is loaded in my macros element) which was not working correctly. This macro DeclarePairedDelimiter is included by default in pretext as we load extpfeil which loads mathtools always. So if this package is not loaded junk appears from it failing to interpret DeclarePairedDelimiter. Because macros are always included in the tex generated by the mbx script this The fix in this instance is simple, I put \usepackage{extpfeil} but this package has nothing to do with images, and I as a user never loaded extpfeil in my latex-preamble!

So the issue is: Should the bare-bones tex document created by the mbx script to turn latex-images into svg's for the html version load more packages than it currently does, to ensure the environment is as similar to the usual tex as possible, so nobody's macros break images unexpectedly?

rbeezer commented 5 years ago

Adding in extpfeil was a very early addition to PreTeXt. I'll give it a hard look to see if we can change the situation to address this problem.

alexjbest commented 5 years ago

I should say I think having mathtools/extpfeil included by default is great, probably I'm not the only one using it without explicitly loading it!

rbeezer commented 5 years ago

Thanks, Alex. I've got it now. (Had only skimmed your post earlier.) Can you comment on the following, and maybe test?

I still want to make extpfeil less built-in, but I see now that this is irrelevant to the problem, it just made this much harder for you to debug since the mtools package was only loaded implicitly.

cc'ing @Alex-Jordan since he has done a lot of this work.

Alex-Jordan commented 5 years ago

I'm not following every detail here. But I can say that extract-latex-image.xsl makes use of both docinfo/latex-image-preamble and docinfo/macros.

Notable things that this leaves out are latex.preamble.early, latex.preamble.late, and packages that mathbook-latex.xsl might load for one reason or another. There are good reasons to leave these three things out, but I can imagine it causing trouble like what is described here. In fact it caused me trouble once, when I had a certain color defined in latex.preamble.late and a LaTeX macro that used that color in docinfo/macros. In that case I was able to just move the color definition to docinfo/latex-image-preamble and things were fine for my situation.

There may indeed be a better way to manage all these things.

alexjbest commented 5 years ago

@rbeezer Adding those lines at line 144 of extract-image.xsl works for me (as extpfeil is all I was missing), but: The <xsl:value-of select="$latex-packages" /> line does not seem to fire correctly, I get \usepackage{}\usepackage{}\usepackage{}\usepackage{}\usepackage{}\usepackage{pgfplots} in my image-1.tex generated by mbx where my latex-preamble is <latex-preamble><package>xypic</package><package>newpxtext</package><package>newpxmath</package><package>cancel</package><package>pgfplots</package></latex-preamble>. This works in my usual tex file generated by xsltproc, note that the last one works correctly!?

Alex-Jordan commented 5 years ago

xypic is a great example to work with for sorting this all out. We call it "xypic", "xy-pic", or alternatives that have capitalization.

The MathJax extension is named xyjax.

The LaTeX package is actually just xy. And in my experience, I need to load it with the all option for it to do what I want it to do (just following online guides). So like \usepackage[all]{xy}.

So markup like <package>xypic</package> is not going to work out, unless there is some special XSLT that specially recognizes "xypic" and does the right things in the various output formats. I don't claim this is the best, but there could be markup like:

<latex-package>
    <name>xy</name>
    <options>all</options>
    <mathjax-extension>xyjax</mathjax-extension>
<latex-package>
davidfarmer commented 5 years ago

I like the idea of xypic which then the XSLT knows what to do. This requires keeping a list of supported packages and some supplemental information about each package.

I think that is better because it is not a good idea to support every single package: that is impossible because they conflict with each other. We should make it difficult for authors/publishers to just start adding packages. A lot of effort has already been done to ensure compatible packages, and we risk seeing that undone.

This would also ensure that added packages undergo enough scrutiny to know that they will work as expected.

A sufficiently knowledgeable person who wants to live dangerously is of course capable of using any package they want. But when something goes wrong they know it is their problem only.

On Fri, 5 Apr 2019, Alex Jordan wrote:

xypic is a great example to work with for sorting this all out. We call it "xypic", "xy-pic", or alternatives that have capitalization.

The MathJax extension is named xyjax.

The LaTeX package is actually just xy. And in my experience, I need to load it with the all option for it to do what I want it to do (just following online guides). So like \usepackage[all]{xy}.

So markup like xypic is not going to work out, unless there is some special XSLT that specially recognizes "xypic" and does the right things in the various output formats. I don't claim this is the best, but there could be markup like:

xy all xyjax — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.[AAM6LOYTSJiDSWDSAxb2MxVyiLlJi3vUks5vd5dugaJpZM4cdqO7.gif]
rbeezer commented 5 years ago

I like the idea of <package>xypic</package> which then the XSLT knows what to do.

I was coming to the same conclusion. A look-up table of approved packages, and exactly what incantations are needed (and under our control for resolving future problems).