Skip to content

[ENH]: Support alternate LaTeX engines #22715

Open

Description

@doronbehar

Problem

I don't use Texlive, I use Tectonic, and using plt.rcParams['text.usetex'] requires me to download a different LaTeX engine, not only because the latex binary is searched, but also because the tex files that are meant for compilation are meant for pdflatex, and not xetex, which tectonic essentially wraps.

Proposed solution

Add a new option to rcParams which will enable using a different LaTeX engine, and another option that will control whether the generated tex files should be intended for xetex or pdftex.

This seems not too complicated to solve, but I wish to know what do you think, and whether you'd be willing to add more moving parts to TexManager class, especially since the generated tex files for a xetex engine should be substantially different.

Activity

  1. jklymak commented on Mar 28, 2022

    @jklymak
    Member
    1. My reading of tectonic is that it still downloads TexLive? Do you really not have pdflatex on your system path?

    2. I don't think its too hard to change text.usetex to include an executable name instead of simply a boolean. OTOH it will increase our maintenance burden when folks claim things don't work.

  2. doronbehar commented on Mar 28, 2022

    @doronbehar
    ContributorAuthor

    My reading of tectonic is that it still downloads TexLive?

    Tectonic downloads .sty according to what your document uses - that's the main feature of it - you don't have to deal with tlmgr or use your Linux package manager to manage tex dependencies - it all happens automatically!

    Do you really not have pdflatex on your system path?

    I do have now, but getting the generated tex file to compile wasn't trivial, due to type1ec.sty and type1cm.sty - it took me an hour or so to figure out how to get these the right packages available, without downloading all of Texlive to my computer. This experience can be different among users of different distributions, but reading #16911 made me feel I'm not the only one.

  3. jklymak commented on Mar 28, 2022

    @jklymak
    Member

    I do have now, but getting the generated tex file to compile wasn't trivial, due to type1ec.sty and type1cm.sty - it took me an hour or so to figure out how to get these the right packages available, without downloading all of Texlive to my computer. This experience can be different among users of different distributions, but reading #16911 made me feel I'm not the only one.

    But that seems an orthogonal issue to whether tectonic works? Personally I agree that it is a bit user-hostile for us to require on a non-standard package, but I'm not sure if that is on us, or on TexLive for not including it by default. I guess your point is that tectonic would have magically taken care of this for you, but that doesn't help our many non-tectonic users.

  4. doronbehar commented on Mar 28, 2022

    @doronbehar
    ContributorAuthor

    I guess your point is that tectonic would have magically taken care of this for you, but that doesn't help our many non-tectonic users.

    That's part of the point but it's not accurate. Generating tex documents that with Tectonic will produce similar results to what's produced now, is simpler because it uses xetex, UTF-8 and modern OpenType fonts - meaning that generating such it won't even require the type1*.sty packages. It will only require fonts, which we can leave for the user to configure in case our default choice doesn't exist.

  5. oscargus commented on Mar 28, 2022

    @oscargus
    Member

    What about introducing another rcParam, like text.texengine or something that defaults to pdflatex?

    Possibly with a finite number of options (pdflatex, xetex, ...). Benefit: it is easier to adapt the tex-file based on the option. Drawback: one cannot specify an exact path (or some parsing to extract the engine from c:\Program Files\...\pdflatex.exe is required).

    But, yes, it can make sense to make the engine configurable in the light of potential benefits from fonts, UTF8 and xetex/lualatex. At the same time, there is for sure a risk for more issues popping up and more support required.

    Probably it can make sense to subclass TexManager into PDFLatexManager and XetexManager for clearer separation. I think one challenge is how to deal with people (thinking they are) wanting to use xetex, but still want to use the old way of specifying fonts.

  6. anntzer commented on Mar 28, 2022

    @anntzer
    Contributor

    We currently don't support xetex or pdftex (and therefore likely can't support tectonic either), due to #20262 (comment). It would be nice to fix that, but it's not a trivial piece of engineering either (as outlined in that comment). If someone wants to have a go at that, I could probably provide some very high-level mentoring (the first step would be to get familiar with the current implementation of dviread)...

  7. changed the title [-][ENH]: Support Tectonic as a LaTeX engine [/-] [+][ENH]: Support alternate LaTeX engine [/+] on Jun 10, 2023
  8. changed the title [-][ENH]: Support alternate LaTeX engine [/-] [+][ENH]: Support alternate LaTeX engines[/+] on Jun 10, 2023
  9. anntzer commented on Mar 26, 2025

    @anntzer
    Contributor

    @doronbehar #29807 should help moving in that direction (by first supporting xetex itself), but from a quick look tectonic is more complicated to support because it does not record full font paths and (from what I've found...) may not expose an external API to query its internal font path database. Essentially, this is the issue described at tectonic-typesetting/tectonic#1019 (the "AFAIK .dvi files unfortunately only list the base name of the font files (e.g. font.otf and not /path/to/font.otf), so after Tectonic (or XeTeX) is done, dvisvgm has to look up the files again." part: actually xetex records full font paths so we're fine, only tectonic doesn't). If you're still interested in this, maybe you can try to get the issue fixed on tectonic's side?


    From a brief investigation: it appears that tectonic searches the file via io.input_open_name
    https://github.com/tectonic-typesetting/tectonic/blob/c2ae25ff1facd9e9cce31b48944b867773f709ec/crates/engine_spx2html/src/initialization.rs#L93-L96
    but there's no command line API to access that. There's tectonic -X bundle search to check that the file exists and tectonic -X bundle cat to dump the contents of the file
    https://github.com/tectonic-typesetting/tectonic/blob/c2ae25ff1facd9e9cce31b48944b867773f709ec/src/bin/tectonic/v2cli/commands/bundle/mod.rs#L102-L115
    but modifying the codebase throughout to support file streams instead of file paths seems a bit heavy; frankly it would be simpler if they just directly recorded the file path (or at least provided a CLI command to print it, but even that seems quite adhoc).

  10. akhmerov commented on Aug 10, 2026

    @akhmerov
    Contributor

    #29939 included in mpl 3.11 allows to hack together a sligtly janky way to use tectonic as a latex renderer. I made a minimal package to apply this as a patch: https://github.com/akhmerov/mpl-tectonic/

  11. anntzer commented on Oct 20, 2026

    @anntzer
    Contributor

    @akhmerov Would you be interested in splitting off the OpenType-embedding-into-vector-formats part and use them to get #29807 merged?
    Then tectonic support would only require patching make_tex (to add an entry explaining how to invoke tectonic) and from_xetex (to understand tectonic font bundles and extract them). I think it would then be reasonable to think of some kind of official hooking mechanism, e.g. rcParams["text.latex.engine"] = "module://mpl_tectonic", which allows swapping those.

  12. akhmerov commented on Oct 20, 2026

    @akhmerov
    Contributor

    Unfortunately I don't understand font handling and formats enough to take responsibility for this: mpl-tectonic is almost entirely vibe-coded.

    Feel free, however, to scavenge any code that is there (I hereby grant a permission to use it under CC-0 license/public domain release), except for the patch by @j-bowhay, which isn't mine, but I imagine Jake also wouldn't mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions