Browse Source

Add missing tex/latext extensions for mathjax

simov 2 years ago
parent
commit
1cff8eb969
3 changed files with 23 additions and 0 deletions
  1. 9 0
      background/messages.js
  2. 4 0
      build/mathjax/build.sh
  3. 10 0
      content/mathjax.js

+ 9 - 0
background/messages.js

@@ -25,6 +25,15 @@ md.messages = ({storage: {defaults, state, set}, compilers, mathjax, xhr, webreq
         sendResponse({err, body})
         sendResponse({err, body})
       })
       })
     }
     }
+    else if (req.message === 'mathjax') {
+      chrome.scripting.executeScript({
+        target: {tabId: sender.tab.id},
+        files: [
+          `/vendor/mathjax/extensions/${req.extension}.js`,
+        ],
+        injectImmediately: true
+      }, sendResponse)
+    }
 
 
     // popup
     // popup
     else if (req.message === 'popup') {
     else if (req.message === 'popup') {

+ 4 - 0
build/mathjax/build.sh

@@ -8,7 +8,11 @@ git clone --depth 1 --branch 3.2.2 https://github.com/mathjax/MathJax.git tmp
 # https://github.com/mathjax/MathJax#reducing-the-size-of-the-components-directory
 # https://github.com/mathjax/MathJax#reducing-the-size-of-the-components-directory
 mkdir -p ../../vendor/mathjax
 mkdir -p ../../vendor/mathjax
 cp tmp/es5/tex-mml-chtml.js ../../vendor/mathjax
 cp tmp/es5/tex-mml-chtml.js ../../vendor/mathjax
+
 mkdir -p ../../vendor/mathjax/fonts
 mkdir -p ../../vendor/mathjax/fonts
 cp tmp/es5/output/chtml/fonts/woff-v2/*.woff ../../vendor/mathjax/fonts
 cp tmp/es5/output/chtml/fonts/woff-v2/*.woff ../../vendor/mathjax/fonts
 
 
+mkdir -p ../../vendor/mathjax/extensions
+cp tmp/es5/input/tex/extensions/*.js ../../vendor/mathjax/extensions/
+
 rm -rf tmp/
 rm -rf tmp/

+ 10 - 0
content/mathjax.js

@@ -1,5 +1,15 @@
 
 
 var MathJax = {
 var MathJax = {
+  loader: {
+    pathFilters: [
+      ({name}) => name.startsWith('[tex]') ? false : true // keep the name
+    ],
+    require: (path) => path.startsWith('[tex]') ?
+      chrome.runtime.sendMessage({
+        message: 'mathjax',
+        extension: path.replace('[tex]/', '')
+      }) : null
+  },
   tex: {
   tex: {
     inlineMath: [
     inlineMath: [
       ['$', '$'],
       ['$', '$'],