Ah, yes, of course. I should be doing that more everywhere. I’m always bemoaning the lack of true let
bindings in JS; I really should be using them when they’re available!
This is now quite nice. Thank you very much for your help!
macros_formula.json (435 Bytes)
I’m curious whether something I’m often doing for macros is common and whether there are good reasons not to do it. My actual version of that macro tiddler looks something like this:
\define formula(form)
\whitespace trim
<$let tv-wikilinks=no digits="([A-Za-z])(\d+)" replacement="$1<sub>$2</sub>"
out={{{ [<__form__>search-replace:g:regexp<digits>,<replacement>search-replace:g:[->],[→]] }}}>
<<out>>
</$let>
\end
* Water: <<formula "H2O">>
* Aspirin: <<formula "C9H8O4" >>
* Salt: <<formula "NaCl">>
* First Equation: <<formula "2H2+O2 -> 2H2O">>
* Second Equation: <<formula "SiCl4 + 4H2O → H4SiO4 + 4HCl" >>
That is, I keep test cases inside the same tiddler that holds my macro, and use it to check whether it’s still working on save. (I rarely use preview mode.) Is there any strong reason to avoid this, outside the obvious concern about clutter and wiki size?
So this is what I will probably keep around: macros_formula_with_demos.json (653 Bytes)