Opened 13 years ago
Closed 13 years ago
#7356 closed enhancement (fixed)
fixed latex representation for floats
Reported by: | robert.marik | Owned by: | AlexGhitza |
---|---|---|---|
Priority: | minor | Milestone: | sage-4.3 |
Component: | basic arithmetic | Keywords: | |
Cc: | Merged in: | sage-4.3.alpha1 | |
Authors: | Robert Bradshaw | Reviewers: | Robert Marik |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
Floats have no LaTeX representation and are formated using str function. Thus output of latex(float(1e25)) is '1e+25' and not '1 \times 10{25}'.
The solution is to define function to handle this like the function below
def float_function(x): r""" Returns the LaTeX code for a float ``x``. INPUT: ``x`` - float number EXAMPLES:: sage: from sage.misc.latex import float_function sage: float_function(float(123.05)) '123.05' sage: float_function(float(3e-15)) '3 \\times 10^{-15}' sage: float_function(float(3.2e25)) '3.2 \\times 10^{25}' sage: float_function(float(3.2e+15)) '3.2 \\times 10^{15}' The output is in some cases shorter than latex method for real numbers. sage: float_function(float(1e+15)) '1 \\times 10^{15}' """ s = str(x) parts = s.split('e') if len(parts) > 1: # scientific notation if parts[1][0] == '+': parts[1] = parts[1][1:] s = "%s \\times 10^{%s}" % (parts[0], parts[1]) return s
Will post simple patch, provided it passes tests.
Attachments (3)
Change History (12)
Changed 13 years ago by
Attachment: | trac_7356_marik.patch added |
---|
comment:1 Changed 13 years ago by
Status: | new → needs_review |
---|
comment:2 Changed 13 years ago by
sage -t "devel/sage/sage/interfaces/maxima.py"
This test passed as well. (Error has been introduced by my custom settings in maxima-init.lisp file)
comment:3 Changed 13 years ago by
comment:4 follow-up: 5 Changed 13 years ago by
Status: | needs_review → needs_info |
---|
Should this be closed as a duplicate since #7328 has been closed with a positive review?
comment:5 Changed 13 years ago by
Replying to jhpalmieri:
Should this be closed as a duplicate since #7328 has been closed with a positive review?
Perhaps yes, but the patch in this trac produces shorter output, so I think that this is better. The patch #7328 produces sometimes zeros which are not necessary at the end of decimal number.
comment:6 Changed 13 years ago by
Status: | needs_info → needs_review |
---|
Changed 13 years ago by
Attachment: | latex-float-4.2.1.patch added |
---|
Use instead of other, applies on top of #7328
comment:7 Changed 13 years ago by
I agree, less digits should be printed. Floats are more like RDF than RR, so I've posted a patch that applies on top of #7328. The attached patch works fine to (though will conflict with 4.2.1).
Changed 13 years ago by
Attachment: | latex-float-4.2.1-reviewer.patch added |
---|
apply on top of latex-float-4.2.1.patch
comment:8 Changed 13 years ago by
Status: | needs_review → positive_review |
---|
Seems good, thanks for fixing. Since one test failed, I fixed it in reviewers patch which should be installed on the top of latex-float-4.2.1.patch
Tests are O.K. now. Positive review.
comment:9 Changed 13 years ago by
Authors: | → Robert Bradshaw |
---|---|
Merged in: | → sage-4.3.alpha1 |
Resolution: | → fixed |
Reviewers: | → Robert Marik |
Status: | positive_review → closed |
The patch for 4.2 is attached. When running tests I got two errors not related to the change in this trac. The first one is solved in #6479.