commit 8da88bcd772e229a7fac68028e3b229abb1c9113
parent 25b205f2fe0c83daab429db5faa6d7630b6be968
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Wed, 12 Jul 2017 19:48:06 +0200
Improved math rendering, fixed server-side math pre-rendering.
Diffstat:
4 files changed, 46 insertions(+), 45 deletions(-)
diff --git a/.travis.yml b/.travis.yml
@@ -41,8 +41,6 @@ jobs:
- texlive-latex-recommended
- latex-xcolor
install:
- - nvm install v8.1 # works with v8.1.4
- - npm install mathjax-node
- if test "$TRAVIS_BUILD_ID" != `cat ~/.racket/travis_build_id`; then travis_terminate 1; fi
- rm -f ~/.racket/travis_build_id
- echo "LaTeX extra packages:"
@@ -67,6 +65,8 @@ jobs:
- find doc -name '*.html' -type f -print0 | xargs -0 ls -ld
- find doc -name '*.html' -type f -print0 | xargs -0 sed -i -e 's|https://download\.racket-lang\.org/docs/6\.9/html/|https://docs.racket-lang.org/|g'
- find doc -name '*.html' -type f -print0 | xargs -0 ls -ld
+ - nvm install v8.1 # works with v8.1.4
+ - npm install mathjax-node
- node < run-mathjax-offline.node.js
- mv doc/phc-thesis/index2.html doc/phc-thesis/index.html
- if test "x${DEPLOY:-}" = "xtrue"; then sh ./auto-push-gh-pages.sh; fi
diff --git a/run-mathjax-offline.node.js b/run-mathjax-offline.node.js
@@ -4,20 +4,23 @@ const mjAPI = require('mathjax-node');
const jsdom = require('jsdom');
// Dynamically load the original MathJax config from …/MathJax/config/default.js
-mjAPI.config({ MathJax: (function() {
- var cfg = {};
- var MathJax = {
- Hub: {
- Config: function(c) { cfg = c; }
- },
- Ajax: {
- loadComplete: function() { return; }
- }
- };
- cfgbytes = fs.readFileSync('doc/phc-thesis/MathJax/config/default.js');
- eval(cfgbytes + '');
- return cfg;
-})(), });
+mjAPI.config({
+ fontURL: 'MathJax/fonts/HTML-CSS/',
+ MathJax: (function() {
+ var cfg = {};
+ var MathJax = {
+ Hub: {
+ Config: function(c) { cfg = c; }
+ },
+ Ajax: {
+ loadComplete: function() { return; }
+ }
+ };
+ cfgbytes = fs.readFileSync('doc/phc-thesis/MathJax/config/default.js');
+ eval(cfgbytes + '');
+ return cfg;
+ })(),
+});
jsdom.env('doc/phc-thesis/index.html', function(err, window) {
var getmath = function () {
@@ -29,18 +32,23 @@ jsdom.env('doc/phc-thesis/index.html', function(err, window) {
return mm;
};
var mm = getmath();
- var process = function(i) {
+ var processMathElement = function(i) {
if (i >= mm.length) {
+ process.stdout.write('\nSaving modified HTML file…\n');
fs.writeFileSync('doc/phc-thesis/index2.html', jsdom.serializeDocument(window.document));
return;
} else {
+ process.stdout.write((i+1)+'/'+mm.length+' '+(mm[i].tagName.toLowerCase() == 'div' ? 'display' : 'inline ')+'\r');
mjAPI.typeset({
- math: mm[i].innerHTML,
- format: 'inline-TeX',
+ math: mm[i].textContent,
+ format: (mm[i].tagName.toLowerCase() == 'div' ? 'TeX' : 'inline-TeX'),
htmlNode: true,
css: true,
}, function(result) {
- if (!(result.errors)) {
+ if (result.errors) {
+ console.log(mm[i].textContent);
+ process.exit(1);
+ } else {
// mark the initial element as hidden
mm[i].classList.add('math-initial-hidden');
@@ -52,18 +60,18 @@ jsdom.env('doc/phc-thesis/index.html', function(err, window) {
window.document.head.appendChild(css);
// wrap the generated element in a class="MathJax_Preview" node
- preview = window.document.createElement(result.tagName);
+ preview = window.document.createElement((mm[i].tagName.toLowerCase() == 'div' ? 'div' : 'span'));
preview.setAttribute('class', 'MathJax_Preview');
preview.appendChild(result.htmlNode);
mm[i].parentNode.insertBefore(preview, mm[i]);
//console.log(result.htmlNode);
- process(i+1);
+ processMathElement(i+1);
}
});
}
};
// Fix the font size (mathjax-node cannot know easily the webpage's font size in advance).
- var patchFontSizeCode = "(function() { var d = document.createElement('div'); d.style.width = '2260ex'; document.body.appendChild(d); window.setTimeout(function() { var sz = d.clientWidth / 1000; document.body.removeChild(d); if (sz > 3) { var st = document.createElement('style'); st.appendChild(document.createTextNode('.mjx-chtml { font-size: '+sz+'px; } .mjx-chtml .mjx-chtml {font-size: inherit }')); document.head.appendChild(st); } }, 0)})();";
+ var patchFontSizeCode = "(function() { var d = document.createElement('div'); d.style.width = '2260ex'; document.body.appendChild(d); window.setTimeout(function() { var sz = d.clientWidth / 1000; document.body.removeChild(d); 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');
patchFontSize.appendChild(window.document.createTextNode(patchFontSizeCode));
patchFontSize.setAttribute('type', 'text/javascript');
@@ -72,7 +80,7 @@ jsdom.env('doc/phc-thesis/index.html', function(err, window) {
// set the initial <span class="math math-initial-hidden"></span> and <div …></div> elements hidden, as we manually injected a preview.
hidestyle = window.document.createElement('style');
hidestyle.setAttribute('type', 'text/css');
- hidestyle.appendChild(window.document.createTextNode('.math-initial-hidden { display:none; visibility:hidden; } .MathJax_Preview { color: inherit; }'));
+ hidestyle.appendChild(window.document.createTextNode('html .math-initial-hidden { display:none; visibility:hidden; } html .MathJax_Preview { color: inherit; }'));
window.document.head.appendChild(hidestyle);
- process(0);
+ processMathElement(0);
});
diff --git a/scribblings/adt-row-e.scrbl b/scribblings/adt-row-e.scrbl
@@ -40,8 +40,8 @@ the value stored in an instance of a constructor.
@acase{…}
@acase{@record[@repeated{@|ɐ|ᵢ = eᵢ}]}
- @acase{(@record-pred[@repeated{@|ɐ|ᵢ}] e)}
- @acase{(@record-pred*[@repeated{@|ɐ|ᵢ} @repeated{-@|ɐ|ⱼ}] e)}@;added
+ @acase{(@record-pred[@repeated{@|ɐ|ᵢ}]\ e)}
+ @acase{(@record-pred*[@repeated{@|ɐ|ᵢ} @repeated{-@|ɐ|ⱼ}]\ e)}@;added
@acase{e.@|ɐ|}
@acase{@opwith[e @|ɐ| e]}
@acase{@opwithout[e @|ɐ|]}
diff --git a/scribblings/util0.rkt b/scribblings/util0.rkt
@@ -8,7 +8,6 @@
scribble-math/katex-convert-unicode)
(provide mathtext
- clean-$
(rename-out [$* $]
[$$* $$]))
@@ -17,14 +16,16 @@
(apply elem #:style (style "mathText"
(list (tex-addition #"\\def\\mathText#1{#1}")
'exact-chars))
- l))
+ (clean-$ l #f)))
;; Math stuff
-(define (clean-$ e)
- (cond [(pair? e) (cons (clean-$ (car e)) (clean-$ (cdr e)))]
+(define (clean-$ e mathmode?)
+ (cond [(pair? e) (cons (clean-$ (car e) mathmode?)
+ (clean-$ (cdr e) mathmode?))]
[(traverse-element? e)
(traverse-element (λ (a b)
- (clean-$ ((traverse-element-traverse e) a b))))]
+ (clean-$ ((traverse-element-traverse e) a b)
+ mathmode?)))]
[(match e
[(element (style (or "math" "texMathInline" "texMathDisplay") _)
content)
@@ -34,9 +35,6 @@
;; been cleaned when the e was created. Plus we risk re-escaping
;; things within \text{…}.
(element-content e)]
- [(match e [(element (style "mathWrapper" _) _) #t]
- [_ #f])
- (clean-$ (element-content e))]
[(match e
[(element (style "mathText" _)
content)
@@ -50,20 +48,15 @@
(element-content e)]
[(element? e)
(element (element-style e)
- (clean-$ (element-content e)))]
+ (clean-$ (element-content e)
+ mathmode?))]
[(string? e)
;; TODO: do this only when compiling to HTML.
- (katex-convert-unicode e)]
+ (katex-convert-unicode e mathmode?)]
[else e]))
-(define (math-wrapper $m)
- (element (style "mathWrapper"
- (list (tex-addition #"\\def\\mathWrapper#1{#1}")
- (css-addition #".mathWrapper { font-size: medium; }")))
- $m))
-
(define ($* . elts)
- (math-wrapper (apply $ (clean-$ elts))))
+ (apply $ (clean-$ elts #t)))
(define ($$* . elts)
- (math-wrapper (apply $$ (clean-$ elts))))
+ (apply $$ (clean-$ elts #t)))