I'm writing macros with m4 to easily embed math in HTML code. Slashes need to be escaped and I want to automate this process but I have not yet figured out a good way.
Running m4
on the following shows the problem:
define(`_imath', `esyscmd(`echo "$ $1 $"')')dnl
_imath(y = \frac{1}{2} x^{2.3} + 2)
My output in the following:
$ y =
rac{1}{2} x^{2.3} + 2 $
If I replace \frac
with \\\frac
then I get the desired result. I could do that every time, but I want to automate this process if I can. The desired result, by the way, is
$ y = \frac{1}{2} x^{2.3} + 2 $
which is piped to another command that'll produce HTML code or an image (outside of this minimal example).
I know one unsatisfactory way to get around this problem. I could use a different character (or combination of characters) for TeX's \
and define another macro to automatically replace it. This is unsatisfactory because I want to use straight LaTeX code without modification and it is not significantly simpler than using three slashes.
How can I change my macro to automatically escape the slash correctly so I can use straight LaTeX code?
It took me long enough to figure this out, but this works:
define(`_imath', `esyscmd(echo "$ patsubst(`$1',`\\',`\\\\\\') $")')dnl
_imath(y = \frac{1}{2} x^{2.3} + 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With