Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Doxygen formula delimiter syntax #31

Closed
arwedus opened this issue Jul 29, 2021 · 5 comments
Closed

Support Doxygen formula delimiter syntax #31

arwedus opened this issue Jul 29, 2021 · 5 comments

Comments

@arwedus
Copy link

arwedus commented Jul 29, 2021

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

@goessner
Copy link
Owner

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
Copy link
Owner

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

@arwedus
Copy link
Author

arwedus commented Oct 29, 2021

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
Copy link
Author

arwedus commented Oct 29, 2021

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
Copy link
Owner

@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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants