6

I would like to fill in values in a report that I'm generating using a Jupyter notebook. While I am using the nbextension Python Markdown, this appears to only allow variables that can isolated, i.e. I can't fill in values that would be in a fraction.

This works, since it is only symbolic:

Markdown cell:

\begin{equation*}
\xi_b = \frac{\epsilon_c}{\epsilon_c + \epsilon_y}
\end{equation*}

But this code snippet wouldn't:

Code cell:

epsilon_c = 0.003
epsilon_y = 0.005

Markdown cell:

\begin{equation*}
\xi_b = \frac{{{epsilon_c}}}{{{epsilon_c}} + {{epsilon_y}}}
\end{equation*}

Is there some way to inject the python variable values directly into my LaTeX expression?

MClare
  • 71
  • 3
  • See this related thread that uses sympy. https://stackoverflow.com/questions/62237257/force-sympy-to-print-math-in-mathjax-jupyter#_=_ – Simon Hobbs Aug 11 '21 at 14:45

1 Answers1

3

You can generate the Latex output from Python cell like this:

from IPython.display import Latex

epsilon_c = 0.003
epsilon_y = 0.005
Latex(f"""\\begin{{equation*}}
\\xi_b = \\frac{{{epsilon_c}}}{{{epsilon_c}}} + {{{epsilon_y}}}
\\end{{equation*}}
""")

enter image description here

iNecas
  • 1,743
  • 1
  • 13
  • 16