title: Matplotlib - using variables in LateX expressions
body: <p>I would like to build an expression using LateX formatting, where some numbers appear but are expressed in terms of a variable in the LateX expression.</p>
  
  <p>The actual goal is to use this in the <code>axes.annotate()</code> method, but for the sake of discussion here is a principle code:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np 
  x = np.arange(-5, 5, 0.05)
  fig = plt.plot(x, x**2)
  plt.grid(True)
  g = 3
  plt.xlabel(r'$test {}$'.format(g))
  plt.show()
  </code></pre>
  
  <p>This is OK.The value of <code>g</code> is passed to the expression.</p>
  
  <p>However, what about using <code>\frac{}{}</code> and other constructs?
  Substituting the <code>xlabel()</code> string above with:</p>
  
  <pre><code>plt.xlabel(r'$test \frac{1}{}$'.format(g))
  </code></pre>
  
  <p>gives:</p>
  
  <pre><code>IndexError: tuple index out of range
  </code></pre>
  
  <p>I understand that something is going on with the use of curly braces and have tried a couple of variants, but nothing worked so far.</p>