代码之家  ›  专栏  ›  技术社区  ›  leonheess

Mathjax在电子应用中的应用

  •  0
  • leonheess  · 技术社区  · 6 年前

    Mathjax 一旦应用程序启动后,它应该像网站上的脚本标签一样,将任何MathML、TeX或ASCIImath“文本”翻译成人类可读的内容。

    我试过了 mathjax-electron mathjax-node 但我一点也没法让它工作。有人能举例说明如何实施吗?

    我使用了mathjax electron的readme.md示例:

    var mathjaxHelper = require('mathjax-electron')
    
    var container = document.createElement('div')
    container.innerHTML = '$$\\sum\\limits_{i=0}^{\\infty} \\frac{1}{n^2}$$'
    
    mathjaxHelper.loadAndTypeset(document, container)
    

    但结果是 undefined 正在抛出错误。我还尝试实现mathjax节点提供的示例,但我根本无法让它工作。

    1 回复  |  直到 6 年前
        1
  •  2
  •   James Hibbard    6 年前

    我尝试了mathjax-electron和mathjax-node,但根本无法让它工作。有人能举例说明如何实施吗?

    当然。使用mathjax electron:

    mkdir mathjax-test
    cd mathjax-test
    npm init -y
    npm i -s electron mathjax-electron
    

    然后创建两个文件: index.js index.html .

    (此处借用)- Electron hello world )

    const electron = require('electron')
    const app = electron.app
    const BrowserWindow = electron.BrowserWindow
    
    let mainWindow
    
    function createWindow () {
      mainWindow = new BrowserWindow({width: 800, height: 600})
      mainWindow.loadURL(`file://${__dirname}/index.html`)
      mainWindow.webContents.openDevTools()
    
      mainWindow.on('closed', function () {
        mainWindow = null
      })
    }
    
    app.on('ready', createWindow)
    
    app.on('window-all-closed', function () {
      if (process.platform !== 'darwin') {
        app.quit()
      }
    })
    
    app.on('activate', function () {
      if (mainWindow === null) {
        createWindow()
      }
    })
    

    索引.html the first example from their homepage )

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <title>Mathjax</title>
        <script src="./node_modules/mathjax-electron/resources/MathJax/MathJax.js?config=electron"></script>
      </head>
      <body>
        <h1>MathJax</h1>
    
        <script>
          var mathjaxHelper = require('mathjax-electron')
          var container = document.createElement('div')
          container.innerHTML = '$$\\sum\\limits_{i=0}^{\\infty} \\frac{1}{n^2}$$'
          mathjaxHelper.typesetMath(container)
          document.querySelector('body').append(container)
        </script>
      </body>
    </html>
    

    然后从项目的根开始:

    ./node_modules/electron/dist/electron .
    

    结果是:

    MathJax Electron showing an equation