commit 2aae846cf4e6a44389c92ed00132ac8a89b57d7d
parent d9de8146e881d772a6d158b706c59d094cd78a6e
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Fri, 21 Jul 2017 02:51:10 +0200
Fixed some mathjax-related problems (performance and appearance). Turned off MathJax in the pre-rendered HTML (for now). [fastbuild]
Diffstat:
8 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/run-mathjax-offline.node.js b/run-mathjax-offline.node.js
@@ -32,6 +32,7 @@ jsdom.env('doc/phc-thesis/index.html', function(err, window) {
return mm;
};
var mm = getmath();
+ var addedCSS = [];
var processMathElement = function(i) {
if (i >= mm.length) {
process.stdout.write('\nSaving modified HTML file…\n');
@@ -53,11 +54,16 @@ jsdom.env('doc/phc-thesis/index.html', function(err, window) {
mm[i].classList.add('math-initial-hidden');
// Add the CSS to the document
- var css = window.document.createElement('style');
- css.setAttribute('type', 'text/css');
- var csstxt = window.document.createTextNode(result.css);
- css.appendChild(csstxt);
- window.document.head.appendChild(css);
+ if (addedCSS.indexOf(result.css) == -1){
+ addedCSS.push(result.css);
+ // Inject font-display: block; to prevent the browsers from stalling while applying fonts each time a new one is loaded.
+ var css = result.css.split('@font-face {').join('@font-face {font-display: block; ');
+ var styleElt = window.document.createElement('style');
+ styleElt.setAttribute('type', 'text/css');
+ var styleTxt = window.document.createTextNode(css);
+ styleElt.appendChild(styleTxt);
+ window.document.head.appendChild(styleElt);
+ }
// wrap the generated element in a class="MathJax_Preview" node
preview = window.document.createElement((mm[i].tagName.toLowerCase() == 'div' ? 'div' : 'span'));
@@ -70,6 +76,14 @@ jsdom.env('doc/phc-thesis/index.html', function(err, window) {
});
}
};
+ // Remove the script which loads MathJax automatically, as it slows down things a lot when it re-renders the math.
+ var scriptsInHead = window.document.head.getElementByTagName('script');
+ for (var i = 0; i < scriptsInHead.length; i++) {
+ var e = scriptsInHead.item(i);
+ if (e.innerHTML.trim() == decodeURI("(function()%20%7Bdocument.write('%3Cscr'%20+%20'ipt%20type=%22text/javascript%22%20src=%22MathJax/MathJax.js?config=default%22%3E%3C/scr'%20+%20'ipt%3E');%7D)();")) {
+ e.parentNode.removeChild(e);
+ }
+ }
// Fix the font size (mathjax-node cannot know easily the webpage's font size in advance).
var patchFontSizeCode = "(function() { var outer = document.createElement('div'); outer.style.width = '0px'; outer.style.height = '0px'; outer.style.overflow = 'hidden'; var d = document.createElement('div'); /* 1.18rem from scribble's stylesheet, times 118% in the MathJax-generated CSS. */ outer.style.fontSize = (1.18 * 1.18) + 'rem'; d.style.width = '1000em'; outer.appendChild(d); document.body.appendChild(outer); window.setTimeout(function() { var sz = d.clientWidth / 1000; document.body.removeChild(outer); if (sz > 3) { var st = document.createElement('style'); st.appendChild(document.createTextNode('html .mjx-chtml { font-size: '+sz+'px; } html .mjx-chtml .mjx-chtml { font-size: inherit; }')); document.head.appendChild(st); } }, 0)})();";
var patchFontSize = window.document.createElement('script');
diff --git a/scribblings/adt-pe.scrbl b/scribblings/adt-pe.scrbl
@@ -20,7 +20,7 @@ a conditional.
define it.}
@todo{How should I note cleanly these removals / replacements which refer to
- an ɐ and its τ or @${v} inside the set of @${@|ɐ|ᵢ}?}
+ an @|ɐ| and its τ or @${v} inside the set of @${@|ɐ|ᵢ}?}
@$${
@aligned{
diff --git a/scribblings/adt-row-pe.scrbl b/scribblings/adt-row-pe.scrbl
@@ -22,7 +22,7 @@ a conditional.
define it.}
@todo{How should I note cleanly these removals / replacements which refer to
- an ɐ and its τ or @${v} inside the set of @${@|ɐ|ᵢ}?}
+ an @|ɐ| and its τ or @${v} inside the set of @${@|ɐ|ᵢ}?}
@$${
@aligned{
diff --git a/scribblings/adt-row-shorthands.scrbl b/scribblings/adt-row-shorthands.scrbl
@@ -46,10 +46,12 @@ the following types:
The polymorphic builder function for a record which
-intuitively corresponds to @record[@repeated{ɐ}] can be written as the
-η-expansion of the @record[@repeated{ɐ = e}] operator:
+intuitively corresponds to @record[@repeated{@ɐ}] can be written as the
+η-expansion of the @record[@repeated{@ɐ = e}] operator:
-@$${(Λ (@repeated{αᵢ}) (λ (@repeated{[xᵢ : αᵢ]}) @record[@repeated{ɐᵢ = xᵢ}]))}
+@$${
+ (Λ (@repeated{αᵢ}) (λ (@repeated{[xᵢ : αᵢ]}) @record[@repeated{@|ɐ|ᵢ = xᵢ}]))
+}
The same applies to the predicate form of records:
diff --git a/scribblings/adt-row-trules.scrbl b/scribblings/adt-row-trules.scrbl
@@ -124,7 +124,7 @@ are in the main part).
Γ ⊢ e_{v} : τ_{v} ; φ_{v} ; o_{v} \\
@|ɐ|ⱼ : τ'ⱼ ∈ @repeatset{@|ɐ|ᵢ : τ'ᵢ}
}
- @${Γ ⊢ @opwith[@${e_{r}} @|ɐⱼ| @${e_{v}}]
+ @${Γ ⊢ @opwith[@${e_{r}} @${@|ɐ|ⱼ} @${e_{v}}]
: @record[@${@repeatset{@|ɐ|ᵢ : τ'ᵢ} ∖ \{@|ɐ|ⱼ : τ'ⱼ\}}
@${@|ɐ|ⱼ : τ_{v}}
@ρf]@;changed
diff --git a/scribblings/adt-trules.scrbl b/scribblings/adt-trules.scrbl
@@ -113,7 +113,7 @@ in@~cite[#:precision "p. 75" "tobin-hochstadt_typed_2010"].
Γ ⊢ e_{v} : τ_{v} ; φ_{v} ; o_{v} \\
@|ɐ|ⱼ : τ'ⱼ ∈ @repeatset{@|ɐ|ᵢ : τ'ᵢ}
}
- @${Γ ⊢ @opwith[@${e_{r}} @|ɐⱼ| @${e_{v}}]
+ @${Γ ⊢ @opwith[@${e_{r}} @${@|ɐ|ⱼ} @${e_{v}}]
: @record[@${@repeatset{@|ɐ|ᵢ : τ'ᵢ} ∖ \{@|ɐ|ⱼ : τ'ⱼ\}} @${@|ɐ|ⱼ : τ_{v}}]
; ϵ|⊥ ; ∅}
@${@textsc{T-Record-With}_2}
diff --git a/scribblings/util.rkt b/scribblings/util.rkt
@@ -157,6 +157,7 @@
(define m
(list setup-math
(tex-header #<<EOTEX
+ \def\ifmathjax#1{}\def\iflatex#1{#1}
\renewcommand{\rmdefault}{cmr}
\newenvironment{qaligned}{%
\begin{array}[t]{@{}r@{}c@{}l@{}}%
@@ -183,7 +184,8 @@ EOTEX
html .MathJax_Display, html div.MathJax_Preview {
margin: 2em 0;
-}"))))))
+}"))))
+ @${\def\ifmathjax#1{#1}\def\iflatex#1{}}))
(define my-title
;; TODO: use this for the other wrapped procs in this file
(make-keyword-procedure
diff --git a/scribblings/util0.rkt b/scribblings/util0.rkt
@@ -5,7 +5,7 @@
scribble/latex-properties
scribble/html-properties
scribble-math
- scribble-math/katex-convert-unicode)
+ scribble-math/mathjax-convert-unicode)
(provide mathtext
(rename-out [$* $]
@@ -54,7 +54,7 @@
mathmode?))]
[(string? e)
;; TODO: do this only when compiling to HTML.
- (katex-convert-unicode e mathmode?)]
+ (mathjax-convert-unicode e mathmode?)]
[else e]))
(define ($* . elts)