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

Fixing Latex documentation. #1290

Merged
merged 7 commits into from
Jan 15, 2025
Merged

Fixing Latex documentation. #1290

merged 7 commits into from
Jan 15, 2025

Conversation

mmatera
Copy link
Contributor

@mmatera mmatera commented Jan 14, 2025

Improving TeXForm to use name_character tables. Adjustments in docstrings.
DRY get_latex_operator. More adjustments

@mmatera mmatera marked this pull request as draft January 14, 2025 04:27
@@ -31,7 +31,7 @@ class DirectedEdge(InfixOperator):
>> DirectedEdge[x, y, z]
= x → y → z

>> a \\[DirectedEdge] b
>> a -> b
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test expressions must be plane ASCII to work with the LaTeX documentation.

<url>
:Divisor function: https://en.wikipedia.org/wiki/Divisor_function</url> (<url>
:SymPy: https://docs.sympy.org/latest/modules/functions/combinatorial.html#sympy.functions.combinatorial.numbers.divisor_sigma</url>, <url>
:WMA: https://reference.wolfram.com/language/ref/DivisorSigma.html</url>)
<dl>
<dt>'DivisorSigma[$k$, $n$]'
<dd>returns σ_$k$($n$)
<dd>returns $\sigma_k$($n$)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make that the underscore be interpreted as a subindex, all must be enclosed by $...$. Also it is better to use the LaTeX command for $\sigma$.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for LaTeX but breaks Django.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how Django docstring looks in master:
image

This is not perfect either. I think we should handle this in the Mathics-Django side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mathics-Django uses Mathjax to render equations, so it is just a matter to call the render when the documentation is loaded. I will look how to do this later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - good. In the end I guess there will be improvement there as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this.

According the MathML documentation, and what we do in
https://github.com/Mathics3/mathics-django/blob/143195d67d3afd2e4cde94f1dde4a641a5fbdd0c/mathics_django/web/media/js/mathics.js#L310

it should be enough to add just bellow here:
https://github.com/Mathics3/mathics-django/blob/143195d67d3afd2e4cde94f1dde4a641a5fbdd0c/mathics_django/web/media/js/doc.js#L6
the line

  MathJax.Hub.Queue(['Typeset', MathJax.Hub, doc]);

However, for some reason it does not do the trick. Any idea about why, or how to ask?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A guess is that this routine is hooked in from a path that processes evaluation output from Python which is distinct from the path that displays document output

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems something like that happens, but I still could not figure out what/how.

mathics/core/convert/op.py Outdated Show resolved Hide resolved
@@ -43,3 +96,34 @@ def ascii_op_to_unicode(ascii_op: str, encoding: str) -> str:
ascii_op, ascii_op
)
return ascii_op


def get_latex_operator(unicode_op: str) -> str:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used both in the documentation system and in the TeXForm formatter.

text += "\\test{%s}\n" % escape_latex_code(self.test)
test_str = self.test
# TODO: replace nonascii characters in test_str
text += "\\test{%s}\n" % escape_latex_code(test_str)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I copy the attribute into a variable, because eventually we would like to translate all the non-ascii characters into amslatex codes.

# character associated to the operator.
# At some point we would like to scan all the unicode characters
# and replace them according to the context.
if self.operator and not self.operator.isascii():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces all the ocurrences of the operator in its unicode form, by its LaTeX form. Eventually we would like to translate any unicode character appearing in the docstring. Notice also that at this point, the documentation contains both the test cases and their results.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, we'd like to ditch all of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, we'd like to ditch all of this.

Even better!

mathics/doc/latex_doc.py Outdated Show resolved Hide resolved
mathics/format/latex.py Outdated Show resolved Hide resolved
adjust sed-hack for missing CapitalDifferentialD translation. Disable the use of the local amstex_operators dicctionary in translation
@mmatera mmatera marked this pull request as ready for review January 14, 2025 23:53
@@ -565,6 +556,7 @@ def graphics3dbox(self, elements=None, **options) -> str:
\begin{{asy}}
import three;
import solids;
import tube;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be required for TubeBox in asy.

@@ -36,6 +36,7 @@ sed -i -e 's/⧦/\\\\Equiv/g' documentation.tex
sed -i -e 's/⊻/xor/g' documentation.tex
sed -i -e 's/∧/&&/g' documentation.tex
sed -i -e 's/‖/||/g' documentation.tex
sed -i -e 's/ⅅ/$\\mathbb{D}$/' documentation.tex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! Can the other sed's get removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to check which one of these can be removed.

@rocky
Copy link
Member

rocky commented Jan 15, 2025

If this can now build the documentation, then let's merge.

@rocky
Copy link
Member

rocky commented Jan 15, 2025

If this can now build the documentation, then let's merge.

I am not seeing that this fixes everything:

$ make clean && make mathics.pdf 
...
LaTeX Warning: Reference `reference-of-built-in-symbols/atomic-elements-of-expr
essions/representation-of-numbers/precision' on page 10 undefined on input line
 367.

[10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24]
[25] [26] [27] [28] [29] [30] [31] [32]
chapter 3.
[33] [34] [35] [36] [37]
chapter 4.
[38] [39] [40] [41] [42]
part II.
[43]
chapter 5.
! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.4900 \begin{testresult}\frac{ $\pi$ }{4}
                                          \end{testresult}\end{testcase}%
Output written on mathics.pdf (43 pages).
Transcript written on mathics.log.

@mmatera
Copy link
Contributor Author

mmatera commented Jan 15, 2025

If this can now build the documentation, then let's merge.

I am not seeing that this fixes everything:

$ make clean && make mathics.pdf 
...
LaTeX Warning: Reference `reference-of-built-in-symbols/atomic-elements-of-expr
essions/representation-of-numbers/precision' on page 10 undefined on input line
 367.

[10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24]
[25] [26] [27] [28] [29] [30] [31] [32]
chapter 3.
[33] [34] [35] [36] [37]
chapter 4.
[38] [39] [40] [41] [42]
part II.
[43]
chapter 5.
! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.4900 \begin{testresult}\frac{ $\pi$ }{4}
                                          \end{testresult}\end{testcase}%
Output written on mathics.pdf (43 pages).
Transcript written on mathics.log.

Please, check if the mathics-scanner databases are updated to the current master.

@rocky
Copy link
Member

rocky commented Jan 15, 2025

If this can now build the documentation, then let's merge.

I am not seeing that this fixes everything:

$ make clean && make mathics.pdf 
...
LaTeX Warning: Reference `reference-of-built-in-symbols/atomic-elements-of-expr
essions/representation-of-numbers/precision' on page 10 undefined on input line
 367.

[10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24]
[25] [26] [27] [28] [29] [30] [31] [32]
chapter 3.
[33] [34] [35] [36] [37]
chapter 4.
[38] [39] [40] [41] [42]
part II.
[43]
chapter 5.
! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.4900 \begin{testresult}\frac{ $\pi$ }{4}
                                          \end{testresult}\end{testcase}%
Output written on mathics.pdf (43 pages).
Transcript written on mathics.log.

Please, check if the mathics-scanner databases are updated to the current master.

I ran make-JSON-tables.sh, but I didn't pull latest master on mathics-scanner. Checking again now...

@rocky
Copy link
Member

rocky commented Jan 15, 2025

It works! Great work - thanks!

@mmatera mmatera changed the title Towards make the latex documentation works again. Fixing Latex documentation. Jan 15, 2025
@rocky
Copy link
Member

rocky commented Jan 15, 2025

LGTM - merge when you are satisfied.

@mmatera mmatera merged commit a2c14ad into master Jan 15, 2025
14 checks passed
@mmatera mmatera deleted the fix_documentation branch January 15, 2025 15:42
@rocky rocky mentioned this pull request Jan 18, 2025
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