Sunday 4 July 2021

struggles with Inkscape's pdflatex extension

[No, still not working]

I was having problems with wrong formulas generated by pdflatex plugin or extension in inkscape. As long as it was sufficient to click "Apply" a few times to get it right, then remove the wrong versions and proceed—I was almost ok with that. But yesterday's session with Maxwell's equations, resulting in the following picture (I changed the input in the plugin's textbox exactly three times, I mean: I'm not joking)

(The red stuff is supposed to be correct, but the Gauss' law is not—shit, \times instead of nothing or \cdot, yeah, it was late, I was getting mad etc.)—all that made me contact people at Inkscape. Someone called Mc (thanks!) told me to get some insight to temporary files of the pdflatex extension that is located at </usr/share/inkscape/extensions/pdflatex.py>, written apparently by a French-speaking person ;) Looking at the temp files wasn't the option since the proposed version (override?) of some (inherited?) cleanup function,

def clean_up(self):
    pass

didn't force the plugin to keep all its files in /tmp. Some mysterious message about implicit cleanup popped up, so I gave up, not wanting to mess with Python, which I hate.

Meanwhile I produced a .tex file with about ten repetitions of the same line with one formula, and tried importing the pdf file (that pdflatex had made) to inkscape. The import with poppler/cairo worked perfect, the internal one resulted in (repeatable) rubbish.

I though a bit about the possible causes and—not finding any, except for somewhat absurd suspicions that something is really wrong with the way in which tmp files are being handled here—I came up with a temporary idea: why not clean the temporary LaTeX file, just in case, every time it's opened? I looked up the possible commands on SO, and this worked like miracle. No matter how many times I press "Apply", the formula is correct, with no changes...

def write_latex(self, stream):
    stream.seek(0)
    stream.truncate(0)

    """Takes a forumle and wraps it in latex"""
    stream.write(r"""%% processed with pdflatex.py

I still don't know why that thing failed before, I don't know whether the two lines above fix that bevavior for good. It works for me, if you have problems like these, just give it a try.

"Never did so many understood so little about so much".
 
Another way to "solve" the problem seems to be: add stream.flush() at the end of the write_latex function. I don't know if it does the same job, but the output is just ok.

No comments:

Post a Comment