Skip to content

Use LaTeX commands instead of Unicode characters #40589

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

user202729
Copy link
Contributor

Because PDF build does not handle Unicode characters correctly.

With this change, there should be less

Missing character: There is no τ (U+03C4) in font cmmi10!

in the documentation, but there are still some (that I cannot hunt down immediately).

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Copy link

github-actions bot commented Aug 15, 2025

Documentation preview for this PR (built with commit 389559a; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@vincentmacri
Copy link
Member

Some of this is definitely good, like the change from \^ to \wedge.

For things like \sigma and \tau, I think this makes the documentation slightly less readable when viewing it with a text interface like a Sage session in the terminal. Not a huge deal, but I think it should be possible to deal with this when the PDF is generated rather than in the docstrings. It looks like the mathletters option from the ucs LaTeX package can do this.

What commands exactly did you run to build the PDF doc? I've always had trouble with the Sage docbuild, especially with meson.

@user202729
Copy link
Contributor Author

What commands exactly did you run to build the PDF doc? I've always had trouble with the Sage docbuild, especially with meson.

I have troubles too. See #40290 . Would be nice if someone contribute to https://doc.sagemath.org/html/en/developer/sage_manuals.html to explain more clearly what needs to be done, I guess.

@user202729
Copy link
Contributor Author

it should be possible to deal with this when the PDF is generated rather than in the docstrings. It looks like the mathletters option from the ucs LaTeX package can do this.

The official LaTeX team doesn't want to support it, see https://tex.stackexchange.com/a/628285/250119 section 2.2.

We could just \usepackage{unicode-math} and change from Computer Modern font to Latin Modern font, but this would slow down the code also. In any case, LaTeX is the language defined by the LaTeX team, and they're mostly in favor of typing out the command, so it may be better to live with it after all.

How about fixing this on IPython?

@user202729
Copy link
Contributor Author

actually Sage already have logic to deal with this:

https://doc.sagemath.org/html/en/reference/misc/sage/misc/sagedoc.html

You may try it out like this:


sage: def f():
....:     r"""
....:     `1 \ge 0`
....:     """
sage: f?
Signature:      f()
Docstring:         1 >= 0
Init docstring: Initialize self.  See help(type(self)) for accurate signature.
File:           ...
Type:           function

So the problem is not modify that module to also substitute Unicode characters. Anyway, out of scope for this pull request.

@tobiasdiez
Copy link
Contributor

The pdf build uses lualatex. Hence, the package unicode-math should do the trick to allow unicode in docstrings.

@user202729
Copy link
Contributor Author

user202729 commented Aug 17, 2025

unicode-math has a few other quirks, for example, it uses Latin Modern Math font instead of Computer Modern Math. See https://tex.stackexchange.com/questions/125175/how-to-get-xelatex-unicode-math-output-as-close-as-possible-to-that-of-pdfla , for example \varnothing gives the same (more ugly in my opinion) symbol as \nothing in unicode-math.

Another issue is: MathJax does not support several Unicode characters e.g. $x²$ does not render as well as $x^2$, but unicode-math does. So using unicode-math might hide some issues in the rendered HTML.

In any case, everywhere else in the code base LaTeX commands are used. Discussion on whether to use unicode-math can be left for later.

@tobiasdiez
Copy link
Contributor

but I think it should be possible to deal with this when the PDF is generated rather than in the docstrings

I agree with this sentiment of @vincentmacri. So maybe just leave the tau's and sigma's untouched in this PR, and see in a follow-up PR if unicode-math (perhaps with a different other font) solves the pdf issues?

@user202729
Copy link
Contributor Author

There's another option: use unicode-math-input. As the maintainer of that package, I encourage people to use it... not really, since I'm the only maintainer and I don't look at it much, it may break at any time.

Also, there's the ². If you don't change it to ^2, it renders badly in the HTML also. At least everyone can agree to change that one right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants