lzanini / mdbook-katex

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

cannot use macro `\newcommand` #103

Open hleiaa opened 10 months ago

hleiaa commented 10 months ago

I understand that we can specify latex macros in a "macros.txt" file. Also, it seems that LaTeX macro commands do not work at this time.

A minimal example:

$$
\newcommand{\RR}{\mathbb{R}}
$$

Real numbers: $\RR$ and $\mathbb{R}$.

The above example does not work. As katex has support for \newcommand, is it possible to use that feature?

Rationale: I mostly write in vscode and wish to publish using mdbook. The above example works fine with vscode markdown preview, which is also powered by katex.

SichangHe commented 10 months ago

Hi @hleiaa,

I remember this problem. TLDR; Please put all the macros in a file and configure mdBook-KaTeX to use it.

My attempt to add an option to process each chapter in serial to fix this: https://github.com/lzanini/mdbook-katex/tree/parallel-chapter-option. It does not work in my testing.

In theory, if the same JS engine processes two blocks, it should remember what happened in the first block when running the second one. I thought that was the case because we use katex-rs, which has one JS engine per thread, but there seems to be something else wrong.

Maybe you could look a bit into this if you want, or consult the katex-rs people. I probably won't have time for major investigation until the end of next month.

Steven Hé (Sīchàng)