Module: sage.misc.latex
Latex printing support
In order to support latex formating, an object should define a special method _latex_(self) that returns a string.
Module-level Functions
c) |
) |
x, [mode=display]) |
Attempt to nicely render an arbitrary SAGE object wih jsmath typesetting. Tries to call ._latex_() on x. If that fails, it will render a string representation of x.
Input:
sage: f = maxima('1/(x^2+1)') sage: g = f.integrate() sage: jsmath(f) <html><div class="math">\frac{1}{x^2+1}</div></html> sage: jsmath(g, 'inline') <html><span class="math">\tan^{-1} x</span></html> sage: jsmath('\int' + latex(f) + '\ dx=' + latex(g)) <html><div class="math">\int\frac{1}{x^2+1}\ dx=\tan^{-1} x</div></html>
Author Log:
x) |
x) |
Return latex version of a variable name.
Here are some guiding principles for usage of this function: 1) If the variable is a single letter, that is the latex version. 2) If the variable name is suffixed by a number, we put the number in the subscript. 3) If the variable name contains an '_' we start the subscript at the underscore. Note that #3 trumps rule #2. 4) If a component of the variable is a greek letter, escape it properly. 5) Recurse nicely with subscripts.
Refer to the examples section for how these rules might play out in practice.
sage: import sage.misc.latex as latex_module sage: latex_variable_name = latex_module.latex_variable_name sage: latex_variable_name('a') 'a' sage: latex_variable_name('abc') '\\mbox{abc}' sage: latex_variable_name('sigma') '\\sigma' sage: latex_variable_name('sigma_k') '\\sigma_{k}' sage: latex_variable_name('sigma389') '\\sigma_{389}' sage: latex_variable_name('beta_00') '\\beta_{00}' sage: latex_variable_name('Omega84') '\\Omega_{84}' sage: latex_variable_name('sigma_alpha') '\\sigma_{\\alpha}' sage: latex_variable_name('nothing1') '\\mbox{nothing}_{1}' sage: latex_variable_name('nothing_abc') '\\mbox{nothing}_{\\mbox{abc}}' sage: latex_variable_name('alpha_beta_gamma12') '\\alpha_{\\beta_{\\gamma_{12}}}'
Author Log:
a) |
x, filename, [density=150], [debug=False], [brk=0], [do_in_background=True], [tiny=False]) |
Create a png image representation of x and save to the given filename.
object) |
Try to pretty print the object in an intelligent way. For many things, this will convert the object to latex inside of html and rely on a latex-aware front end (like jsMath) to render the text
[enable=True]) |
Enable or disable default pretty printing. Pretty printing means rendering things so that jsMath or some other latex-aware front end can render real math.
object) |
'view' or 'print' the object depending on the situation.
In particular, if in notebook mode with the typeset box checked, view the object. Otherwise, print the object.
Input: object: anything
sage: sage.misc.latex.print_or_typeset(3) 3 sage: sage.misc.latex.EMBEDDED_MODE=True sage: sage.misc.latex.print_or_typeset(3) 3 sage: sys.displayhook = sage.misc.latex.pretty_print sage: sage.misc.latex.print_or_typeset(3) <html><span class="math">3</span></html> sage: sage.misc.latex.EMBEDDED_MODE=False
symbols, coeffs) |
Compute a latex representation of a linear combination of some formal symbols.
Input:
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\text{a} + \left(t - 2\right)\text{s} + \left(t^{12} + 2\right)\text{}'
x) |
objects, [title=SAGE], [zoom=4], [expert=True], [debug=False], [sep=], [tiny=False]) |
Compute a latex representation of each object in objects, compile, and display typeset. If used from the command line, this requires that latex be installed.
Input:
This function behaves differently depending on whether in notebook mode or not.
If not in notebook mode, this opens up a window displaying a dvi (or pdf) file, displaying the following: the title string is printed, centered, at the top. Beneath that, each object in objects is typeset on its own line, with the string sep typeset between these lines.
If the program xdvi is used to display the dvi file, then the values of expert and zoom are passed on to it. On OS X displays a pdf.
If in notebook mode, this uses jmath to display the output in the notebook. Only the first argument, objects, is relevant; the others are ignored. If objects is a list, the result is typeset as a Python list, e.g. [12, -3.431] - each object in the list is not printed on its own line.
sage: sage.misc.latex.EMBEDDED_MODE=True sage: view(3) <html><span class="math">3</span></html> sage: sage.misc.latex.EMBEDDED_MODE=False
Class: JSMath
Functions: eval
Special Functions: __call__
Class: JSMathExpr
self, y) |
Special Functions: __add__,
__init__,
__radd__,
__repr__
Class: Latex
%latex The equation $y^2 = x^3 + x$ defines an elliptic curve. We have $2006 = \sage{factor(2006)}$.
%latex_debug
to get debugging output.
Use latex(...)
to typeset a SAGE object.
Use %slide
instead to typeset slides.
self, [debug=False], [slide=False], [density=150]) |
Functions: eval
self, x, [strip=False], [filename=None], [debug=None], [density=None], [locals=]) |
Input:
Special Functions: __call__,
__init__,
_latex_preparse
Class: LatexExpr
self, x) |
Special Functions: __init__,
__repr__,
_latex_
See About this document... for information on suggesting changes.