Ticket #14256: trac_14256-verb-text-nt.patch

File trac_14256-verb-text-nt.patch, 4.3 KB (added by nthiery, 9 years ago)
• sage/misc/latex.py

# HG changeset patch
# User Nicolas M. Thiery <nthiery@users.sf.net>
# Date 1363030396 14400
# Node ID 05e7b56e3f791f52f19f0dc8512464879cfcd77b
# Parent  af9947274520010a6f6993fc450e15852f4ec7a7
imported patch blah

diff --git a/sage/misc/latex.py b/sage/misc/latex.py
 a def str_function(x): '-34.5' sage: str_function('+34.5') '+34.5' sage: str_function('hello_world') '\\verb|hello_world|' sage: str_function('-1.00000?') # trac 12178 '-1.00000?' sage: print str_function('hello world!') \text{hello world!} sage: print str_function('hello_world') \verb|hello_world| sage: print str_function('hello{world') \verb|hello{world| sage: print str_function('1 0 0\n  1 0\n    1') \begin{array}{l} \verb|1|\phantom{\verb!x!}\verb|0|\phantom{\verb!x!}\verb|0|\\ \phantom{\verb!xx!}\verb|1|\phantom{\verb!x!}\verb|0|\\ \phantom{\verb!xxxx!}\verb|1| \end{array} sage: print str_function('-1.00000?') # trac 12178 -1.00000? """ # Check if x is just a number with a possible sign, and/or decimal # point, and/or ends with "?" if re.match(r'(\+|-)?[0-9]*\.?[0-9]*\??\$', x): return x # for strings without {}, newlines, or special caracters, just use # the standard \text function if not any(c in x for c in "\n{}_^"): return r"\text{%s}"%x # Try to pick a delimiter. for delimiter in """|"'#%&,.:;?!@_~^+-/\=<>()[]{}0123456789E""": if delimiter == "E": class Latex(LatexCall): sage: latex(FiniteField(25,'a')) \Bold{F}_{5^{2}} sage: latex("hello") \verb|hello| \text{hello} sage: LatexExpr(r"\frac{x^2 - 1}{x + 1} = x - 1") \frac{x^2 - 1}{x + 1} = x - 1 class MathJax: sage: MathJax().eval(3, mode='inline') sage: MathJax().eval(type(3), mode='inline') """ # Get a regular LaTeX representation of x x = latex(x, combine_all=combine_all) def repr_lincomb(symbols, coeffs): sage: t = PolynomialRing(QQ, 't').0 sage: from sage.misc.latex import repr_lincomb sage: repr_lincomb(['a', 's', ''], [-t, t - 2, t^12 + 2]) '-t\\verb|a| + \\left(t - 2\\right)\\verb|s| + \\left(t^{12} + 2\\right)' '-t\\text{a} + \\left(t - 2\\right)\\text{s} + \\left(t^{12} + 2\\right)' sage: repr_lincomb(['a', 'b'], [1,1]) '\\verb|a| + \\verb|b|' '\\text{a} + \\text{b}' Verify that a certain corner case works (see :trac:5707 and :trac:5766):: def pretty_print (*args): sage: pretty_print(ZZ)  # indirect doctest sage: pretty_print("Integers = ", ZZ) # trac 11775 To typeset LaTeX code as-is, use :class:LatexExpr`:: def pretty_print_default(enable=True): sage: pretty_print_default(True) sage: sys.displayhook sage: pretty_print_default(False) sage: sys.displayhook == sys.__displayhook__ True