goessner / markdown-it-texmath

Support TeX math equations with your Markdown documents.
MIT License
156 stars 28 forks source link

Support Doxygen formula delimiter syntax #31

Closed arwedus closed 2 years ago

arwedus commented 3 years ago

I assume #28 was closed by accident? Does the VS Code plug-in now support \f$ and \f[ \f] as delimiters?

goessner commented 3 years ago

Hi, please add ...

    doxygen: {
        inline: [ 
            {   name: 'math_inline', 
                rex: /\\f\$(.+?)\\f\$/gy,
                tmpl: '<eq>$1</eq>',
                tag: '\\f$'
            },
        block: [
            {   name: 'math_block_eqno',
                rex: /\\f\[([^$]+?)\\f\]\s*?\(([^)\s]+?)\)/gmy,
                tmpl: '<section class="eqno"><eqn>$1</eqn><span>($2)</span></section>',
                tag: 'f[f]'
            },
            {   name: 'math_block',
                rex: /\\f\[([^$]+?)\\f\]/gmy,
                tmpl: '<section><eqn>$1</eqn></section>',
                tag: ''f[f]'
            }
   }

to the texmath.rules dictionary (object) in your local texmath.js file and try out, if it works.

If it does, I can add it in a later version.

Do not forget to change ...

const md = require('markdown-it')({html:true})
                  .use(tm, { engine: require('katex'),
                             delimiters: 'doxygen',
                             katexOptions: { macros: {"\\RR": "\\mathbb{R}"} } });

or change the delimiter in mdmath preferences.

-- sg

goessner commented 2 years ago

closed due to missing interest ... might be reopened some time ...

arwedus commented 2 years ago

Hi @goessner, sorry I forgot about this issue. I found out where the texmath.js file is and added it to the dictionary (not a JS programmer but I think I did it correctly...), and reloaded VS code. Unfortunately, I get the following error:

\fParseError: KaTeX parse error: Undefined control sequence: \f at position 68: …ma_assoc_score)\̲f̲.

arwedus commented 2 years ago

Ah sorry, I still had the markdown-preview-enhanced extension enabled (which supports configuring arbitrary math delimiter pairs). I disabled all Markdown extensions now, except the built-in one.

The following code snippet in texmath.js, and configuring the mdmath.delimiters option to "doxygen", works for me:

texmath.rules = {
...
    doxygen: {
        inline: [ 
            {   name: 'math_inline', 
                rex: /\\f\$(.+?)\\f\$/gy,
                tmpl: '<eq>$1</eq>',
                tag: '\\f$'
            }
        ],
        block: [
            {   name: 'math_block_eqno',
                rex: /\\f\[(.+?)\\f\]\s*?\(([^)\s]+?)\)/gmy,
                tmpl: '<section class="eqno"><eqn>$1</eqn><span>($2)</span></section>',
                tag: '\\f['
            },
            {   name: 'math_block',
                rex: /\\f\[(.+?)\\f\]/gmy,
                tmpl: '<section><eqn>$1</eqn></section>',
                tag: '\\f['
            }
        ]
    }
};

Some flaw I noticed with this regexp is that it supports block math on a single line, but not on a separate line as example 2:

\f[  e = m * c^2 \f]

\f[
   e = m * c^2 
\f]
goessner commented 2 years ago

@arwedus ... thanks for testing 'doxygen' delimiters and positive feedback.

Changing your regexes to

    doxygen: {
        inline: [ 
            {   name: 'math_inline', 
                rex: /\\f\$(.+?)\\f\$/gy,
                tmpl: '<eq>$1</eq>',
                tag: '\\f$'
            }
        ],
        block: [
            {   name: 'math_block_eqno',
                rex: /\\f\[([^]+?)\\f\]\s*?\(([^)\s]+?)\)/gmy,
                tmpl: '<section class="eqno"><eqn>$1</eqn><span>($2)</span></section>',
                tag: '\\f['
            },
            {   name: 'math_block',
                rex: /\\f\[([^]+?)\\f\]/gmy,
                tmpl: '<section><eqn>$1</eqn></section>',
                tag: '\\f['
            }
        ]
    }

should make them work with multiple lines now.

I included them to version 0.9.4

thanks again ...