glushchenko / fsnotes

Notes manager for macOS/iOS
https://fsnot.es
MIT License
6.43k stars 473 forks source link

Incorrect MathJax delimiter configuration, with fix. #1471

Closed Koloth closed 1 year ago

Koloth commented 1 year ago

Description

There is currently a minor misconfiguration in MathJax which has created a few other bug reports (everyone mentioning parentheses rendering improperly with math preview mode on). In this code:

public static func getMathJaxJS() -> String {
        if !UserDefaultsManagement.mathJaxPreview {
            return String()
        }

        let inline = "['$', '$'], ['\\(', '\\)'], ['$$', '$$'], ['\\((', '\\))']"

        return """
            <script>
            MathJax = {
              tex: {
                inlineMath: [\(inline)]
              }
            };
            </script>
            <script id="MathJax-script" async src="{WEB_PATH}js/tex-mml-chtml.js"></script>
        """
    }

The slashes are escaped once, so this means that the javascript gets written into it the line:

MathJax = {
      tex: {
        inlineMath: [['$', '$'], ['\(', '\)'], ['$$', '$$'], ['\((', '\))']]
      }
    };

However, for javascript to interpret this properly, it needs to have the \ escaped as well, so the original code needs to be

public static func getMathJaxJS() -> String {
        if !UserDefaultsManagement.mathJaxPreview {
            return String()
        }

        let inline = "['$', '$'], ['\\\\(', '\\\\)'], ['$$', '$$'], ['\\\\((', '\\\\))']"

        return """
            <script>
            MathJax = {
              tex: {
                inlineMath: [\(inline)]
              }
            };
            </script>
            <script id="MathJax-script" async src="{WEB_PATH}js/tex-mml-chtml.js"></script>
        """
    }

This modification (a common error, see for instance here) should set the proper delimiters in the mathjax configuration, and stop complaints around parentheses rendering strangely with math preview on.

I'm not submitting as a PR since I have not been able to test on my dev machine.

To Reproduce

Write anything with round brackets and turn on MathJax preview

Expected behavior

MathJax should need \(f(x) = x^2\) to trigger, not just (f(x) = x^2).

FSNotes version

6.1.2

macOS/iOS version

12.5.1 (21G83)

Additional context

No response

glushchenko commented 1 year ago

Seems this https://github.com/glushchenko/fsnotes/commit/915a4af719995ce37bec2a06c67fb3291999091a fixes it