ILIAS icon indicating copy to clipboard operation
ILIAS copied to clipboard

UI LatexContent

Open fneumann opened this issue 10 months ago • 7 comments

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.

fneumann avatar Feb 27 '25 11:02 fneumann

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?

fneumann avatar Feb 27 '25 12:02 fneumann

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

Amstutz avatar Mar 14 '25 14:03 Amstutz

Jour Fixe, 31 MAR 2025: We highly appreciate this PR and accept it for trunk.

matthiaskunkel avatar Mar 31 '25 13:03 matthiaskunkel

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 avatar Apr 10 '25 14:04 fneumann

@fneumann please reassign me once this is ready for another round.

thibsy avatar Apr 24 '25 11:04 thibsy

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.js I: 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 on R\LatexResources).

  • R\LatexResources: The node_modules/mathjax/es5 directory has over 106 files. We support only a standard configuration provided by tex-chtml-full.js which 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 in UI.php with an anonymous function. R\ResourceRegistry can't be used since it can't handle directories or the file types .json and .woff. The interface I\LatexResources and the class R\DefaultLatexResources were an attempt to provide the selection for the export of ILIAS learning modules. I deleted them. The learning module component will have to copy mathjax.js and everything under public/node_modules/mathjax/es5 to create a self-contained HTML export with MathJax support.

  • I\Legacy\LatexRenderer I: 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 the C\Legacy\LatexContent component, respectively pages from the ILIAS page editor or pages displaying test question. Since the registerResources function 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 for C\Legacy\LatexContent as long as we have to process Latex for the legacy content in in the page editor and test.

  • I\Legacy\LatexRenderer II: done.

  • mathjax.js II: This is not possible. The skipHtmlTags generally 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.js III: I now use c-layout__page--latex to ignore latex on page level and c-legacy__content--latex to 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

fneumann avatar May 07 '25 13:05 fneumann

Dear @Amstutz, @klees and @thibsy,

the PR is ready for a next round. Could one of you have alook?

Thanks in advance Fred

fneumann avatar May 26 '25 08:05 fneumann

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

fneumann avatar Jul 04 '25 12:07 fneumann

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.

fneumann avatar Jul 14 '25 07:07 fneumann