Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upgrades to MathJax version 3 and supports setting different configuration files (defaults to 'tex-mml-chtml'). #2285

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mathjax-config = "tex-mml-chtml"
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`.
- **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,
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// 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 @@ -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(),
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 @@ -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([_, ..])) {
Expand Down
2 changes: 1 addition & 1 deletion src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

{{#if mathjax_support}}
<!-- MathJax -->
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/{{ mathjax_config }}.js"></script>
{{/if}}
</head>
<body class="sidebar-visible no-js">
Expand Down