From 9c55840ca87fb369f3a6d828d83075698899339e Mon Sep 17 00:00:00 2001 From: expikr <77922942+expikr@users.noreply.github.com> Date: Thu, 23 Nov 2023 20:17:18 +0800 Subject: [PATCH] Add asciimath support Update mathjax.md --- guide/src/format/configuration/renderers.md | 3 +++ guide/src/format/mathjax.md | 13 +++++++++++++ src/config.rs | 3 +++ src/renderer/html_handlebars/hbs_renderer.rs | 4 ++++ src/theme/index.hbs | 4 ++++ test_book/book.toml | 1 + 6 files changed, 28 insertions(+) diff --git a/guide/src/format/configuration/renderers.md b/guide/src/format/configuration/renderers.md index 16a42516..f6970e17 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 +asciimath-support = false 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`. +- **asciimath-support:** Enables AsciiMath for [MathJax](../mathjax.md) if enabled, otherwise has no effect. Defaults to + `false`. - **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/guide/src/format/mathjax.md b/guide/src/format/mathjax.md index 3dd79215..e1d6768f 100644 --- a/guide/src/format/mathjax.md +++ b/guide/src/format/mathjax.md @@ -41,3 +41,16 @@ you would write: ```bash \\[ \mu = \frac{1}{N} \sum_{i=0} x_i \\] ``` + +### AsciiMath syntax + +[AsciiMath](http://asciimath.org/) is a less verbose equation syntax than LaTeX, delimited by \\\`...\\\`. + +To enable AsciiMath, you need to add the `asciimath-support` key to your `book.toml` +under the `output.html` section, in addition to enabling `mathjax-support`: + +```toml +[output.html] +mathjax-support = true +asciimath-support = true +``` \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index 1a30c507..a43e06bb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -490,6 +490,8 @@ pub struct HtmlConfig { pub curly_quotes: bool, /// Should mathjax be enabled? pub mathjax_support: bool, + /// Should asciimath be enabled? + pub asciimath_support: bool, /// Whether to fonts.css and respective font files to the output directory. pub copy_fonts: bool, /// An optional google analytics code. @@ -550,6 +552,7 @@ impl Default for HtmlConfig { preferred_dark_theme: None, curly_quotes: false, mathjax_support: false, + asciimath_support: false, 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 e170e2fc..7ac4f9f6 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -681,6 +681,10 @@ fn make_data( data.insert("mathjax_support".to_owned(), json!(true)); } + if html_config.asciimath_support { + data.insert("asciimath_support".to_owned(), json!(true)); + } + // This `matches!` checks for a non-empty file. if html_config.copy_fonts || matches!(theme.fonts_css.as_deref(), Some([_, ..])) { data.insert("copy_fonts".to_owned(), json!(true)); diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 6f3948c6..d2fab36b 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -50,8 +50,12 @@ {{#if mathjax_support}} + {{#if asciimath_support}} + + {{else}} {{/if}} + {{/if}}
diff --git a/test_book/book.toml b/test_book/book.toml index a3050076..5f4485cf 100644 --- a/test_book/book.toml +++ b/test_book/book.toml @@ -9,6 +9,7 @@ edition = "2018" [output.html] mathjax-support = true +asciimath-support = true [output.html.playground] editable = true