Skip to content

Add optional math support for markdown#2708

Open
recmo wants to merge 19 commits into
getzola:nextfrom
recmo:recmo/enable-math
Open

Add optional math support for markdown#2708
recmo wants to merge 19 commits into
getzola:nextfrom
recmo:recmo/enable-math

Conversation

@recmo

@recmo recmo commented Nov 18, 2024

Copy link
Copy Markdown

IMPORTANT: Please do not create a Pull Request adding a new feature without discussing it first.

The place to discuss new features is the forum: https://zola.discourse.group/
If you want to add a new feature, please open a thread there first in the feature requests section.

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

(Delete or ignore this section for documentation changes)

  • Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • Have you created/updated the relevant documentation page(s)?

This fixes #2019 without adding substantial complexity or dependencies. It optionally enables a common-mark extension available in pulldown-cmark.

This will correctly parse delimited math, and render html like <span class="math math-inline">\sum_i x_i<\span>.

To render the latex using Katex, include something like this in the header:

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css"
        integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+"
        crossorigin="anonymous">
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js"
        integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg"
        crossorigin="anonymous"></script>
    <script defer>
        document.addEventListener("DOMContentLoaded", function () {
            const macros = {};
            for (let el of document.getElementsByClassName('math')) {
              katex.render(el.textContent, el, {
                output: 'html',
                throwOnError: false,
                displayMode: el.classList.contains('math-display'),
                macros,
              });
            }
        });
    </script>

@recmo recmo changed the title Recmo/enable math Add optional math support for markdown Nov 18, 2024
@recmo recmo force-pushed the recmo/enable-math branch from a52418a to b513f1f Compare November 18, 2024 15:24
Comment thread components/config/src/config/markup.rs Outdated
/// Whether smart punctuation is enabled (changing quotes, dashes, dots etc in their typographic form)
pub smart_punctuation: bool,
/// Whether to enable latex math rendering
pub math: bool,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want that to be an enum. Eventually (hopefully) there will be math rendering inside Zola (eg https://zola.discourse.group/t/a-simpler-katex-alternative-that-works-today/2156/3) so we will want to support classes/pre-render etc

matoutech and others added 18 commits January 24, 2026 22:19
Updated changelog to reflect breaking changes in version 0.22.0.
Co-authored-by: Keats <680355+Keats@users.noreply.github.com>
Signed-off-by: zyxhere💭 <zyx@envs.net>
Co-authored-by: Keats <680355+Keats@users.noreply.github.com>
…tzola#3110)

* docs: Add link to TextMate themes in configuration and highlighting docs getzola#3088

* docs: revise TextMate themes link wording
@recmo recmo force-pushed the recmo/enable-math branch from 284ffcb to 9a77052 Compare May 4, 2026 21:20
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 this pull request may close these issues.

8 participants