From 99e24db07564eb917e9209724a62c78cb7fd3ab4 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 23 Jul 2018 15:30:58 +0100 Subject: [PATCH 1/3] Move MathJax config to base so it is always run This prevents an issue where using MathJax would not be configured correctly unless using the mathjax directive. --- services/web/public/coffee/base.coffee | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/services/web/public/coffee/base.coffee b/services/web/public/coffee/base.coffee index cb9e70b6bf..e5e0958a24 100644 --- a/services/web/public/coffee/base.coffee +++ b/services/web/public/coffee/base.coffee @@ -26,7 +26,22 @@ define [ baseUrl: window.sharelatex.sixpackDomain client_id: window.user_id }) - + + MathJax?.Hub?.Config( + extensions: ["Safe.js"] + messageStyle: "none" + imageFont:null + "HTML-CSS": { availableFonts: ["TeX"] }, + TeX: + equationNumbers: { autoNumber: "AMS" }, + useLabelIDs: false + skipStartupTypeset: true + tex2jax: + processEscapes: true, + inlineMath: [ ["\\(","\\)"] ], + displayMath: [ ['$$','$$'], ["\\[","\\]"] ] + ) + App.run ($templateCache) -> # UI Select templates are hard-coded and use Glyphicon icons (which we don't import). # The line below simply overrides the hard-coded template with our own, which is From db518e16aa596ad93bd04df0fc4a2f68bd5540cb Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 23 Jul 2018 15:32:17 +0100 Subject: [PATCH 2/3] Don't set config unless needed in directive Updates mathjax directive to only set config if it is needed. The main config is now set in base.coffee so isn't needed --- .../public/coffee/directives/mathjax.coffee | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/services/web/public/coffee/directives/mathjax.coffee b/services/web/public/coffee/directives/mathjax.coffee index 269526287e..7124318214 100644 --- a/services/web/public/coffee/directives/mathjax.coffee +++ b/services/web/public/coffee/directives/mathjax.coffee @@ -4,23 +4,16 @@ define [ App.directive "mathjax", () -> return { link: (scope, element, attrs) -> - mathjaxConfig = - extensions: ["Safe.js"] - messageStyle: "none" - imageFont:null - "HTML-CSS": { availableFonts: ["TeX"] }, - TeX: - equationNumbers: { autoNumber: "AMS" }, - useLabelIDs: false - skipStartupTypeset: true - tex2jax: - processEscapes: true, - inlineMath: [ ["\\(","\\)"] ], - displayMath: [ ['$$','$$'], ["\\[","\\]"] ] if attrs.delimiter != 'no-single-dollar' - mathjaxConfig.tex2jax.inlineMath.push(['$','$']); + inlineMathConfig = MathJax?.Hub?.config?.tex2jax.inlineMath + alreadyConfigured = _.find inlineMathConfig, (c) -> + c[0] == '$' and c[1] == '$' - MathJax?.Hub?.Config(mathjaxConfig); + if !alreadyConfigured? + MathJax?.Hub?.Config( + tex2jax: + inlineMath: inlineMathConfig.concat([['$', '$']]) + ) setTimeout () -> MathJax?.Hub?.Queue(["Typeset", MathJax?.Hub, element.get(0)]) From 9af906b7dcf5573ea61eaebb3031c94370733ee8 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 23 Jul 2018 16:03:49 +0100 Subject: [PATCH 3/3] Copy across some mathjax config from v1, seems to fix artefacts in rendering --- services/web/public/coffee/base.coffee | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/services/web/public/coffee/base.coffee b/services/web/public/coffee/base.coffee index e5e0958a24..0a6f47f9fa 100644 --- a/services/web/public/coffee/base.coffee +++ b/services/web/public/coffee/base.coffee @@ -31,14 +31,21 @@ define [ extensions: ["Safe.js"] messageStyle: "none" imageFont:null - "HTML-CSS": { availableFonts: ["TeX"] }, + "HTML-CSS": + availableFonts: ["TeX"] + # MathJax's automatic font scaling does not work well when we render math + # that isn't yet on the page, so we disable it and set a global font + # scale factor + scale: 110 + matchFontHeight: false TeX: - equationNumbers: { autoNumber: "AMS" }, + equationNumbers: { autoNumber: "AMS" } useLabelIDs: false skipStartupTypeset: true tex2jax: - processEscapes: true, - inlineMath: [ ["\\(","\\)"] ], + processEscapes: true + # Dollar delimiters are added by the mathjax directive + inlineMath: [ ["\\(","\\)"] ] displayMath: [ ['$$','$$'], ["\\[","\\]"] ] )