title: Python, Math, and Latex: Display + Compute?
body: <p>Suppose that I have a family of equations that depend on a variable n. What I want to do is to write a simple code so that by just by choosing a particular n, it will generate the equation for that particular value of n.</p>
  
  <p>Here is an example of a code I wrote on ipython. It will display the partial sum of the harmonic series for any n of my choosing (without evaluating it).</p>
  
  <pre><code>from IPython.display import display, Math, Latex
  
  txt = "$1"
  n = 100000
  long = 0
  for i in range(n):
      if (i&lt;3 or i &gt; n -3):
          str = "+\dfrac{{1}}"
          temp = "{0}".format(i+2)
          str +="{"+temp+"}"
          txt+=str
      else:
          if long == 0:
              txt +="+..."
              long+=1
      txt +="$"
  display(Math(txt))
  </code></pre>
  
  <p>This generates the following output:</p>
  
  <p><img src="https://i.stack.imgur.com/moXp7.png" alt="enter image description here"></p>
  
  <p>And of course, I can adjust my n to whatever value I want.</p>
  
  <p>The way this code is written, it doesn't really adapt too well to other types of expressions.  And I would also like to have " = ::whatever the value is to my desired precision::"</p>
  
  <p>Is there a smart way to do this either on ipython or latex?</p>