Skip to content

Commit b12f67c

Browse files
author
_
committed
Add asciimath support
Update mathjax.md
1 parent dec0e24 commit b12f67c

File tree

6 files changed

+28
-0
lines changed

6 files changed

+28
-0
lines changed

guide/src/format/configuration/renderers.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ default-theme = "light"
9999
preferred-dark-theme = "navy"
100100
curly-quotes = true
101101
mathjax-support = false
102+
asciimath-support = false
102103
copy-fonts = true
103104
additional-css = ["custom.css", "custom2.css"]
104105
additional-js = ["custom.js"]
@@ -126,6 +127,8 @@ The following configuration options are available:
126127
that occur in code blocks and code spans. Defaults to `false`.
127128
- **mathjax-support:** Adds support for [MathJax](../mathjax.md). Defaults to
128129
`false`.
130+
- **asciimath-support:** Enables AsciiMath for [MathJax](../mathjax.md) if enabled, otherwise has no effect. Defaults to
131+
`false`.
129132
- **copy-fonts:** (**Deprecated**) If `true` (the default), mdBook uses its built-in fonts which are copied to the output directory.
130133
If `false`, the built-in fonts will not be used.
131134
This option is deprecated. If you want to define your own custom fonts,

guide/src/format/mathjax.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,16 @@ you would write:
4141
```bash
4242
\\[ \mu = \frac{1}{N} \sum_{i=0} x_i \\]
4343
```
44+
45+
### AsciiMath syntax
46+
47+
[AsciiMath](http://asciimath.org/) is a less verbose equation syntax than LaTeX, delimited by <kbd>\\\`...\\\`</kbd>.
48+
49+
To enable AsciiMath, you need to add the `asciimath-support` key to your `book.toml`
50+
under the `output.html` section, in addition to enabling `mathjax-support`:
51+
52+
```toml
53+
[output.html]
54+
mathjax-support = true
55+
asciimath-support = true
56+
```

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ pub struct HtmlConfig {
490490
pub curly_quotes: bool,
491491
/// Should mathjax be enabled?
492492
pub mathjax_support: bool,
493+
/// Should asciimath be enabled?
494+
pub asciimath_support: bool,
493495
/// Whether to fonts.css and respective font files to the output directory.
494496
pub copy_fonts: bool,
495497
/// An optional google analytics code.
@@ -550,6 +552,7 @@ impl Default for HtmlConfig {
550552
preferred_dark_theme: None,
551553
curly_quotes: false,
552554
mathjax_support: false,
555+
asciimath_support: false,
553556
copy_fonts: true,
554557
google_analytics: None,
555558
additional_css: Vec::new(),

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,10 @@ fn make_data(
681681
data.insert("mathjax_support".to_owned(), json!(true));
682682
}
683683

684+
if html_config.asciimath_support {
685+
data.insert("asciimath_support".to_owned(), json!(true));
686+
}
687+
684688
// This `matches!` checks for a non-empty file.
685689
if html_config.copy_fonts || matches!(theme.fonts_css.as_deref(), Some([_, ..])) {
686690
data.insert("copy_fonts".to_owned(), json!(true));

src/theme/index.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@
5050

5151
{{#if mathjax_support}}
5252
<!-- MathJax -->
53+
{{#if asciimath_support}}
54+
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>
55+
{{else}}
5356
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
5457
{{/if}}
58+
{{/if}}
5559
</head>
5660
<body>
5761
<div id="body-container">

test_book/book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition = "2018"
99

1010
[output.html]
1111
mathjax-support = true
12+
asciimath-support = true
1213

1314
[output.html.playground]
1415
editable = true

0 commit comments

Comments
 (0)