title: Mathematical Equations - Rendering and Evaluation with Python and QT (and sympy?)
body: <p>I am developing a GUI application (in the civil engineering context) with python3 and QT and want to display an equation in three different ways:</p>
  
  <ol>
  <li>symbolic: sigma=N/A</li>
  <li>with values: sigma=200kN/20cm²</li>
  <li>as a result: sigma=10kN/cm²</li>
  </ol>
  
  <p>The layout of the equation and the order of symbols has to be the same for both (1) and (2), but i only want to enter the equation once in my sourcecode. I searched a lot, this is the best i could get:</p>
  
  <pre><code>class myfancy_equation():
      def __init__(self):
          self.a = Symbol('a')
          self.b = Symbol('b',commutative=False)
          self.x = Symbol('x')
          self.expr = (self.b * self.a)/self.x
      def mlatex(self):
          return latex(self.expr)
      def mevaluate(self,a_in,b_in,x_in):
          unev = self.expr.subs({self.a:a_in,self.b:b_in,self.x:x_in})
          symb_names = dict()
          symb_names[self.a] = str(a_in) 
          symb_names[self.b] = str(b_in) 
          symb_names[self.x] = str(x_in) 
          # unev_latex = latex(self.expr.subs({self.a:a_in,self.b:b_in,self.x:x_in}))
          unev_latex = latex(self.expr,symbol_names=symb_names)
          ev = self.expr.subs({self.a:a_in,self.b:b_in,self.x:x_in}).evalf()
          return unev,unev_latex,ev
  
  mfe = myfancy_equation()
  
  lat = mfe.mlatex()
  un,unl,ev = mfe.mevaluate(5,7,3)
  
  print("Original, unevaluated, evaluated:")
  print( lat,"=",unl,'=',ev)
  </code></pre>
  
  <p>I have read that sympy was not primarly developed for displaying equations, but the result is hardly readable (and unpredictable) for more complex equations. i tried playing around with the "commutative" parameter, but always end up with a mixed equation like this:
  <a href="http://www.oberthanner.at/render.png" rel="nofollow">http://www.oberthanner.at/render.png</a>
  am i missing the point or is it just impossible with sympy?</p>
  
  <p>btw: i encountered a different behaviour of the commutative parameter when using python2.</p>