Skip to content

Commit 1c59502

Browse files
committed
Upgrade to MathJax 4 and use some heuristic to detect inline or center.
1 parent d231427 commit 1c59502

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

converter/generator/DocToStaticPagesTransformer.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,16 @@ protected internal override void Transform(IHtmlDocument document, IHtmlHeadElem
8383
if (img.ClassList.Contains("tex"))
8484
{
8585
var span = document.CreateElement<IHtmlSpanElement>();
86-
8786
span.ClassName = "tex";
88-
span.TextContent = $@"\({img.AlternativeText}\)";
87+
88+
if (img.IsOnlyChild() && img.Parent!.ChildNodes.OfType<IText>().All(t => t.Text.IsBlank))
89+
{
90+
span.TextContent = $@"\[{img.AlternativeText}\]";
91+
}
92+
else
93+
{
94+
span.TextContent = $@"\({img.AlternativeText}\)";
95+
}
8996

9097
return span;
9198
}

converter/templates/Layouts/Site.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<link href="~/books/style.css" asp-append-version="true" rel="stylesheet" />
1717
<script src="~/books/script.js" asp-append-version="true"></script>
1818

19-
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML'></script>
19+
<script src="https://cdn.jsdelivr.net/npm/mathjax@4/tex-chtml.js"></script>
2020

2121
@RenderSection("head", required: false)
2222
</head>

converter/templates/wwwroot/books/script.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,8 @@ window.MathJax = {
9797
options: {
9898
processHtmlClass: 'tex',
9999
ignoreHtmlClass: '.*'
100+
},
101+
chtml: {
102+
scale: 1.2 // Boosts font size globally
100103
}
101104
};

0 commit comments

Comments
 (0)