badboy / mdbook-toc

A preprocessor for mdbook to add inline Table of Contents support.
Mozilla Public License 2.0
163 stars 20 forks source link

Broken link when using underscores in math mode #48

Closed yannickseurin closed 11 months ago

yannickseurin commented 11 months ago

Links are not properly formatted when using underscores in math mode, e.g.

## Analysis of $q_1$

produces anchor #analysis-of-q1 for the header but the link in the toc is analysis-of-q_1

badboy commented 11 months ago

Indeed this seems broken and should be fixed.

I wonder though do I need to enable anything or add another plugin to get proper rendering for $q_1? It doesn't seem to render math out of the box

badboy commented 11 months ago

Hm, no wait. We do the right thing! In a local test I get this generated in the ToC:

<li><a href="#analysis-of-q_1">Analysis of $q_1$</a></li>

With mdbook generating:

<h1 id="analysis-of-q_1"><a class="header" href="#analysis-of-q_1">Analysis of $q_1$</a></h1>

So ... we're fine actually? Please show me a reproducable example.

yannickseurin commented 11 months ago

Ah forgot to mention I'm using mdbook-katex to render math... I can confirm that when not using it everything works fine as you described. The problem shows up when using both mdbook-katex and mdbook-toc as mdbook now generates

<h1 id="analysis-of-q1"><a class="header" href="#analysis-of-q1">...</a></h1>

So I guess it's rather an issue with mdbook-katex

badboy commented 11 months ago

We do essentially the same that mdbook does. If katex modifies the code after that it of course will break.

Closing this as not an issue with mdbook-toc though.