lzanini / mdbook-katex

A preprocessor for mdBook, rendering LaTex equations to HTML at build time.
MIT License
195 stars 34 forks source link

About client-side katex.js features #109

Closed rogeryoungh closed 4 months ago

rogeryoungh commented 4 months ago

I'm trying to remove the katex-rs dependency in mdbook-katex based on escape trick. I escaped three characters: \->\\ * -> \* _ -> \_. So far, I haven't found any problems.

I've noticed that the main repository is having a lot of problems with quickjs, so maybe we should add client-js mode. Thanks to the good design of scan, I can easily merge my escape code using the cargo feature.

I have only tested the case where KatexConfig is the default setting and it works fine on my site.

for c in code.chars() {
    match c {
        '_' => {
            result.push_str("\\_");
        }
        '*' => {
            result.push_str("\\*");
        }
        '\\' => {
            result.push_str("\\\\");
        }
        _ => {
            result.push(c);
        }
    }
}

Currently I am experiencing the following issues:

SichangHe commented 4 months ago

Sounds good. We could put katex-rs behind a feature flag, and it would get rid of a slew of problems from it for some people. It would need to be a default feature for backwards compatibility, though.

I have only tested the case where KatexConfig is the default setting and it works fine on my site.

Please provide a dummy example in the README for people's reference. This feature would be experimental, and people would try it out at their own risks following the dummy example.

  • The katex.css is added to the HTML by the preprocessor. To add katex.js we also need to generate the configuration using the auto-render.js hook according to KatexConfig.
  • The KatexConfig configuration is very extensive and I'm not sure which configurations are broken by the client-side js mode.
  • I think it might be easier to instruct people to use head.hbs in the README.

I think we let people configure this themselves in the template, because it is client-side. KatexConfig is for server-side rendering. Note that the no-css option could also be set, if the user wants to set katex.css themselves.

SichangHe commented 4 months ago

Please feel free to ask any questions that would help you implement this feature.