Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Katex renderer should not throw on error #571

Closed
titonbarua opened this issue Nov 7, 2023 · 0 comments · Fixed by #606
Closed

Katex renderer should not throw on error #571

titonbarua opened this issue Nov 7, 2023 · 0 comments · Fixed by #606

Comments

@titonbarua
Copy link

Right now, even a slight error on tex source will make the cell unreadable after Katex throws ParseError. Sometimes the whole page becomes blank and auto-reload with watch fails even after doing a correction. Current Katex renderer function does not handle the parser errors gracefully.

(defn render-katex [tex-string {:keys [inline?]}]
  (let [katex (hooks/use-d3-require "katex@0.16.4")]
    (if katex
      [:span {:dangerouslySetInnerHTML {:__html (.renderToString katex tex-string (j/obj :displayMode (not inline?)))}}]
      default-loading-view)))

Katex documentation ( https://katex.org/docs/options ) says that the behavior can be controlled with throwOnError option. Documentation for the option is:

throwOnError: boolean. If true (the default), KaTeX will throw a ParseError when it encounters an unsupported command or invalid LaTeX. If false, KaTeX will render unsupported commands as text, and render invalid LaTeX as its source code with hover text giving the error, in the color given by errorColor.

Having information about source of error is much better from usability perspective. As such, render-katex should be modified like this:

(defn render-katex [tex-string {:keys [inline?]}]
  (let [katex (hooks/use-d3-require "katex@0.16.4")]
    (if katex
      [:span {:dangerouslySetInnerHTML {:__html (.renderToString katex tex-string (j/obj :displayMode (not inline?) :throwOnError false))}}]
      default-loading-view)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant