# Katex not rendering correctly in html export

#### einar.risholm

10 Sep, 2021 11:25 AM

I use a little LaTex, and it usually renders nicely in the app. I have noticed however, that the  are sometimes converted to \$ and \$, and failing to render properly. This happens every time I convert to html, and I have to manually remove them. The display equation should also automatically center align, but are aligned to the left. I can correct this by adding display: block; text-align: center; to the .katex class. 1. Posted by einar.risholm on 22 Sep, 2021 04:11 PM With the new update  is broken as well... It renders to $$ and $$ both in the app and in html exports. 2. Support Staff Posted by Brett on 23 Sep, 2021 01:31 AM I didn't make any changes to MathJax/Katex handling at all in the last update, and I stopped it from doing the \$ replacements a couple of versions ago. Are you really on the latest? 3. Posted by einar.risholm on 23 Sep, 2021 08:14 AM I'm using version 2.6.10. 4. Posted by einar.risholm on 23 Sep, 2021 10:29 AM I have completely removed Marked 2 and reinstalled it. The issue is still present. 5. Support Staff Posted by Brett on 23 Sep, 2021 07:06 PM It looks like it's not the syntax replacement that's broken, it's the entire Katex install. The script isn't loading properly. Possible to use MathJax until I have a chance to figure out what's going on? Also, you're correct, when using the MultiMarkdown processor Marked is still replacing with $$and with \[, which is for compatibility with MMD math processing. I'll look back into just disabling that, but in the mean time, if using the Discount (GFM) processor is an option, it shouldn't alter your markup when using that. -Brett 6. Posted by einar.risholm on 24 Sep, 2021 06:54 AM So both Katex and MultiMarkdown are causing problems. Switched to MathJax for now, although this introduces a new set of problems like lack of text mode macros that breaks rendering, but that issue is beyond Marked 2. Will I get any feedback on when Katex renders properly? 7. Support Staff Posted by Brett on 24 Sep, 2021 05:38 PM I pushed an update yesterday that at least gets Katex running again. If you're on the direct-download version, you'll have to update by downloading as I managed to break the auto-update on the last version. The new version does not address the original issue, though. I double checked, and Marked is not making any alterations to  syntax internally, so it has to be something happening in the Markdown processors. Can you share a snippet of text containing an equation and the syntax that demonstrates the issue? Thanks, Brett 8. Posted by einar.risholm on 25 Sep, 2021 06:29 AM The following snippets renders properly with Katex in Marked 2 and breaks in html export: Inline (2*3 = 6)  Display mode \rightarrow ONE - TWO - THREE \rightarrow FOUR - FIVE - SIX  Display mode with \\ line break \rightarrow ONE - TWO - THREE \\ \rightarrow FOUR - FIVE - SIX  There still seems to be a parsing problem in Marked 2. If I make a syntax error that breaks rendering, fix the error, save the document and refresh Marked 2, the equation don't update, but appears as if no changes where made. I have to edit somewhere else in the document for Marked 2 to refresh properly. The html export issues are the same as before,  translates to \( and  translates to \[, resulting in syntax error. The last but not least snippet worked before, but are not rendered at all anymore. Every snippet here works as expected on stackedit.io, which also use katex.  \rightarrow ONE - TWO - THREE \\ \rightarrow FOUR - FIVE - SIX   9. Support Staff Posted by Brett on 25 Sep, 2021 06:33 PM Just tested running it directly through MultiMarkdown and that's definitely where the syntax conversion is happening. I can't do anything about that. However, I can adjust the exported HTML to handle them. If you want to edit the exports yourself, here's what needs to be included (replacing the Katex script reference that Marked includes now). I'll be updating Marked to do this itself soon. <script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.js" integrity="sha384-GxNFqL3r9uRJQhR+47eDxuPoNE7yLftQM8LcxzgS4HT73tp970WS/wV5p8UzCOmb" crossorigin="anonymous"></script> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/contrib/auto-render.min.js" integrity="sha384-vZTG03m+2yp6N6BNi5iM4rW4oIwk5DfcNdFfxkk9ZWpDriOkXX8voJBFrAO7MpVl" crossorigin="anonymous"></script> <script> document.addEventListener("DOMContentLoaded", function() { renderMathInElement(document.body, { // customised options // • auto-render specific keys, e.g.: delimiters: [ {left: '', right: '', display: true}, {left: '', right: '', display: false}, {left: '\\(', right: '\$$', display: false}, {left: '\\[', right: '\$', display: true} ], // • rendering keys, e.g.: throwOnError : false }); }); </script>  As far as the bug where you can't make edits inside of equations goes, I'm going to have to look further into that. Until I solve it, you can get around it by just placing the cursor outside of the  and hitting space->⌘S to get it to update the render.

## Reply to this discussion

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

### »

#### Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

# Keyboard shortcuts

### Generic

? Show this help Blurs the current field

### Comment Form

r Focus the comment reply box Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

## Recent Discussions

 25 Sep, 2021 06:33 PM Katex not rendering correctly in html export 24 Sep, 2021 08:39 PM Bottom Scroll Bar 18 Sep, 2021 11:13 AM Collating multiple GitHub md files into one a single formatted and branded PDF file. For the PDF version 13 Sep, 2021 09:19 PM ATX-style heading not rendered if text is enclosed in square brackets 10 Sep, 2021 03:14 PM Document goes blank and shows

## Recent Articles

 Intra-document links in exported PDFs Using Ulysses with Marked Fenced code blocks inside indented code blocks Using JavaScript in Marked Custom CSS: Writing custom CSS for Marked