PreTeXtBook / pretext-cli

Command line interface for quickly creating, authoring, and building PreTeXt documents.
https://pretextbook.org
GNU General Public License v3.0
17 stars 18 forks source link

Get latex-image generation working #8

Closed oscarlevin closed 4 years ago

oscarlevin commented 4 years ago

Unclear what the best way is, but one way would be to simply leverage the rbeezer/mathbook directory structure.

StevenClontz commented 4 years ago

Something to investigate: https://jeltef.github.io/PyLaTeX/current/

StevenClontz commented 4 years ago

So after a bit of research, it seems plausible that PyLaTeX would be the "Pythonic" way to take TikZ snippets and pass them off to LaTeX to burn to a PDF (in particular, abstracting away cross-platform concerns aside from "you need to have TeXLive installed on your platform"). That said, I cannot find a similar Python library wrapping a cross-platform mechanism to convert the resulting PDF to SVG.

So here's another approach. You might remember Jim Fowler presenting a Javascript interpreter for TikZ in Portland a year ago: https://github.com/kisonecat/tikzjax If we used that, we could cheat: to build LaTeX, we just dump the authored TikZ into the *.tex file, and to build HTML, we simply wrap the authored TikZ in <script type="text/tikz"> and let TikzJaX convert the image to SVG within the browser. If we did this, then we can produce LaTeX and HTML source without any dependencies outside of Python (and users are on their own to convert LaTeX to PDF, or we use PyLaTeX to help that process along).

I lean towards the latter, perhaps via introducing a <tikz> element to rbeezer/mathbook.

oscarlevin commented 4 years ago

It seems that someday it might be possible to have tikz authored images rendered in the browser without building them separately. This is a project for pretext, not for the pretext cli. In the mean time...

I have restructured static to mirror the rbeezer/mathbook directory structure, refactoring the code to account for this. There might be some issues with how importlib works with this, but it seems to be working on my windows install. Then using the latex_image_conversion module from pretext-core, we can now generated images using the -d (--diagrams) flag. Work finished at 930e635.

This should be ready for testing on various machines that pip-install pretext-cli. I'll close for now.

StevenClontz commented 4 years ago

It seems that someday it might be possible to have tikz authored images rendered in the browser without building them separately. This is a project for pretext, not for the pretext cli.

Agreed, and given the current state of Tikzjax (particularly lack of support for Greek letter variables, apparently), we'll need to wait a bit before that's ready for production. But when it's available, I strongly prefer having pretext's cli use it for HTML production by default to eliminate all non-Python dependencies for new authors.