-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Unable to save figure as pdf while using latex package concmath #20469
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
Comments
From some research, it looks like this arises because concmath uses fonts in the Metafont format, which is not supported by Matplotlib. If you run either latex+dvips or pdflatex on a single tex file that uses such fonts, you'll see in the log an invocation of (I'm tempted to close as "upstream fix required" due to the situation with FreeType.) |
Sorry if this is a naive question, but I'm confused about this statement: "..., which is not supported by Matplotlib.": Everything works fine as long as one doesn't try saving the plot as a pdf. For example, as mentioned earlier, there are no problems if one tries to save the figure as a png or jpeg file (and there are, of course, no issues encountered if one doesn't try to save the file at all). So wouldn't this mean that Matplotlib does support the font, and rather the problem is with saving into a pdf? |
No, it's not a naive question at all! That's because for png/jpeg output, we rely on dvipng to rasterize the text (i.e. transform the text into an image). For pdf we don't do that, as the point of pdf is normally to have selectable text, but then we need to actually know how to embed the font and the glyph infos into the pdf file (which is what's not supported here). I guess yet another solution would be to give up on embedding the font/glyphs in that case and just embed a dvipng-generated image... @aitikgupta I guess this is actually relevant for your gsoc: switching to parsing dvi even for raster output would mean a small loss of functionality (for agg) in this case, and conversely, perhaps falling back on embedding dvipng rasters would be a relatively simple workaround for vector output? |
hmm, what if instead we let users decide this? On a different note, non-editable PDFs hardly make sense? If users want to use just 'images' in their PDFs (and not actual text), they could just convert PNG outputs. (or we could provide a flag like mentioned above) |
Just a side point: I realized we don't actually need to figure out the correct mktexpk/mf invocations ourselves, at least that part can be handled transparently by kpathsea (https://tug.org/texinfohtml/kpathsea.html#mktex-scripts). (We need to call something like Making things user-configurable seems fine, although as always that means that both branches need to be implemented :-) After some more investigation, it looks like pdflatex embeds such fonts as type3, taking advantage of the possibility to just specify glyphs as raster images (after all, it can use arbitrary postscript operators to define glyphs). (We'd still need to somehow get the bitmap out of the pk file, though.) |
Just for future reference, here's a minimal repro: from pylab import *
rcParams["text.latex.preamble"] = r"\usepackage{concmath}"
figtext(.5, .5, r"\textrm{hello, world}", usetex=True)
savefig("/tmp/test.pdf")' |
I guess if we want to work on this, the first part would be to implement a parser for the pk format, following the description at https://ctan.math.illinois.edu/info/knuth-pdf/mfware/gftopk.pdf (starting at section 21). Probably a good programming exercise ;-) |
Uh oh!
There was an error while loading. Please reload this page.
Hello all,
I seem to run into a problem when I use the (latex) package
concmath
, and try saving the resultant plot as a pdf (png and jpeg work fine). As suggested in #10272, I've tried installing the "cm-super" package, but this does not solve the issue. I've also played around with the backends, but the problem still persists. A short code that generates this issue:with the following traceback:
Please let me know if there's a way to circumvent this issue. Thank you all in advance!
Operating system: macOS Big Sur 11.2.3
Matplotlib version: 3.4.2
Matplotlib backend: module://ipykernel.pylab.backend_inline
Python version: 3.8.8
Matploblib came pre-installed with anaconda, but upgraded through pip.
The text was updated successfully, but these errors were encountered: