#28917 closed defect (fixed)

sagemath should not use math names with underscore when generating Latex

Reported by: gh-nasser1 Owned by:
Priority: minor Milestone: sage-9.1
Component: symbolics Keywords: latex
Cc: Merged in:
Authors: Dave Morris Reviewers: Markus Wageringel
Report Upstream: N/A Work issues:
Branch: 77bc7f4 (Commits, GitHub, GitLab) Commit: 77bc7f493fe82b0eefbcbd0a075040403427b51e
Dependencies: Stopgaps:

Status badges

Description (last modified by gh-DaveWitteMorris)

seen at https://ask.sagemath.org/question/49232/latex-problem-using-result-obtained-from-fricas-integrate/.

Using sagemath 8.9, when asking sagemath for latex of a math expression which contains something like log_integral, it generates in latex log_integral which does not typeset well due to underscore. Better translation would be \logintegral, this allows one to make a math operator using \DeclareMathOperator{\logintegral}{log\_integral}

But it is not possible to do this now as things stands. Here is an example

sage: var('t')
sage: result=integrate(1/log(t)^2,t, algorithm="fricas")
sage: result

(log(t)*log_integral(t) - t)/log(t)

sage: latex(result)

\frac{\log\left(t\right) log_integral\left(t\right) - t}{\log\left(t\right)}

The latex above would be better as

sage: latex(result)

\frac{\log\left(t\right) \logintegral\left(t\right) - t}{\log\left(t\right)}

even though \logintegral is not known to Latex, it can be made a known math name using \DeclareMathOperator as shown above.

EDIT: In order to avoid macros that are not known to Latex, we can define the Latex name to be \operatorname{log\_integral}.

Change History (9)

comment:1 Changed 21 months ago by embray

  • Milestone changed from sage-9.0 to sage-9.1

Ticket retargeted after milestone closed

comment:2 Changed 18 months ago by gh-DaveWitteMorris

  • Branch set to public/28917

comment:3 Changed 18 months ago by gh-DaveWitteMorris

  • Authors set to Dave Morris
  • Commit set to 6fda05daf36531b73ddd2df4ed7c9fdd6ca4c51d
  • Component changed from translations to symbolics
  • Description modified (diff)
  • Status changed from new to needs_review

I changed the Latex name of log_integral to \operatorname{log\_integral} so that the resulting Latex code can be pasted directly into a Latex file, without needing to add any macro definitions. (This is the same approach that was already used in the Latex name of exp_polar.) I made a similar fix to the Latex name of log_integral_offset, which was the only other place that I found this problem in the sage source.


New commits:

6fda05dunderscore in latex name

comment:4 Changed 18 months ago by gh-mwageringel

  • Reviewers set to Markus Wageringel
  • Status changed from needs_review to needs_work

Thank you for fixing this. There is just a small problem with the backslashes in the docstring. These need to be escaped, or (preferably) the docstring should be changed to a raw string:

     def __init__(self):
-        """
+        r"""
         See the docstring for ``Function_log_integral``.

Other than that, this looks good to me. I could not find other instances of this latex problem in Sage, either.

comment:5 Changed 18 months ago by git

  • Commit changed from 6fda05daf36531b73ddd2df4ed7c9fdd6ca4c51d to 77bc7f493fe82b0eefbcbd0a075040403427b51e

Branch pushed to git repo; I updated commit sha1. New commits:

77bc7f4need raw strings

comment:6 Changed 18 months ago by gh-DaveWitteMorris

Oops. Thanks for the correction. I also fixed a typo in a docstring (Function_log_integral-offset -> Function_log_integral_offset).

comment:7 Changed 18 months ago by gh-DaveWitteMorris

  • Status changed from needs_work to needs_review

comment:8 Changed 18 months ago by gh-mwageringel

  • Status changed from needs_review to positive_review

Thanks.

comment:9 Changed 18 months ago by vbraun

  • Branch changed from public/28917 to 77bc7f493fe82b0eefbcbd0a075040403427b51e
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.