-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Conversation
@@ -31,7 +31,7 @@ class DirectedEdge(InfixOperator): | |||
>> DirectedEdge[x, y, z] | |||
= x → y → z | |||
|
|||
>> a \\[DirectedEdge] b | |||
>> a -> b |
There was a problem hiding this comment.
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$) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@@ -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: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
adjust sed-hack for missing CapitalDifferentialD translation. Disable the use of the local amstex_operators dicctionary in translation
f7d1c15
to
26458ac
Compare
@@ -565,6 +556,7 @@ def graphics3dbox(self, elements=None, **options) -> str: | |||
\begin{{asy}} | |||
import three; | |||
import solids; | |||
import tube; |
There was a problem hiding this comment.
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.
mathics/doc/latex/sed-hack.sh
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
If this can now build the documentation, then let's merge. |
I am not seeing that this fixes everything:
|
Please, check if the mathics-scanner databases are updated to the current master. |
I ran |
It works! Great work - thanks! |
LGTM - merge when you are satisfied. |
Improving TeXForm to use name_character tables. Adjustments in docstrings.
DRY get_latex_operator. More adjustments