adding subscripts in expressions #2590
-
I'm working on a React component which uses mathjs expressions to both pretty print tex and evaluate the solution. An example of implemented component is linked below. https://calcs.app/analysis-shape-properties In that example, the area formula is both tex'ified and evaluated from the string This works great, but I am wondering if it is possible to add subscripts to the variables while still maintaining the ability to both generate tex and evaluate the expression? For instance, I might want to call the area I don't see any mention of subscripts in the docs, and trying the obvious formats doesn't appear to work |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
For variables names you can use characters like letters, numbers (except as first character), and underscrore If you do need something like that, you could maybe do some post processing of the names yourself, like in expressions you use |
Beta Was this translation helpful? Give feedback.
For variables names you can use characters like letters, numbers (except as first character), and underscrore
_
. However the brackets{
and}
have a special meaning: these are used to create an object likeA = {"name": "Joe"}
. So you can't use these characters in a variable name.If you do need something like that, you could maybe do some post processing of the names yourself, like in expressions you use
A_rect
, and for displaying in tex you replace the part after the underscore withA_{rect}
. To achieve that, you can write your own LaTeX handler: https://mathjs.org/docs/expressions/customization.html#handler