TransWikia.com

Formula in a variable that can be referenced later

TeX - LaTeX Asked by Frank Henard on July 2, 2021

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
Display[x];

The result would be something like this:

a/b/c

One Answer

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

documentclass{standalone}

newcommand{somefunction}{frac{a}{b}}
newcommand{x}{frac{somefunction}{c}}

begin{document}
    $x$
end{document}

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.

Correct answer by Gunter on July 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP