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

Improve support for LaTeX via MathML in documentation #221

Merged
merged 4 commits into from
Jan 29, 2025

Conversation

mmatera
Copy link
Contributor

@mmatera mmatera commented Jan 26, 2025

This PR contains the minimal changes needed to support LaTeX expressions in the documentation.

@mmatera
Copy link
Contributor Author

mmatera commented Jan 26, 2025

imagen

@mmatera mmatera marked this pull request as ready for review January 26, 2025 15:28
@rocky rocky changed the title Support for LaTeX in documentation Improve support for LaTeX via MathML in documentation Jan 29, 2025
@rocky
Copy link
Member

rocky commented Jan 29, 2025

LGTM - thanks.

This starts us toward improving the online doc so it has can have an impact larger than what is visible right now. I suspect our homegrown parsing limits what we can offer MathML. For example, right now we have to tag $x$^2 rather than $x^2$.

Some things to note:

While this works in a "dd" tag, I don't think it works in "dt". I tried putting $\sigma_k$ in the <dt> portion of DivisorSigma , and that came out untranslated.

Also, when I look at Cuboid, is don't see p_min (in the dd portion since dt doesn't work) getting rendered with a subscript. Know why?

At any rate, these can be done in a future PR.

@rocky rocky merged commit 2ed4a3d into master Jan 29, 2025
9 checks passed
@rocky rocky deleted the support_for_LaTeX_in_documentation branch January 29, 2025 17:27
@mmatera
Copy link
Contributor Author

mmatera commented Jan 29, 2025

LGTM - thanks.

This starts us toward improving the online doc so it has can have an impact larger than what is visible right now. I suspect our homegrown parsing limits what we can offer MathML. For example, right now we have to tag $x$^2 rather than $x^2$.

I can check, but in principle now $x^2$ would work fine both in the PDF and the online documentation

Some things to note:

While this works in a "dd" tag, I don't think it works in "dt". I tried putting $\sigma_k$ in the <dt> portion of DivisorSigma , and that came out untranslated.

OK, but we use <dt> blocks for code, so we do not need LaTeX code there.

Also, when I look at Cuboid, is don't see p_min (in the dd portion since dt doesn't work) getting rendered with a subscript. Know why?

The reason seems that in these blocks, $...$ blocks are translated to <var>...</var>. I will check if we can get ride of this conversions.

At any rate, these can be done in a future PR.

@rocky
Copy link
Member

rocky commented Jan 29, 2025

OK, but we use <dt> blocks for code, so we do not need LaTeX code there.

That is not the way "dt" is supposed to work. A lot of our formatting and WMA's formatting use Mathematical notation in the definition term.

Also, when I look at Cuboid, is don't see p_min (in the dd portion since dt doesn't work) getting rendered with a subscript. Know why?

Maybe because p_min is not wrapped in $ ?

No. See https://github.com/Mathics3/mathics-core/blob/master/mathics/builtin/drawing/graphics3d.py#L257

@mmatera
Copy link
Contributor Author

mmatera commented Jan 29, 2025

Yep. The problem is a concatenation of several small issues:

  • This regular expression
    LATEX_RE = re.compile(r"(\s?)\$(\w+?)\$(\s?)") defined in mathics.doc.doc_entries is used in

    text = LATEX_RE.sub(repl_latex, text)
    to replace $var$ by <VAR>var</VAR> . This makes sense if var is a sequence of alphabetic characters and numbers, but not for a LaTeX expression. To avoid using it for more complicated expressions, we should change the regular expression to
    LATEX_RE = re.compile(r"(\s?)\$([A-Za-z]+?)\$(\s?)")

  • Due to the quotes, 'Cuboid[$p_min$]' is translated to HTML as <code>Cuboid[$p_min$]</code>, which makes the code to be handled as "code" i.e., verbatim. The way to allow MathML in the arguments would be to use the quotes around the HEAD of the expression, like this: 'Cuboid'[$p_{min}$]

  • LaTeX interpreter understand p_min as p_{m}in, i.e., just the first character is considered as the subindex. To have min as subindex, we need to wrap it in curly brackets.

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

Successfully merging this pull request may close these issues.

2 participants