UI LatexContent
This PR proposes to add a new component Legacy\LatexContent to the UI framework. It is related to the corresponding feature request Streamline LaTeX usage . It relpaces the closed former PR.
Legacy\LatexContent is used as an intermediate solution for legacy content with mathematical formulas that are rendered by the JavaScript library MathJax. The LaTeX code of these formulas must be wrapped in the delimiters [tex] and [tex].
The modification of page content by MathJax is controlled by CSS classes. The class tex2jax_default_ignore is added to the body element of a page to prevent a modification outside Legacy\LatexContent. These contents are wrapped in elements with a class tex2jax_process to enable the modification inside.
Legacy\LatexContent registers a JavaScript file mathjax.js on the page. This file configures and loads MathJax asynchronously. MathJax scans the page for content to be processed and subsequently loads additional modules. All resources that are needed by MathJax are defined by the class DefaultLatexResources implementing the interface LatexResources. It is used by the UI framework to populate the public folder with these resources, and it is offered to other Components by a 'Define/Use' integration to support the export of the resources for offline content.
The Legacy\Factory is added to provide separate renderers for the legacy components Content and LatexContent. This way the resources for MathJax are only added to pages that use LatexContent. However, these are stilly many pages because the content of the ILIAS page editor needs to be wrapped in a LatexContent component.
Compared to the previous pull request, this new one does not inject a configuration to the UI framework by ILIAS. That means there is no setup switch to prevent the inclusion of the MathJax library on the page once a LatexContent is included, event if it does not have a LaTeX formula at all.
Dear UI Coordinators, please find here the new approach for moving MathJax to the UI framework. How should we proceed? Would you like to have a look at this PR before I put the feature Request Streamline LaTeX Usage on the JourFix Agenda?
Hi Fred,
We just discussed the among the UI Coordinators. The Public Interface is ready to be discussed in the upcoming JF. Thx a lot. The label is attached.
Please note, that we are also working on the review of the implementation, there are some observations and point to do.
Further note, that issues connected to this Latex Content component will need to be processed by you according to the Coordinator Model.
Thx for you work
@klees, @thibsy and @Amstutz
Jour Fixe, 31 MAR 2025: We highly appreciate this PR and accept it for trunk.
Dear UI coordinators, the JF acceptance is only related to the public interface of the new component. I'm still waiting for your review of the implementation and need the final acceptance to create separate PRs for the components that use MathJax. Especially a provision of interface LatexResources would be important to implement to use these resources in an HTML export of learning modules.
@fneumann please reassign me once this is ready for another round.
Dear @Amstutz, @klees and @thibsy,
thanks for your in-depth review. I was able to address most of your points, see my comments below. The code is revised and ready for a re-review.
-
mathjax.jsI: The combination of mathjax configuration and async loading in one script was recommended in the MathJax documentation because the main MathJax script (tex-chtml-full.js) has a minified size of 304 kB. It is now added separately with synchronous loading. Please note that MathJax loads additional assets (see note onR\LatexResources). -
R\LatexResources: Thenode_modules/mathjax/es5directory has over 106 files. We support only a standard configuration provided bytex-chtml-full.jswhich is registered as a resource. Other assets are loaded by MathJax on demand when Latex expressions are rendered. We don't know which of them will be needed, so we have to provide all sub directories of es5 as public assets. This is now done inUI.phpwith an anonymous function.R\ResourceRegistrycan't be used since it can't handle directories or the file types .json and .woff. The interfaceI\LatexResourcesand the classR\DefaultLatexResourceswere an attempt to provide the selection for the export of ILIAS learning modules. I deleted them. The learning module component will have to copymathjax.jsand everything underpublic/node_modules/mathjax/es5to create a self-contained HTML export with MathJax support. -
I\Legacy\LatexRendererI: in the JF on 31 March 2025 we decided not to optionally deactivate MathJax in the setup. This decision was drawn based on the assumption that MathJax will only be added to pages that use theC\Legacy\LatexContentcomponent, respectively pages from the ILIAS page editor or pages displaying test question. Since theregisterResourcesfunction does not get the rendered component as a parameter, we can only make that difference by a separate renderer. Currently there are four other UI components using an own renderer factory, so this is not an exotic pattern. Are there actual plans for ILIAS 11 to bundle all Javascript in one file? Otherwise I recommend to use a separate renderer forC\Legacy\LatexContentas long as we have to process Latex for the legacy content in in the page editor and test. -
I\Legacy\LatexRendererII: done. -
mathjax.jsII: This is not possible. TheskipHtmlTagsgenerally blocks rendering for certain tags. It cannot be changed with an enabling class for sub elements. So we have to provide a disabling class (see next point). -
mathjax.jsIII: I now usec-layout__page--latexto ignore latex on page level andc-legacy__content--latexto proces latex on component level. Both are fixed attributes in the template files. -
PHP code-style: applied the PHP CS Fixer to all modified PHP files.
Best regards Fred
Dear @Amstutz, @klees and @thibsy,
the PR is ready for a next round. Could one of you have alook?
Thanks in advance Fred
Dear @Amstutz, @klees and @thibsy,
I implemented your requested changes. Regarding the C\Legacy\LegacyRendererFactory I can't add something new to what I alredy explained. To not further block the creation of PRs for the consuming ILIAS components, I removed the separate renderer and the factory. Mathjax will now be added to every page having a legacy component. We well see if someone complains.
Please have a hopepully final review of the changes.
Best regards Fred
Thanks @thibsy for merging this PR. This brings us a big step forward. Now the way is open to use the UI element and to remove the old MathJax service from the system.