SaswatPadhi / pseudocode.js

Beautiful pseudocode for the Web
https://saswatpadhi.github.io/pseudocode.js
MIT License
224 stars 33 forks source link

Render problem in existing mathmatical multiline expressions (R-Bookdown,R-Markdown) #20

Closed reisman234 closed 4 years ago

reisman234 commented 4 years ago

Hello, i use your pseudocode.js lib in my r-bookdown project to generate the nice latex algorithmic output. The include step was stright forward, as it is mentioned in the usage guide in the readme.

  1. include mathjax and pseudocode.js in header: I have a header_index.html that lists everything that goes into the header tag. Beause there was already an existing entry of mathjax i tried it first, without the new mathjax-include, but this did not work and i added the include for mathjax3.
  2. write code: after that setup and some modifications on the css-file i could add example code in my Rmd-file (R-Markdown) and had the expected output in the browser.

However, I got some errors, existing mathematical expressions were apparently influenced by the change in MathJax. In my book i had both, inline expressions ($somesthing$) and also multiline expressions ($$ centered mathmatical expression $$) and only the latter expressions are affected and are not correctly displayed.

For Example: from following expression: $$L[k](A) = \prod_{i=1}^N[a_i,k]\cdot h[k]$$ is the folling output generated:

I noticed the following lines in the include of MathJax:

inlineMath: [['$','$'], ['\\(','\\)']],
displayMath: [['$$','$$'], ['\[','\]']],

The second line looks to me what influences multiline expressions and has just one "\" insteed of two "\\" as it is in the top line. I changed it to the following: displayMath: [['$$','$$'], ['\\[','\\]']],

and voila, that solve my problem.

I`m not very familiar with javascript and related subjects, so I don't really understand what happens in the include statement and if the backslash is really missing or not. As a simple test I created a simple HTML page. There it seems to be no matter if there are 1 or 2 backslashes in the expression.

SaswatPadhi commented 4 years ago

Thanks a lot from bringing it to my attention!

Fortunately, this does not affect the pseudocode.js library itself, but only the way users should setup MathJax. I would update the documentation right away. You are right that the displayMath brackets should be preceded by 2 backslashes.