shd101wyy / vscode-markdown-preview-enhanced

One of the "BEST" markdown preview extensions for Visual Studio Code
https://shd101wyy.github.io/markdown-preview-enhanced
Other
1.44k stars 172 forks source link

[Feature Request] Greater Mathjax Customisability #1882

Open mayurankv opened 9 months ago

mayurankv commented 9 months ago

Is your feature request related to a problem? Please describe. It isn't possible to change MathJax config settings for things like the MathJax.Startup.Ready function since the config is read in as a json. I'm currently making changes to the code via a custom script injection but it would be great if the crossnotes config could also include javascript functions in the MathJax config.

Describe the solution you'd like Config allows changing of Startup.Ready, Startup.PageReady functions etc.

Describe alternatives you've considered I'm currently making changes to the code via a custom script injection

Additional context Alternatively, the ability to load a .sty file as a preamble would be amazing! All that needs to be done for MathJax is to run MathJax.tex2chtml(preamble) where preamble is a string containing all the definitions (this needs to be properly escaped etc.). This would solve my particular usecase for editing the MathJax config though the original solution would still be ideal!

Once again, thanks so much for this amazing extension!

yuriever commented 9 months ago

Do you mean the \newcommand macros? They can be added to Markdown Preview Enhanced: Open Config Script (Global) , e.g.

  mathjaxConfig: {
    loader: {
      load: ['[tex]/tagformat', '[tex]/configmacros', '[tex]/physics']
    },
    tex: {
      // packages included
      packages: { '[+]': ['tagformat', 'configmacros', 'physics'] },
      // inline math mode delimiters
      physics: {
        italicdiff: true,
        arrowdel: false
      },
      inlineMath: [['$', '$'], ['\\(', '\\)']],
      // display math mode delimiters
      displayMath: [['$$', '$$'], ['\\[', '\\]']],
      // use \$ to escape the dollar sign
      processEscapes: true,
      // process \begin{xxx}...\end{xxx} outside of math mode
      processEnvironments: true,
      // process \ref{...} outside of math mode
      processRefs: true,
      // pattern for recognizing numbers
      digits: /^(?:[0-9]+(?:\{,\}[0-9]{3})*(?:\.[0-9]*)?|\.[0-9]+)/,
      // macros
      macros: {
        "nn": "\\nonumber",
        "hat": [
          "\\widehat{#1}",
          "1"
        ]
      },
      environments: {
      },
    },
    options: {
      ignoreHtmlClass: '.'
    }
  },
})
mayurankv commented 9 months ago

I understand this and that works great for some things. However, for greater customisability, changing the Mathajax pageReady function would be great. For example something like

mathjaxConfig: {
   loader: {
     load: ['[tex]/color','[tex]/cancel']
   },
   tex: {
     packages: {'[+]': ['cancel', 'color']},
     inlineMath: [['$', '$'], ['\\(', '\\)']]
   },
   startup: {
     pageReady() {
       return MathJax.startup.defaultPageReady().then(function () {
          console.log("foo")
       });
     }
   }
 };

This can't currently be done as the config is stored as a JSON so the javascript can't be read and stored. If it could be that would be amazing!