Formula macro won't find my native latex installation

Hi there,

I’ve setup a fresh xwiki installation (version 17.6.0) on a ubuntu server. I have installed the packages texlive-latex-base texlive-latex-extra texlive-lang-german dvisvgm .. latex and dvisvgm are included in the PATH. it actually works on the commandline. This is, what I have configured in xwiki.properties:

macro.formula.renderer=native
macro.formula.defaultType=SVG
macro.formula.defaultFontSize=LARGE

So it should use the native latex installation. But I am constantly getting the message:

Das Makro [formula] konnte nicht ausgeführt werden. Grund: [The image type [image/svg+xml] is not supported by the SnuggleTeX formula renderer.]

Any ideas?

Thanks Holger

Note that the formula macro has been kind of deprecated. Hmm not sure that is official as I don’t see the info on https://extensions.xwiki.org/xwiki/bin/view/Extension/Formula%20Macro.

What’s sure is that it’s been made a contrib extensions and nobody is active on it.

The replacement is the mathjax extension → https://extensions.xwiki.org/xwiki/bin/view/Extension/MathJax/MathJaxMacro/

Could you use it?

Thx

Hi Vincent,

it does not seem to support inline math, does it?

Thanks Holger

Ah, I found out, that I have to surround my math with \( … \) for inline use. So I am going to write a wrapper macro named formula like so

{{velocity}}
#if ($wikimacro.context.isInline())
{{mathjax}}\($xcontext.macro.content\){{/mathjax}}
#else
{{mathjax}}
\begin{equation}
$xcontext.macro.content
\end{equation}
{{/mathjax}}
#end
{{/velocity}}

Indeed the Mathjax does says:

The default math delimiters are $...$ and \[...\] for displayed mathematics, and \(...\) for in-line mathematics.

At Writing Mathematics for MathJax — MathJax 4.0 documentation

I’ve updated the example at https://extensions.xwiki.org/xwiki/bin/view/Extension/MathJax/MathJaxMacro/#HUsage

You could do that, or not, depends what you’re looking for. There are lots of other possibilities with mathjax as shown in the example at https://extensions.xwiki.org/xwiki/bin/view/Extension/MathJax/MathJaxMacro/#HUsage(which is not complete).

I assume you’re happy to replace the formula macro with the mathjax one, right? (FTR, the reason we switched initially was because it provides a better rendering quality).

Thx

well,I think, I have to wrap it .. otherwise I’d have to edit 100s of pages with 1000s of formulas

indeed! rendering quality is much better and size adapts to the font size.

do you actually know katex .. it’s much faster than mathjax and has a comparabel rendering quality

No I wasn’t aware of it. Looks nice, thx for the info!

Maybe someone (you?) could implement a katex extension?

Or we/you could develop {{latex}} macro extension that is configurable and for which you could choose the rendering engine (mathjax or katex).

If you’re curious, the source code for the mathjax macro is at GitHub - xwiki-contrib/macro-mathjax: Enter content supported by the MathJax javascript engine :slight_smile:

Thx

Ah I see, you want the same behavior as the {{formula}} macro so that your wiki pages continue to work. Indeed…

You’ll need to decide if you want your user to choose using both formula and mathjax macros in your wiki. If you only want formula then you’ll need to hide the mathjax one.

See https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/WritingMacros/MacroDefaultCategories/ and https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Configuration/#HMacroscategoriesandvisibility

my approach would be to wrap katex with a webcomponent like this one:

GitHub - justinfagnani/katex-elements: Custom elements for easily using KaTeX

I’d create a fork with updated dependencies.

Webcomponents are HTML code. You want to write wiki pages in HTML? Doesn’t seem the best idea to me :slight_smile:

no .. like so ..

macro code:

{{html clean="false"}}
<script type="module">
import * as katexElements from 'https://esm.run/katex-elements';
</script>
{{/html}}

{{groovy}}
println("{{html clean=false}}<katex-inline>" + wikimacro.content + "</katex-inline>{{/html}}");
{{/groovy}}

this is, how it’s used in a wiki-page:

{{katex}}c = \pm\sqrt{a^2 + b^2}{{/katex}}

that’s just a proof of concept, but it actually works like this .. try it out!

of course, the block, that loads the web-component should appear only once on the page .. maybe, we could load it from a webjar?

Have you tried it? Is there anything wrong with doing it this way? It’s slim, fast and easy ..