source-academy / sicp

XML sources of SICP and SICP JS, and support for generating Interactive SICP JS, PDF, e-book and comparison editions
https://sourceacademy.org/sicpjs
Creative Commons Attribution Share Alike 4.0 International
916 stars 123 forks source link

Comparison edition: 4.4: MathJax rendering within JS confused by $pattern_variables #904

Open cben opened 1 year ago

cben commented 1 year ago

The logic programming patterns in section 4.4 used ?foo for variables in Scheme and $foo in JS. That's a great choice, as dollar is the only punctuation char valid in JS identifiers, and alludes to $var syntaxes in shells/Perl/etc. :+1:

Alas, in the comparison edition, the dollars confuse MathJax, which apparently processes the whole page, including all JS code :-(

here is a particularly mixed-up example, where same list( is sometimes literal code sometimes italic "math", and underscore in lives_near makes the letter n subscript — and most importantly all the dollars are gone.

Screenshot $lives_near rendered from this XML: https://github.com/source-academy/sicp/blob/ca6ce376aadd94070b50727a0678ba04a3eb44e2/xml/chapter4/section4/subsection1.xml#L1676-L1679

(same happens in later subsections 4.4.2 and so on.)


Now, you can't just exclude all Scheme/JS snippets from mathjax processing, cause some are deliberate, like here: Screenshot query_1, ..., query_n https://github.com/source-academy/sicp/blob/ca6ce376aadd94070b50727a0678ba04a3eb44e2/xml/chapter4/section4/subsection1.xml#L1068-L1080

So it has to depend on LATEX="yes" attribute.

cben commented 1 year ago

The JS-only edition looks fine BTW: https://sourceacademy.org/sicpjs/4.4.1#p20 There code is code, dollars are dollars, all monospace, yet the LATEX="yes" portions do get rendered with KaTeX.