Skip to content

Commit

Permalink
Add asciimath support
Browse files Browse the repository at this point in the history
Update mathjax.md
  • Loading branch information
expikr committed Nov 23, 2023
1 parent 41567b0 commit 9c55840
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions guide/src/format/configuration/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions guide/src/format/mathjax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kbd>\\\`...\\\`</kbd>.

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
```
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@

{{#if mathjax_support}}
<!-- MathJax -->
{{#if asciimath_support}}
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>
{{else}}
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
{{/if}}
{{/if}}
</head>
<body>
<div id="body-container">
Expand Down
1 change: 1 addition & 0 deletions test_book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2018"

[output.html]
mathjax-support = true
asciimath-support = true

[output.html.playground]
editable = true
Expand Down

0 comments on commit 9c55840

Please sign in to comment.