From 80dc6c69baa952816fb869d854d8e3a159e87afc Mon Sep 17 00:00:00 2001 From: HouJP Date: Sat, 6 Jan 2024 09:32:34 +0800 Subject: [PATCH] Feature: Migrates to MathJax version 3 and supports setting different configuration files (defaults to 'tex-mml-chtml'). --- guide/src/format/configuration/renderers.md | 3 +++ src/config.rs | 3 +++ src/renderer/html_handlebars/hbs_renderer.rs | 4 ++++ src/theme/index.hbs | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/guide/src/format/configuration/renderers.md b/guide/src/format/configuration/renderers.md index 7e7430141a..12d0d9917e 100644 --- a/guide/src/format/configuration/renderers.md +++ b/guide/src/format/configuration/renderers.md @@ -99,6 +99,7 @@ default-theme = "light" preferred-dark-theme = "navy" curly-quotes = true mathjax-support = false +mathjax-config = "tex-mml-chtml" copy-fonts = true additional-css = ["custom.css", "custom2.css"] additional-js = ["custom.js"] @@ -126,6 +127,8 @@ The following configuration options are available: that occur in code blocks and code spans. Defaults to `false`. - **mathjax-support:** Adds support for [MathJax](../mathjax.md). Defaults to `false`. +- **mathjax-config:** The [configuration file](https://docs.mathjax.org/en/latest/web/components/combined.html) + used by MathJax. Defaults to `tex-mml-chtml`. - **copy-fonts:** (**Deprecated**) If `true` (the default), mdBook uses its built-in fonts which are copied to the output directory. If `false`, the built-in fonts will not be used. This option is deprecated. If you want to define your own custom fonts, diff --git a/src/config.rs b/src/config.rs index 7f56e797ab..468e57166f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -530,6 +530,8 @@ pub struct HtmlConfig { pub curly_quotes: bool, /// Should mathjax be enabled? pub mathjax_support: bool, + /// The configuration file used by MathJax, defaults to 'tex-mml-chtml'. + pub mathjax_config: Option, /// Whether to fonts.css and respective font files to the output directory. pub copy_fonts: bool, /// An optional google analytics code. @@ -592,6 +594,7 @@ impl Default for HtmlConfig { preferred_dark_theme: None, curly_quotes: false, mathjax_support: false, + mathjax_config: Some(String::from("tex-mml-chtml")), copy_fonts: true, google_analytics: None, additional_css: Vec::new(), diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index c701729fcb..6e08203bba 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -667,6 +667,10 @@ fn make_data( if html_config.mathjax_support { data.insert("mathjax_support".to_owned(), json!(true)); } + data.insert( + "mathjax_config".to_owned(), + json!(html_config.mathjax_config.clone().unwrap_or_default()), + ); // This `matches!` checks for a non-empty file. if html_config.copy_fonts || matches!(theme.fonts_css.as_deref(), Some([_, ..])) { diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 080b78516a..26feeb52e7 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -50,7 +50,7 @@ {{#if mathjax_support}} - + {{/if}}