boolesrings / Simple-Mathjax-wordpress-plugin

15 stars 9 forks source link

Problem with ampersands in custom preamble (A glitch in the matrix) #20

Open scoskey opened 6 years ago

scoskey commented 6 years ago

https://wordpress.org/support/topic/problem-with-ampersands-in-custom-preamble-a-glitch-in-the-matrix/

Hi,

Love SImple MathJax, it makes my life as a maths blogger SO MUCH easier. Thanks for doing such great work.

I have one thing I’m struggling with: I’ve added a \newcommand in the custom preamble that looks like this:

\newcommand{\mattwotwo}[4]{\begin{pmatrix} #1 & #2 \ #3 & #4 \end{pmatrix}}

However, it seems that the ampersands are being escaped and turned into & amp; before they’re processed, leaving me with ‘amps’ in my matrix! Escaping the ampersands with a \ leaves literal &s instead of spacing.

I know there’s a warning that this bit is untested and unescaped strings like this may cause problems — my current workaround is to put ampersands in the LaTeX as I do it, which is clunky but works — I wondered if there was a more elegant way to do it that didn’t involve remembering them?

pkra commented 6 years ago

https://github.com/boolesrings/Simple-Mathjax-wordpress-plugin/blob/4a6495beebf0449151cc4862bb7ac36333c441db/simple-mathjax.php#L38 shows that we've already hacked (PHP?) escaping. We can unescape ampersands the same way.