Ticket #7356: trac_7356_marik.patch

File trac_7356_marik.patch, 1.8 KB (added by robert.marik, 12 years ago)
  • sage/misc/latex.py

    # HG changeset patch
    # User Robert Marik <marik@mendelu.cz>
    # Date 1256899087 -3600
    # Node ID 41ef609f17d3fc134cac2a534124388746ee89d5
    # Parent  f872a92f5f9afff4b4971afc82bf9270faec269b
    trac 7356
    
    diff -r f872a92f5f9a -r 41ef609f17d3 sage/misc/latex.py
    a b  
    257257    """
    258258    return "\\left\\{" + ", ".join([latex(key) + ":\\: " + latex(value) for key,value in x.iteritems()]) + "\\right\\}"
    259259
     260def float_function(x):
     261    r"""
     262    Returns the LaTeX code for a float ``x``.
     263
     264    INPUT: ``x`` - float number
     265
     266    EXAMPLES::
     267
     268        sage: from sage.misc.latex import float_function
     269        sage: float_function(float(123.05))
     270        '123.05'
     271        sage: float_function(float(3e-15))
     272        '3 \\times 10^{-15}'
     273        sage: float_function(float(3.2e25))
     274        '3.2 \\times 10^{25}'
     275        sage: float_function(float(3.2e+15))
     276        '3.2 \\times 10^{15}'
     277
     278        The output is in some cases shorter than latex method for real numbers.
     279
     280        sage: float_function(float(1e+15))
     281        '1 \\times 10^{15}'
     282    """
     283    s = str(x)
     284    parts = s.split('e')
     285    if len(parts) > 1:
     286        # scientific notation
     287        if parts[1][0] == '+':
     288            parts[1] = parts[1][1:]
     289        s = "%s \\times 10^{%s}" % (parts[0], parts[1])
     290    return s
     291
    260292# One can add to the latex_table in order to install latexing
    261293# functionality for other types.  (Suggested by Robert Kerns of Enthought.)
    262294
    263295latex_table = {list: list_function, tuple:tuple_function, bool:bool_function,
    264                str: str_function, int:str, long:str, float:str, dict: dict_function}
     296               str: str_function, int:str, long:str, float:float_function, dict: dict_function}
    265297
    266298class LatexExpr(str):
    267299    """