# mathjax for tex support (General)

Hello

This was originally a follow up of this entry.

... MathJax ...

The administrator sets the url to the script files (like now to the google-service). The administrator can set a local url or an external CDN service.

MathJax works in another way than i.e. the Google-service, which is used in this instance. The forum script replaces the TeX-formulas inside its special BB-code to images and the selected service with the TeX-code as a URL-parameter as the source (src-attribute) of the image. With an external service, that works the same way than Google, one gets the image rendering for the formula.

$a_1 \dots a_n$ => $$$a_1 \dots a_n$$$

Not so with MathJax. MathJax needs the formula as source code in the page. There's no image replacement like (actually) in MLF. It might be also necessary not to add the BB-code () to get MathJax working (haven't tested it yet). So the BB-code-button would not appear to prevent the "misuse" of the TeX-BB-Code (no TeX-service-URL given to the settings) but a forum could have TeX-support with MathJax nevertheless. The forum operator has to tell the audience how it works.

$a_1 \dots a_n$

The pure notation, like shown above, should be rendered as formula if the forum operator does not set the URL in the settings but loads MathJax (from CDN or locally hosted). It should work IMHO that way (I for myself used MathJax only with MathML, not with TeX).

In generally, it should be doable. But that's another thread.

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

## mathjax for tex support

Hi,

MathJax needs the formula as source code in the page. There's no image replacement like (actually) in MLF. It might be also necessary not to add the BB-code () to get MathJax working (haven't tested it yet). So the BB-code-button would not appear to prevent the "misuse" of the TeX-BB-Code (no TeX-service-URL given to the settings) but a forum could have TeX-support with MathJax nevertheless. The forum operator has to tell the audience how it works.

We should keep the tex-button to avoid tex output in source codes.

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

## mathjax for tex support

Hi,

here an example of how it (could) work

<html>

<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<script type="text/x-mathjax-config">/*<![CDATA[*/MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ["$","$"], ["\$$","\$$"] ],
displayMath: [ ["$$","$$"], ["\$","\$"] ],
ignoreClass: "tex2jax_ignore",
processClass: "tex2jax_process",
processEscapes: true
},

TeX: {
equationNumbers: { autoNumber: "AMS" }

}

});

/*!]]>*/</script>

<body class="tex2jax_ignore">

<p>Some Text with TeX <span class="tex2jax_process">\sin{x} = y</span></p>
<p>Some Text with TeX <span class="tex2jax_process">$\sin{x} = y$</span></p>
<p>Some Text with TeX <span class="tex2jax_process">$$\sin{x} = y$$</span></p>

</body>

</html>

We need to define two classes e.g. tex2jax_ignore for ignoring TeX and tex2jax_process for parsing equations. Thus, the [tex]-Tag must replaced by (in my example) <span class="tex2jax_process">...</span> or, to be downwards compatible with the current solution, by <span class="tex2jax_process">$...$</span>.

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

## mathjax for tex support

Hello

here an example of how it (could) work

<html>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<script type="text/x-mathjax-config">/*<![CDATA[*/MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ["$","$"], ["\$$","\$$"] ],
displayMath: [ ["$$","$$"], ["\$","\$"] ],
ignoreClass: "tex2jax_ignore",
processClass: "tex2jax_process",
processEscapes: true
},
TeX: {
equationNumbers: { autoNumber: "AMS" }
}
});
/*!]]>*/</script>

<body class="tex2jax_ignore">

<p>Some Text with TeX <span class="tex2jax_process">\sin{x} = y</span></p>
<p>Some Text with TeX <span class="tex2jax_process">$\sin{x} = y$</span></p>
<p>Some Text with TeX <span class="tex2jax_process">$$\sin{x} = y$$</span></p>

</body>

</html>

Deactivating the parsing globally and activating it locally. Looks interesting.

We need to define two classes e.g. tex2jax_ignore for ignoring TeX and tex2jax_process for parsing equations. Thus, the [tex]-Tag must replaced by (in my example) <span class="tex2jax_process">...</span> or, to be downwards compatible with the current solution, by <span class="tex2jax_process">$...$</span>.

This would be a parallel way beside the old image-replacement-with-URL-to-a-external-service? If so, the setting bbcode_tex, currently storing the URL to the external service should be an on-off-switcher instead like the other bbcode_*-settings, and the URL should move to a different setting (IMHO).

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

## mathjax for tex support

Hi Auge,

Deactivating the parsing globally and activating it locally. Looks interesting.

Maybe, there is another (or better) solution but this one works (and, currently, I don't saw another way to avoid conflicts). Maybe, you have another solution?!

This would be a parallel way beside the old image-replacement-with-URL-to-a-external-service?

I prefer to remove the old implementation and switch to mathjax, because mathjax can be host by the forum administrator. The bbcode_tex can be an URI, e.g. the CDN service of the Javascript files. If we use the simple on-off-switcher, we need another - as you pointed out - option. But what will be done, if the user enable the option but does not provide the URI? Isn't it a redundantly option?

Alternatively, we pre-configure the mathjax. In this case, an on-off-switcher make sense. Was it your intention?

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

## mathjax for tex support

Hi Auge,

Deactivating the parsing globally and activating it locally. Looks interesting.

Maybe, there is another (or better) solution but this one works (and, currently, I don't saw another way to avoid conflicts). Maybe, you have another solution?!

No, I haven't.

I prefer to remove the old implementation and switch to mathjax, because mathjax can be host by the forum administrator.

That's generally a step forward (IMHO).

The bbcode_tex can be an URI, e.g. the CDN service of the Javascript files. If we use the simple on-off-switcher, we need another - as you pointed out - option. But what will be done, if the user enable the option but does not provide the URI? Isn't it a redundantly option?

Alternatively, we pre-configure the mathjax. In this case, an on-off-switcher make sense.

Correct, but I for myself do not want to insert new dependencies. More, I want to remove dependencies (in general and where possible). Thatswhy I mentioned highlight.js in another entry. Both cases, code highlightning and TeX-formula-rendering are not common but more exceptional usecases. Recommending libraries and showing the way to insert it in one or two steps is IMHO better than to run afterwards the updates of the external libs.

With a JS-library, included from a CDN, a forum operator is on the actual version of the lib at every moment but she/he has to inform the visitors about shared data (to come back to the GDPR). With a local copy of a JS-library on the other hand, a forum operator will not send data to a third party (except the lib does it on it's own) but she/he has to check for updates every when and then (I know, it won't happen in most cases).

My intention was to make the new way possible without removing the old way [1]. That said, my thought was ...

1. ... to switch TeX-support on and off and ...
2. ... to decide, if TeX-formulas get rendered the old way, if an URL is provided, or ...
3. ... the formulas get rendered by MathJax without the URL in the new setting but with an additional <script>-element in the header of the main template. Otherwise a visitor sees the plain TeX-formula surrounded by the BB-code. That would look ugly but is not dangerous.

Tschö, Auge

[1]: Nur, um es klarzustellen. Ich bevorzuge einen vollständigen Umstieg von externen TeX-zu-Bilderdiensten zu einer JS-Bibliothek, die lokal betreibbar ist. Es kann aber Installationen geben, in denen die alte Art, TeX-Formeln zu rendern, benutzt wird. Dort gibt es mindestens auch schon die Cache-Versionen der Postings, die nicht neu erstellt werden, bloß, weil wir eine Funktion umbauen. Die Postings sind dann einfach mal kaputt, wenn der Cache nicht explizit gelöscht wird. Deswegen überlegte ich, wie man den neuen Weg neben den alten Weg stellen könnte, ohne letzteren zu versperren.

--
Trenne niemals Müll, denn er hat nur eine Silbe!

## mathjax for tex support

Hi,

My intention was to make the new way possible without removing the old way [1]. That said, my thought was ...

1. ... to switch TeX-support on and off and ...
2. ... to decide, if TeX-formulas get rendered the old way, if an URL is provided, or ...
3. ... the formulas get rendered by MathJax without the URL in the new setting but with an additional <script>-element in the header of the main template. Otherwise a visitor sees the plain TeX-formula surrounded by the BB-code. That would look ugly but is not dangerous.

Thus, the admin can not configure the CDN in the setting area? One can enable the option "Yes I want TeX support" but nothing will happen, because the CDN must set manually in main template? What is the benefit of the enable/disable option?

Currently, the TEX-Code is transformed to an image. If MathJax is used, we need a tag like span or div (to restrict the scope of MathJax). How do we switch between both modes?

Dort gibt es mindestens auch schon die Cache-Versionen der Postings, die nicht neu erstellt werden, bloß, weil wir eine Funktion umbauen. Die Postings sind dann einfach mal kaputt, wenn der Cache nicht explizit gelöscht wird.

Dann wäre unsere Caching Funktion aber kaputt. Ich meine, die Cache-Version beinhaltet den vollständigen HTML-Code mit allen Tags ergo auch das generierte Bild (also die URL) von Goople-Chart für die Gleichungen. Wenn der Cache nicht gelöscht wird, werden bei diesen Postings einfach alle "Bilder" angezeigt wie bisher. Erst wenn er gelöscht wird, ist dies anders. Oder missinterpretiere ich unseren Cache?

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

## mathjax for tex support

Hello

1. ... to switch TeX-support on and off and ...
2. ... to decide, if TeX-formulas get rendered the old way, if an URL is provided, or ...
3. ... the formulas get rendered by MathJax without the URL in the new setting but with an additional <script>-element in the header of the main template. Otherwise a visitor sees the plain TeX-formula surrounded by the BB-code. That would look ugly but is not dangerous.

Thus, the admin can not configure the CDN in the setting area?

This was only a first thought.

One can enable the option "Yes I want TeX support" but nothing will happen, because the CDN must set manually in main template? What is the benefit of the enable/disable option?

As said, it was only a first thought and not a ready-to-use-solution. The benefit of the on-off-switch in itself would be a unification of the behaviour with all the other bbcode-settings, which are on-off-switches with only this one exception.

Currently, the TEX-Code is transformed to an image. If MathJax is used, we need a tag like span or div (to restrict the scope of MathJax). How do we switch between both modes?

That's the question. With only a URL we can't decide, to take the old or the new way. With an on-off-switch and a URL we have the same problem. Thatswhy my first thought was to distinguish between TeX-support off, TeX-support on with only the bbcode_tex (with external include of the JS-lib in the template) as the new way and TeX-support on with the bbcode_tex and an provided URL for the old way. I know, this is not very convinient for every one of the few affected operators but it prevents the introduction of (at least) a third setting.

Dort gibt es mindestens auch schon die Cache-Versionen der Postings, die nicht neu erstellt werden, bloß, weil wir eine Funktion umbauen. Die Postings sind dann einfach mal kaputt, wenn der Cache nicht explizit gelöscht wird.

Dann wäre unsere Caching Funktion aber kaputt. Ich meine, die Cache-Version beinhaltet den vollständigen HTML-Code mit allen Tags ergo auch das generierte Bild (also die URL) von Goople-Chart für die Gleichungen. Wenn der Cache nicht gelöscht wird, werden bei diesen Postings einfach alle "Bilder" angezeigt wie bisher. Erst wenn er gelöscht wird, ist dies anders. Oder missinterpretiere ich unseren Cache?

Nein, tust nicht du, sondern bis eben ich. Ich dachte, es ginge bei dieser Funktion in den Einstellungen um den Inhalt des Verzeichnisses templates_c, aber es geht, wie du richtig sagtest, um die Caching-Tabellen in der Datenbank, in denen die vorgerenderten HTML-Ausgaben der Postings gespeichert werden. Den Cache kann man selbstredend auch bei einem Update löschen, wenn es nötig werden sollte.

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

## mathjax for tex support

Hi,

That's the question. With only a URL we can't decide, to take the old or the new way.

Is it useful to support the old way (until the end[tm])? What will we do in the future, if we found another service/way to enable TeX-support? Isn't it a barrel without ground?

Currently, I prefer the following solution:
bbcode_tex can be enabled/disables (i.e. set to 1 or 0); per default, the option is disabled
bbcode_tex_uri is a new option to define the URI of mathjax (default value is the external service)

Depending on the tex option bbcode_tex, we add the script defined in bbcode_tex_uri (at runtime). If the option is disabled, we don't add any further script.

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

## mathjax for tex support

Hello

That's the question. With only a URL we can't decide, to take the old or the new way.

Is it useful to support the old way (until the end[tm])?

Don't know (and no!). If we change the method of the TeX-rendering, it seems to be fair to make an old behaviour deprecated in a first step and not removing it instantly. On the other hand I wouldn't expect many forums using the TeX-formula-feature at all so it would affect only a few installations. Assuming, we inform our audience early and open enough, every one of the few affected forum operators can prepare her/himself.

What will we do in the future, if we found another service/way to enable TeX-support? Isn't it a barrel without ground?

This is not impossible but I would assume that future libs behave similar (not equal) to MathJax (clientside rendering and thatswhy JavaScript).

Currently, I prefer the following solution:
bbcode_tex can be enabled/disables (i.e. set to 1 or 0); per default, the option is disabled

Yes.

bbcode_tex_uri is a new option to define the URI of mathjax (default value is the external service)

That would remove the old behaviour.

Depending on the tex option bbcode_tex, we add the script defined in bbcode_tex_uri (at runtime). If the option is disabled, we don't add any further script.

So the proposal is to remove the old way to render TeX-formulas?

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

## mathjax for tex support

Hi Auge,

That would remove the old behaviour.
So the proposal is to remove the old way to render TeX-formulas?

That is my opinion, but yes, I prefer this solution.

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

## mathjax for tex support

Hello

That would remove the old behaviour.
So the proposal is to remove the old way to render TeX-formulas?

That is my opinion, but yes, I prefer this solution.

Taking the following into account ...

... I wouldn't expect many forums using the TeX-formula-feature at all so it would affect only a few installations.

... let's kick it with version 2.5.

For this installation I would prefer a local copy of MathJax on the server of mylittleforum.net because of GDPR caused declaration. I don't want to add further complexity to the data privacy statement (we send to $there and to $there ... oh ... and not to forget to \$there).

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

## mathjax for tex support

Hello Auge,

Taking the following into account ...

... I wouldn't expect many forums using the TeX-formula-feature at all so it would affect only a few installations.

... let's kick it with version 2.5.

Okay, so, I should wait to implement it or should I use the master branch?

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

## mathjax for tex support

Hello

Taking the following into account ... let's kick it with version 2.5.

Okay, so, I should wait to implement it or should I use the master branch?

Build it in a feature branch and merge into the master, if ready.

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

## mathjax for tex support

Hi,

Build it in a feature branch and merge into the master, if ready.

done.

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

## mathjax for tex support

Hello

I found another JS-library for LaTeX-formula-rendering named KaTeX. A link in their readme led me to this speed comparision between KaTeX and Mathjax. I have no clue about objectivity of the test conditions but it looks really impressive.

The LaTeX-code in the example page gets rendered in a quarter second with KaTeX and within four seconds with Mathjax. Additionally the download of the package for selfhosting the lib has a size of only 2.8Mb compared to MathJax, that comes with 34.9Mb in its current version 2.7.4.

Nice.

Tschö, Auge

PS: I will cut the TeX-support-part off from the main thread.

--
Trenne niemals Müll, denn er hat nur eine Silbe!

## mathjax for tex support

Hi,

the lib has a size of only 2.8Mb compared to MathJax, that comes with 34.9Mb in its current version 2.7.4.

Objectively considered, the different in package size must result from differences in the number of features.

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences

## mathjax for tex support

Hello

the lib has a size of only 2.8Mb compared to MathJax, that comes with 34.9Mb in its current version 2.7.4.

Objectively considered, the different in package size must result from differences in the number of features.

That's correct. MathJax supports not only LaTeX formulas but also formulas in MathML and ASCIImath as source, it provides output in HTML, SVG and also in MathML and it contains more font formats to support older browsers (i.e. old Opera versions with only SVG-font support or ancient IEs (down to IE6), that supports only the eot-format and so on) where you'll need only woff or woff2 for more or less modern browsers. MathJax is far more than only a formula renderer for websites and it's grown over the years.

My posting was only a notice about an alternative to MathJax. Before I found the library KaTeX I wasn't aware of an alternative to MathJax. We do not need to support one of the libraries directly. So, if we provide the ability to include none or one of the libs, we are done. And – thanks to your work – we are (for version 2.5).

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

## mathjax for tex support

Hi,

My posting was only a notice about an alternative to MathJax.

Currently, it isn't an alternative to MathJax because it seems to be impossible to define a HTML tag (with a specific class) that is used for TeX.

/Micha

--
applied-geodesy.org - OpenSource Least-Squares Adjustment Software for Geodetic Sciences