Is there a way to put a formula in a variable (as in like a programming language variable) so that it can be referred to and rendered later? I was able to do this in Mathematica, but I'm moving away from Mathematica because I don't want to pay for it. I want to change to something more openly available like LaTex for displaying math formulas.

Note: I'm using Jupyter Notebook, which happens to use MathJax for LaTex rendering.

Though I mentioned programming language variables, Mathematica, and Jupyter Notebook, I am asking about doing this purely in LaTex (MathJax in my case).

I didn't have a lot of time with Mathematica, but here's an example of something that could be done in Mathematica

some_function = a/b
x = some_function/c

The result would be something like this:


  • 2
    Hi, I am slightly confused as you mention Mathematica and Jupyther (Pyton). Both are more a programming language. LaTeX is more for typesetting. Could you explain your questions a little further. Maybe with an example? Otherwise, take a look at \newcommand, which could go in the right direction. \pgfmathdeclarfunction could also be an option for you.
    – Gunter
    Jun 4, 2021 at 14:17
  • 2
    jupyter notebooks don't (I think) runlatex by default. Are you using mathjax (which is a javascript emulation of a subset of latex math markup) it is rather hard to tell what your intended input and output is. Jun 4, 2021 at 14:22
  • 1
    jupyter-contrib-nbextensions.readthedocs.io/en/latest/… perhaps? Edit: that has nothing to do with LaTeX though, as said above a Notebook doesn't actually use LaTeX. Jun 4, 2021 at 16:17
  • Jupyter Notebook uses Mathjax by default, and Mathjax supports LaTex. Jun 4, 2021 at 20:01
  • 2
    mathjax emulates a subset of latex syntax but does not use tex at all, it is mostly off topic on this site. (the answer to your meta question is that mathjax is not enabled on this site, to show tex output post an image of the rendered document) Jun 4, 2021 at 21:30

1 Answer 1


Given your example, I would come up with this for pure LaTeX:




enter image description here

Depending on the use cases, one could also consider placing the $ inside of the \newcommand, but this would limit the nesting.

Having no Jupyter at hand, I can not test, if this works also there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .