1
from tkinter import *
import matplotlib.pyplot as plt
window = Tk()

entryBox = Entry(window,text='input latex command')
entryBox.grid(row=0,column=0)

s = '$\sum {n} = \frac{n(n+1)}{2}$'
plt.text(.5,.5, s, fontsize=40)
plt.show()

This snippet displays only a part of the expression as follows: enter image description here

instead of the expected result:

enter image description here

(This is achieved by changing the 7th line as: plt.text(.3,.3, r'$\sum {n} = \frac{n(n+1)}{2}$', fontsize=40)).

My understanding is that in the first case we are not passing the string as a raw string. How can I get the plot to render correctly when I have the string as a string variable but cannot input it as a string literal?

Thomas Kühn
  • 9,412
  • 3
  • 47
  • 63
Mutasim Mim
  • 146
  • 1
  • 7

1 Answers1

0

Filter your string using:

s = s.replace("\x0c", "\\f")

as this doesn't work on frac formfeed apparently.

Nae
  • 14,209
  • 7
  • 52
  • 79