Generate function with keyword arguments from `Symbolics` expression

Thanks a lot for your responses!

Overall, my impression is that Pluto notebooks are now pretty close to a viable replacement for “write and publish papers” in my field. Although traditional Journals would not allow such submissions (yet?), even a supplement can go a long way. If there are people interested in seeing how far one can go with replacing papers by Pluto notebooks, I’m happy to discuss or contribute!

To try this out, I replicated parts of a published paper (I use its results in my research) as a Julia notebook. It still needs a lot more polish but using my wonky function to “substitute all the equations into each other”, I managed to reproduce the expected numeric result. I’m still planing to try reproducing some optimizations from the paper (let’s see where Julia’s SciML ecosystem takes me) and plots (should work fine).

In the paper, around 30 variables (most require superscripts to represent in LaTeX) are defined and used ion around 30 equations. The equations are mathematically trivial (arithmetic, roots, logarithms, factorials). The challenge is making sure there are no typos (even the original authors seem to have struggled with this) and that the equations in the paper are consistent with any code used for simulations and optimizations. For this, LaTeX rendering, as well as doing away with the separation of paper and simulation program, should help a lot.

While typing out the equations, I came to the conclusion that @variables var"{crazy_latex_syntax}" is too limiting and does not scale well. There are too many variables to keep track of and having an alias for each one is not the way to go. Is there some way to specify a desired LaTeX representation as a “tagged on attribute” to a Symbolics.jl variable? What would it take to make that work? (I guess the obvious solution would be “stop using superscripts”, which one might try in “ones own” papers…)

This could also be solved by customizing the behavior of Latexify.jl (such customization should become possible once Latexify.jl/Issue#123 is solved), which I’ve also asked about. However, I think such LaTeX representations are really a part of the variable definition and specified within Symbolics.jl. I imagine something like a special type acting like Num, except when rendering as Latex (and perhaps some safety checks). Maybe one could write something like

# Not real Julia code! Just wishful thinking
@latex_variables x_mu1_plus => L"x_{\mu_{1}}^{+}", <etc...>

Unfortunately, I don’t know how to make a new type X that behaves like an existing type Y in all circumstances except Z. Julia doesn’t allow deriving from concrete types, has no (and should’t have) universal default conversions…