0
import sys
from PyQt5.QtWidgets import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas

from matplotlib import rc
rc("text", usetex=True)

app = QApplication(sys.argv)
fen = QDialog()

figure = Figure()
canvas = FigureCanvas(figure)
text_edit = QTextEdit()
list_widget = QListWidget()

layout = QHBoxLayout()
layout.addWidget(canvas)
layout.addWidget(text_edit)
fen.setLayout(layout)


def change():
    text = figure.suptitle(
        r'{}'.format(text_edit.toPlainText()),
        x=0.0,
        y=1.0,
        horizontalalignment='left',
        verticalalignment='top'
        )
    canvas.draw()

text_edit.textChanged.connect(change)


fen.show()
app.exec_()

I have this error:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/texmanager.py", line 486, in make_png
    stderr=subprocess.STDOUT)
  File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['dvipng', '-bg', 'Transparent', '-D', '100.0', '-T', 'tight', '-o', 'b31418787d5e331336f86388cc930ab9.png', 'c073de3d59bf9cbb888f5b9c550ef4f8.dvi']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/loic/Application_math/test.py", line 31, in change
    canvas.draw()
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_qt5agg.py", line 127, in draw
    super(FigureCanvasQTAggBase, self).draw()
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 430, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1299, in draw
    renderer, self, artists, self.suppressComposite)
  File "/usr/lib/python3/dist-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/text.py", line 762, in draw
    mtext=mtext)
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 250, in draw_tex
    Z = texmanager.get_grey(s, size, self.dpi)
  File "/usr/lib/python3/dist-packages/matplotlib/texmanager.py", line 545, in get_grey
    pngfile = self.make_png(tex, fontsize, dpi)
  File "/usr/lib/python3/dist-packages/matplotlib/texmanager.py", line 493, in make_png
    exc.output.decode("utf-8"))))
RuntimeError: dvipng was not able to process the following string:
b''

Here is the full report generated by dvipng:
c073de3d59bf9cbb888f5b9c550ef4f8.dvi: No such file or directory
This is dvipng 1.16 Copyright 2002-2015, 2019 Jan-Ake Larsson
rc("text", usetex=True) 

This line causes the error but I don't see how to correct it. I tried to install/uninstall MiKTeX 10 times and nothing changes I still have the error.

Same issue here RuntimeError: LaTeX was not able to process the following string: r'lb' But no solution for me

I found what doesn't fit. It's just the blank lines. There's a way to pass empty lines? if I can't air it out its not very useful ^^

Colat
  • 41
  • 8
  • There is definitely a conceptional problem here: Each time you type something it is directly translated into latex. However, while typing you may easily produce invalid latex commands. So you either need to validate those or catch any errors that occur while typing. – ImportanceOfBeingErnest Feb 16 '20 at 10:18
  • I tried to put an expect to take the RuntimeError, I don't have an error anymore except that it's very very slow. The goal is to make an instant visualization like on the forum. – Colat Feb 16 '20 at 10:26
  • Rendering latex *is* slow. I guess you have to choose, either use latex or get quicker interaction. You might also try to make sure that the text isn't rendered too often, like maximally twice a second or so. – ImportanceOfBeingErnest Feb 16 '20 at 10:43
  • Okay, thanks, so there's not really a way to make it quick. What and this file in error c073de3d59bf9cbb888f5b9c550ef4f8.dvi? – Colat Feb 16 '20 at 10:49
  • When matplotlib renders a latex string, it will create a text file, run latex on it, then take the output file and place the content into the figure. So those are temporary files that are created by latex, one for each string in a figure. – ImportanceOfBeingErnest Feb 16 '20 at 11:04
  • Why does he raise an error saying he can't find the file if he creates them? I'm sorry for all my questions, I really can't figure out. c073de3d59bf9cbb888f5b9c550ef4f8.dvi: No such file or directory – Colat Feb 16 '20 at 11:09
  • In case latex is told to run on an invalid latex string, it will of course not produce any output, so the expected output file is missing. – ImportanceOfBeingErnest Feb 16 '20 at 11:10
  • Okay, thanks, so the slowness is really just cause it's latex and has nothing to do with the error. – Colat Feb 16 '20 at 11:19

0 Answers0