code
stringlengths
17
6.64M
class TestReduceNoGetinitargs(): '\n An old-style class with no :meth:`__getinitargs__` method. Used for testing\n :func:`explain_pickle`.\n ' def __init__(self): '\n Initialize a TestReduceNoGetinitargs object. Note that the\n constructor prints out a message.\n\n EXA...
class TestAppendList(list): '\n A subclass of :class:`list`, with deliberately-broken append and extend methods.\n Used for testing :func:`explain_pickle`.\n ' def append(self): '\n A deliberately broken append method.\n\n EXAMPLES::\n\n sage: from sage.misc.explain_...
class TestAppendNonlist(): '\n A list-like class, carefully designed to test exact unpickling\n behavior. Used for testing :func:`explain_pickle`.\n ' def __init__(self): '\n Construct a TestAppendNonlist.\n\n EXAMPLES::\n\n sage: from sage.misc.explain_pickle impor...
class TestBuild(): '\n A simple class with a :meth:`__getstate__` but no :meth:`__setstate__`. Used for testing\n :func:`explain_pickle`.\n ' def __getstate__(self): "\n A __getstate__ method for testing pickling.\n\n EXAMPLES::\n\n sage: from sage.misc.explain_pick...
class TestBuildSetstate(TestBuild): '\n A simple class with a :meth:`__getstate__` and a :meth:`__setstate__`. Used for testing\n :func:`explain_pickle`.\n ' def __setstate__(self, state): "\n Set the state of a TestBuildSetstate. Both prints a message, and\n swaps x and y, t...
class TestGlobalOldName(): '\n A featureless new-style class. When you try to unpickle an instance\n of this class, it is redirected to create a :class:`TestGlobalNewName` instead.\n Used for testing :func:`explain_pickle`.\n\n EXAMPLES::\n\n sage: from sage.misc.explain_pickle import *\n ...
class TestGlobalNewName(): '\n A featureless new-style class. When you try to unpickle an instance\n of :class:`TestGlobalOldName`, it is redirected to create an instance of this\n class instead. Used for testing :func:`explain_pickle`.\n\n EXAMPLES::\n\n sage: from sage.misc.explain_pickle i...
class TestGlobalFunnyName(): "\n A featureless new-style class which has a name that's not a legal\n Python identifier.\n\n EXAMPLES::\n\n sage: from sage.misc.explain_pickle import *\n sage: globals()['funny$name'] = TestGlobalFunnyName # see comment at end of file\n sage: TestGloba...
def flatten(in_list, ltypes=(list, tuple), max_level=sys.maxsize): "\n Flatten a nested list.\n\n INPUT:\n\n - ``in_list`` -- a list or tuple\n - ``ltypes`` -- optional list of particular types to flatten\n - ``max_level`` -- the maximum level to flatten\n\n OUTPUT:\n\n a flat list of the ent...
class func_persist(): '\n Put ``@func_persist`` right before your function\n definition to cache values it computes to disk.\n ' def __init__(self, f, dir='func_persist'): self.__func = f self.__dir = dir os.makedirs(dir, exist_ok=True) self.__doc__ = ('%s%s%s' % (f._...
def additive_order(x): '\n Return the additive order of ``x``.\n\n EXAMPLES::\n\n sage: additive_order(5)\n +Infinity\n sage: additive_order(Mod(5,11))\n 11\n sage: additive_order(Mod(4,12))\n 3\n ' return x.additive_order()
def base_ring(x): "\n Return the base ring over which ``x`` is defined.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(GF(7), 'x')\n sage: base_ring(R)\n Finite Field of size 7\n " return x.base_ring()
def base_field(x): "\n Return the base field over which ``x`` is defined.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(GF(7), 'x')\n sage: base_ring(R)\n Finite Field of size 7\n sage: base_field(R)\n Finite Field of size 7\n\n This catches base rings which are fields as...
def basis(x): '\n Return the fixed basis of ``x``.\n\n EXAMPLES::\n\n sage: V = VectorSpace(QQ, 3) # needs sage.modules\n sage: S = V.subspace([[1,2,0], [2,2,-1]]) # needs sage.modules\n sage: basis...
def category(x): '\n Return the category of ``x``.\n\n EXAMPLES::\n\n sage: V = VectorSpace(QQ, 3) # needs sage.modules\n sage: category(V) # needs sage.modules\n Category of...
def characteristic_polynomial(x, var='x'): "\n Return the characteristic polynomial of ``x`` in the given variable.\n\n EXAMPLES::\n\n sage: # needs sage.libs.pari sage.modules\n sage: M = MatrixSpace(QQ, 3, 3)\n sage: A = M([1,2,3,4,5,6,7,8,9])\n sage: charpoly(A)\n x^3 -...
def coerce(P, x): "\n Coerce ``x`` to type ``P`` if possible.\n\n EXAMPLES::\n\n sage: type(5)\n <class 'sage.rings.integer.Integer'>\n sage: type(coerce(QQ,5))\n <class 'sage.rings.rational.Rational'>\n " try: return P.coerce(x) except AttributeError: ...
def cyclotomic_polynomial(n, var='x'): '\n Return the `n^{th}` cyclotomic polynomial.\n\n EXAMPLES::\n\n sage: # needs sage.libs.pari\n sage: cyclotomic_polynomial(3)\n x^2 + x + 1\n sage: cyclotomic_polynomial(4)\n x^2 + 1\n sage: cyclotomic_polynomial(9)\n ...
def decomposition(x): '\n Return the decomposition of ``x``.\n\n EXAMPLES::\n\n sage: M = matrix([[2, 3], [3, 4]]) # needs sage.libs.pari sage.modules\n sage: M.decomposition() # needs sage.lib...
def denominator(x): '\n Return the denominator of ``x``.\n\n EXAMPLES::\n\n sage: denominator(17/11111)\n 11111\n sage: R.<x> = PolynomialRing(QQ)\n sage: F = FractionField(R)\n sage: r = (x+1)/(x-1)\n sage: denominator(r)\n x - 1\n ' if isinstance(x, ...
def det(x): '\n Return the determinant of ``x``.\n\n EXAMPLES::\n\n sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules\n sage: A = M([1,2,3, 4,5,6, 7,8,9]) # needs sage.modules\n sage: det(A) ...
def dimension(x): '\n Return the dimension of ``x``.\n\n EXAMPLES::\n\n sage: V = VectorSpace(QQ, 3) # needs sage.modules\n sage: S = V.subspace([[1,2,0], [2,2,-1]]) # needs sage.modules\n sage: dim...
def discriminant(x): "\n Return the discriminant of ``x``.\n\n EXAMPLES::\n\n sage: R.<x> = PolynomialRing(QQ)\n sage: S = R.quotient(x^29 - 17*x - 1, 'alpha') # needs sage.libs.pari\n sage: K = S.number_field() ...
def eta(x): '\n Return the value of the `\\eta` function at ``x``, which must be\n in the upper half plane.\n\n The `\\eta` function is\n\n .. MATH::\n\n \\eta(z) = e^{\\pi i z / 12} \\prod_{n=1}^{\\infty}(1-e^{2\\pi inz})\n\n EXAMPLES::\n\n sage: eta(1 + I) ...
def fcp(x, var='x'): "\n Return the factorization of the characteristic polynomial of ``x``.\n\n EXAMPLES::\n\n sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules\n sage: A = M([1,2,3, 4,5,6, 7,8,9]) ...
def gen(x): '\n Return the generator of ``x``.\n\n EXAMPLES::\n\n sage: R.<x> = QQ[]; R\n Univariate Polynomial Ring in x over Rational Field\n sage: gen(R)\n x\n sage: gen(GF(7))\n 1\n sage: A = AbelianGroup(1, [23]) ...
def gens(x): '\n Return the generators of ``x``.\n\n EXAMPLES::\n\n sage: R.<x,y> = SR[] # needs sage.symbolic\n sage: R # needs sage.symbolic\n Multivariat...
def hecke_operator(x, n): '\n Return the `n`-th Hecke operator `T_n` acting on ``x``.\n\n EXAMPLES::\n\n sage: M = ModularSymbols(1,12) # needs sage.modular\n sage: hecke_operator(M,5) # need...
def image(x): '\n Return the image of ``x``.\n\n EXAMPLES::\n\n sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules\n sage: A = M([1,2,3, 4,5,6, 7,8,9]) # needs sage.modules\n sage: image(A) ...
def symbolic_sum(expression, *args, **kwds): "\n Return the symbolic sum `\\sum_{v = a}^b expression` with respect\n to the variable `v` with endpoints `a` and `b`.\n\n INPUT:\n\n - ``expression`` - a symbolic expression\n\n - ``v`` - a variable or variable name\n\n - ``a`` - lower endpoint of t...
def symbolic_prod(expression, *args, **kwds): "\n Return the symbolic product `\\prod_{v = a}^b expression` with respect\n to the variable `v` with endpoints `a` and `b`.\n\n INPUT:\n\n - ``expression`` - a symbolic expression\n\n - ``v`` - a variable or variable name\n\n - ``a`` - lower endpoin...
def integral(x, *args, **kwds): "\n Return an indefinite or definite integral of an object ``x``.\n\n First call ``x.integral()`` and if that fails make an object and\n integrate it using Maxima, maple, etc, as specified by algorithm.\n\n For symbolic expression calls\n :func:`sage.calculus.calculu...
def integral_closure(x): '\n Return the integral closure of ``x``.\n\n EXAMPLES::\n\n sage: integral_closure(QQ)\n Rational Field\n sage: K.<a> = QuadraticField(5) # needs sage.rings.number_field\n sage: O2 = K.order(2 * a); O2 ...
def interval(a, b): '\n Integers between `a` and `b` *inclusive* (`a` and `b` integers).\n\n EXAMPLES::\n\n sage: I = interval(1,3)\n sage: 2 in I\n True\n sage: 1 in I\n True\n sage: 4 in I\n False\n ' return list(range(a, (b + 1)))
def xinterval(a, b): '\n Iterator over the integers between `a` and `b`, *inclusive*.\n\n EXAMPLES::\n\n sage: I = xinterval(2,5); I\n range(2, 6)\n sage: 5 in I\n True\n sage: 6 in I\n False\n ' return range(a, (b + 1))
def is_commutative(x): "\n Return whether or not ``x`` is commutative.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(QQ, 'x')\n sage: is_commutative(R)\n doctest:...DeprecationWarning: use X.is_commutative() or X in Rings().Commutative()\n See https://github.com/sagemath/sage/issue...
def is_even(x): '\n Return whether or not an integer ``x`` is even, e.g., divisible by 2.\n\n EXAMPLES::\n\n sage: is_even(-1)\n False\n sage: is_even(4)\n True\n sage: is_even(-2)\n True\n ' try: return x.is_even() except AttributeError: ...
def is_integrally_closed(x): "\n Return whether ``x`` is integrally closed.\n\n EXAMPLES::\n\n sage: is_integrally_closed(QQ)\n doctest:...DeprecationWarning: use X.is_integrally_closed()\n See https://github.com/sagemath/sage/issues/32347 for details.\n True\n sage: x = p...
def is_field(x, proof=True): "\n Return whether or not ``x`` is a field.\n\n Alternatively, one can use ``x in Fields()``.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(QQ, 'x')\n sage: F = FractionField(R)\n sage: is_field(F)\n doctest:...DeprecationWarning: use X.is_field() or...
def is_odd(x): '\n Return whether or not ``x`` is odd.\n\n This is by definition the complement of :func:`is_even`.\n\n EXAMPLES::\n\n sage: is_odd(-2)\n False\n sage: is_odd(-3)\n True\n sage: is_odd(0)\n False\n sage: is_odd(1)\n True\n ' r...
def kernel(x): '\n Return the left kernel of ``x``.\n\n EXAMPLES::\n\n sage: # needs sage.modules\n sage: M = MatrixSpace(QQ, 3, 2)\n sage: A = M([1,2, 3,4, 5,6])\n sage: kernel(A)\n Vector space of degree 3 and dimension 1 over Rational Field\n Basis matrix:\n ...
def krull_dimension(x): '\n Return the Krull dimension of ``x``.\n\n EXAMPLES::\n\n sage: krull_dimension(QQ)\n 0\n sage: krull_dimension(ZZ)\n 1\n sage: krull_dimension(ZZ[sqrt(5)]) # needs sage.rings.number_field sage.symbolic...
def lift(x): "\n Lift an object of a quotient ring `R/I` to `R`.\n\n EXAMPLES:\n\n We lift an integer modulo `3`::\n\n sage: Mod(2,3).lift()\n 2\n\n We lift an element of a quotient polynomial ring::\n\n sage: R.<x> = QQ['x']\n sage: S.<xmod> = R.quo(x^2 + 1) ...
def log(*args, **kwds): '\n Return the logarithm of the first argument to the base of\n the second argument which if missing defaults to ``e``.\n\n It calls the ``log`` method of the first argument when computing\n the logarithm, thus allowing the use of logarithm on any object\n containing a ``log...
def minimal_polynomial(x, var='x'): "\n Return the minimal polynomial of ``x``.\n\n EXAMPLES::\n\n sage: # needs sage.libs.pari sage.modules\n sage: a = matrix(ZZ, 2, [1..4])\n sage: minpoly(a)\n x^2 - 5*x - 2\n sage: minpoly(a, 't')\n t^2 - 5*t - 2\n sage: m...
def multiplicative_order(x): '\n Return the multiplicative order of ``x``, if ``x`` is a unit, or\n raise :class:`ArithmeticError` otherwise.\n\n EXAMPLES::\n\n sage: a = mod(5, 11)\n sage: multiplicative_order(a) # needs sage.libs.pari\n ...
def ngens(x): '\n Return the number of generators of ``x``.\n\n EXAMPLES::\n\n sage: R.<x,y> = SR[]; R # needs sage.symbolic\n Multivariate Polynomial Ring in x, y over Symbolic Ring\n sage: ngens(R) ...
def norm(x): '\n Return the norm of ``x``.\n\n For matrices and vectors, this returns the L2-norm. The L2-norm of a\n vector `\\textbf{v} = (v_1, v_2, \\dots, v_n)`, also called the Euclidean\n norm, is defined as\n\n .. MATH::\n\n |\\textbf{v}|\n =\n \\sqrt{\\sum_{i=1}^n |v_i|...
def numerator(x): '\n Return the numerator of ``x``.\n\n EXAMPLES::\n\n sage: R.<x> = PolynomialRing(QQ)\n sage: F = FractionField(R)\n sage: r = (x+1)/(x-1)\n sage: numerator(r)\n x + 1\n sage: numerator(17/11111)\n 17\n ' if isinstance(x, int): ...
def numerical_approx(x, prec=None, digits=None, algorithm=None): "\n Return a numerical approximation of ``self`` with ``prec`` bits\n (or decimal ``digits``) of precision.\n\n No guarantee is made about the accuracy of the result.\n\n .. NOTE::\n\n Lower case :func:`n` is an alias for :func:`n...
def objgens(x): "\n EXAMPLES::\n\n sage: R, x = objgens(PolynomialRing(QQ,3, 'x'))\n sage: R\n Multivariate Polynomial Ring in x0, x1, x2 over Rational Field\n sage: x\n (x0, x1, x2)\n " return x.objgens()
def objgen(x): "\n EXAMPLES::\n\n sage: R, x = objgen(FractionField(QQ['x']))\n sage: R\n Fraction Field of Univariate Polynomial Ring in x over Rational Field\n sage: x\n x\n " return x.objgen()
def order(x): '\n Return the order of ``x``.\n\n If ``x`` is a ring or module element, this is\n the additive order of ``x``.\n\n EXAMPLES::\n\n sage: C = CyclicPermutationGroup(10) # needs sage.groups\n sage: order(C) ...
def rank(x): '\n Return the rank of ``x``.\n\n EXAMPLES:\n\n We compute the rank of a matrix::\n\n sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules\n sage: A = M([1,2,3, 4,5,6, 7,8,9]) # needs s...
def regulator(x): "\n Return the regulator of ``x``.\n\n EXAMPLES::\n\n sage: x = polygen(ZZ, 'x')\n sage: regulator(NumberField(x^2 - 2, 'a')) # needs sage.rings.number_field\n 0.881373587019543\n sage: regulator(EllipticCurve('11a')) ...
def round(x, ndigits=0): "\n round(number[, ndigits]) - double-precision real number\n\n Round a number to a given precision in decimal digits (default 0\n digits). If no precision is specified this just calls the element's\n .round() method.\n\n EXAMPLES::\n\n sage: # needs sage.symbolic\n ...
def quotient(x, y, *args, **kwds): '\n Return the quotient object x/y, e.g., a quotient of numbers or of a\n polynomial ring x by the ideal generated by y, etc.\n\n EXAMPLES::\n\n sage: quotient(5,6)\n 5/6\n sage: quotient(5.,6.)\n 0.833333333333333\n sage: R.<x> = ZZ[]...
def isqrt(x): '\n Return an integer square root, i.e., the floor of a square root.\n\n EXAMPLES::\n\n sage: isqrt(10)\n 3\n sage: isqrt(10r)\n 3\n ' try: return x.isqrt() except AttributeError: from sage.functions.all import floor n = Integer(fl...
def squarefree_part(x): "\n Return the square free part of ``x``, i.e., a divisor\n `z` such that `x = z y^2`, for a perfect square\n `y^2`.\n\n EXAMPLES::\n\n sage: squarefree_part(100)\n 1\n sage: squarefree_part(12)\n 3\n sage: squarefree_part(10)\n 10\n ...
def _do_sqrt(x, prec=None, extend=True, all=False): '\n Used internally to compute the square root of ``x``.\n\n INPUT:\n\n - ``x`` -- a number\n\n - ``prec`` -- a positive integer (default: ``None``); when specified,\n compute the square root with ``prec`` bits of precision\n\n - ``extend...
def sqrt(x, *args, **kwds): "\n INPUT:\n\n - ``x`` -- a number\n\n - ``prec`` -- integer (default: ``None``): if ``None``, returns\n an exact square root; otherwise returns a numerical square root if\n necessary, to the given bits of precision.\n\n - ``extend`` -- bool (default: ``True`...
def transpose(x): '\n Return the transpose of ``x``.\n\n EXAMPLES::\n\n sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules\n sage: A = M([1,2,3, 4,5,6, 7,8,9]) # needs sage.modules\n sage: tra...
class Profiler(SageObject): def __init__(self, filename=None): '\n Interface to the gperftools profiler\n\n INPUT:\n\n - ``filename`` -- string or ``None`` (default). The file name\n to log to. By default, a new temporary file is created.\n\n EXAMPLES::\n\n ...
def crun(s, evaluator): "\n Profile single statement.\n\n - ``s`` -- string. Sage code to profile.\n\n - ``evaluator`` -- callable to evaluate.\n\n EXAMPLES::\n\n sage: import sage.misc.gperftools as gperf\n sage: ev = lambda ex:eval(ex, globals(), locals())\n sage: gperf.crun('gp...
def run_100ms(): '\n Used for doctesting.\n\n A function that performs some computation for more than (but not\n that much more than) 100ms.\n\n EXAMPLES::\n\n sage: from sage.misc.gperftools import run_100ms\n sage: run_100ms()\n ' t0 = time.time() t1 = (t0 + 0.1) from sa...
class HtmlFragment(str, SageObject): "\n A HTML fragment.\n\n This is a piece of HTML, usually not a complete document. For\n example, just a ``<div>...</div>`` piece and not the entire\n ``<html>...</html>``.\n\n EXAMPLES::\n\n sage: from sage.misc.html import HtmlFragment\n sage: H...
def math_parse(s): "\n Transform the string ``s`` with TeX maths to an HTML string renderable by\n MathJax.\n\n INPUT:\n\n - ``s`` -- a string\n\n OUTPUT:\n\n A :class:`HtmlFragment` instance.\n\n Specifically this method does the following:\n\n * Replace all ``\\$text\\$``\\'s by ``\\(tex...
class MathJaxExpr(): '\n An arbitrary MathJax expression that can be nicely concatenated.\n\n EXAMPLES::\n\n sage: from sage.misc.html import MathJaxExpr\n sage: MathJaxExpr("a^{2}") + MathJaxExpr("x^{-1}")\n a^{2}x^{-1}\n ' def __init__(self, y): '\n Initialize a...
class MathJax(): '\n Render LaTeX input using MathJax. This returns a :class:`MathJaxExpr`.\n\n EXAMPLES::\n\n sage: from sage.misc.html import MathJax\n sage: MathJax()(3)\n <html>\\[3\\]</html>\n sage: MathJax()(ZZ)\n <html>\\[\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\Bold...
class HTMLFragmentFactory(SageObject): def _repr_(self): '\n Return string representation\n\n OUTPUT:\n\n String.\n\n EXAMPLES::\n\n sage: html\n Create HTML output (see html? for details)\n ' return 'Create HTML output (see html? for detai...
def pretty_print_default(enable=True): "\n Enable or disable default pretty printing.\n\n Pretty printing means rendering things in HTML and by MathJax so that a\n browser-based frontend can render real math.\n\n This function is pretty useless without the notebook, it should not\n be in the global...
def _import_module_from_path(name, path=None): '\n Import the module named ``name`` by searching the given path entries (or\n `sys.path` by default).\n\n Returns a fully executed module object without inserting that module into\n `sys.modules`.\n\n EXAMPLES::\n\n sage: from sage.misc.inline_...
def _import_module_from_path_impl(name, path): 'Implement ``_import_module_from_path`` for Python 3.4+.' finder = importlib.machinery.PathFinder() spec = finder.find_spec(name, path=path) if (spec is None): raise ImportError('No module named {}'.format(name)) mod = importlib.util.module_fr...
class InlineFortran(): def __init__(self, globals=None): self.globs = globals self.library_paths = [] self.libraries = [] self.verbose = False def __repr__(self): return 'Interface to Fortran compiler' def __call__(self, *args, **kwds): return self.eval(*...
def list_function(x): "\n Returns the LaTeX code for a list ``x``.\n\n INPUT: ``x`` - a list\n\n EXAMPLES::\n\n sage: from sage.misc.latex import list_function\n sage: list_function([1,2,3])\n '\\\\left[1, 2, 3\\\\right]'\n sage: latex([1,2,3]) # indirect doctest\n \\l...
def tuple_function(x, combine_all=False): "\n Returns the LaTeX code for a tuple ``x``.\n\n INPUT:\n\n - ``x`` -- a tuple\n\n - ``combine_all`` -- boolean (default: ``False``) If ``combine_all`` is\n ``True``, then it does not return a tuple and instead returns a string\n with all the elemen...
def bool_function(x): '\n Returns the LaTeX code for a boolean ``x``.\n\n INPUT:\n\n - ``x`` -- boolean\n\n EXAMPLES::\n\n sage: from sage.misc.latex import bool_function\n sage: print(bool_function(2==3))\n \\mathrm{False}\n sage: print(bool_function(3==(2+1)))\n \\...
def builtin_constant_function(x): "\n Returns the LaTeX code for a builtin constant ``x``.\n\n INPUT:\n\n - ``x`` -- builtin constant\n\n .. SEEALSO:: Python built-in Constants http://docs.python.org/library/constants.html\n\n EXAMPLES::\n\n sage: from sage.misc.latex import builtin_constant...
def None_function(x): '\n Returns the LaTeX code for ``None``.\n\n INPUT:\n\n - ``x`` -- ``None``\n\n EXAMPLES::\n\n sage: from sage.misc.latex import None_function\n sage: print(None_function(None))\n \\mathrm{None}\n ' assert (x is None) return '\\mathrm{None}'
def str_function(x): '\n Return a LaTeX representation of the string ``x``.\n\n The main purpose of this function is to generate LaTeX representation for\n classes that do not provide a customized method.\n\n If ``x`` contains only digits with, possibly, a single decimal point and/or\n a sign in fr...
def dict_function(x): "\n Return the LaTeX code for a dictionary ``x``.\n\n INPUT:\n\n - ``x`` -- a dictionary\n\n EXAMPLES::\n\n sage: # needs sage.symbolic\n sage: from sage.misc.latex import dict_function\n sage: x,y,z = var('x,y,z')\n sage: print(dict_function({x/2: y^2...
def float_function(x): '\n Returns the LaTeX code for a python float ``x``.\n\n INPUT:\n\n - ``x`` -- a python float\n\n EXAMPLES::\n\n sage: from sage.misc.latex import float_function\n sage: float_function(float(3.14))\n 3.14\n sage: float_function(float(1e-10))\n ...
class LatexExpr(str): '\n A class for LaTeX expressions.\n\n Normally, objects of this class are created by a :func:`latex` call. It is\n also possible to generate :class:`LatexExpr` directly from a string, which\n must contain valid LaTeX code for typesetting in math mode (without dollar\n signs)....
def has_latex_attr(x) -> bool: '\n Return ``True`` if ``x`` has a ``_latex_`` attribute, except if ``x``\n is a ``type``, in which case return ``False``.\n\n EXAMPLES::\n\n sage: from sage.misc.latex import has_latex_attr\n sage: has_latex_attr(identity_matrix(3)) ...
@cached_function def default_engine(): "\n Return the default latex engine and the official name of the engine.\n\n This is determined by availability of the popular engines on the user's\n system. It is assumed that at least latex is available.\n\n EXAMPLES::\n\n sage: from sage.misc.latex imp...
class _Latex_prefs_object(SageObject): '\n An object that holds LaTeX global preferences.\n ' def __init__(self, bb=False, delimiters=['(', ')'], matrix_column_alignment='r'): '\n Define an object that holds LaTeX global preferences.\n\n EXAMPLES::\n\n sage: from sage.m...
def latex_extra_preamble(): '\n Return the string containing the user-configured preamble,\n ``sage_latex_macros``, and any user-configured macros. This is\n used in the :meth:`~Latex.eval` method for the :class:`Latex`\n class, and in :func:`_latex_file_`; it follows either\n ``LATEX_HEADER`` or ...
def _run_latex_(filename, debug=False, density=150, engine=None, png=False, do_in_background=False): '\n This runs LaTeX on the TeX file "filename.tex". It produces files\n ``filename.dvi`` (or ``filename.pdf``` if ``engine`` is either ``\'pdflatex\'``,\n ``\'xelatex\'``, or ``\'lualatex\'``) and if ``p...
class LatexCall(): "\n Typeset Sage objects via a ``__call__`` method to this class,\n typically by calling those objects' ``_latex_`` methods. The\n class :class:`Latex` inherits from this. This class is used in\n :mod:`~sage.misc.latex_macros`, while functions from\n :mod:`~sage.misc.latex_macro...
class Latex(LatexCall): 'nodetex\n Enter, e.g.,\n\n ::\n\n %latex\n The equation $y^2 = x^3 + x$ defines an elliptic curve.\n We have $2006 = \\sage{factor(2006)}$.\n\n in an input cell in the notebook to get a typeset version. Use\n ``%latex_debug`` to get debugging output.\n\n ...
def _latex_file_(objects, title='SAGE', debug=False, sep='', tiny=False, math_left='\\[', math_right='\\]', extra_preamble=''): 'nodetex\n Produce a string to be used as a LaTeX file, containing a\n representation of each object in objects.\n\n INPUT:\n\n - ``objects`` -- list (or object)\n\n - ``t...
def view(objects, title='Sage', debug=False, sep='', tiny=False, engine=None, viewer=None, tightpage=True, margin=None, mode='inline', combine_all=False, **kwds): 'nodetex\n Compute a latex representation of each object in objects, compile,\n and display typeset. If used from the command line, this requires...
def png(x, filename, density=150, debug=False, do_in_background=False, tiny=False, engine=None): '\n Create a png image representation of ``x`` and save to the given\n filename.\n\n INPUT:\n\n - ``x`` -- object to be displayed\n\n - ``filename`` -- file in which to save the image\n\n - ``density...
def coeff_repr(c): "\n LaTeX string representing coefficients in a linear combination.\n\n INPUT:\n\n - ``c`` -- a coefficient (i.e., an element of a ring)\n\n OUTPUT:\n\n A string\n\n EXAMPLES::\n\n sage: from sage.misc.latex import coeff_repr\n sage: coeff_repr(QQ(1/2))\n ...
def repr_lincomb(symbols, coeffs): "\n Compute a latex representation of a linear combination of some\n formal symbols.\n\n INPUT:\n\n - ``symbols`` -- list of symbols\n\n - ``coeffs`` -- list of coefficients of the symbols\n\n OUTPUT: A string\n\n EXAMPLES::\n\n sage: t = PolynomialRi...
def latex_varify(a, is_fname=False): '\n Convert a string ``a`` to a LaTeX string: if it\'s an element of\n ``common_varnames``, then prepend a backslash. If ``a`` consists\n of a single letter, then return it. Otherwise, return\n either "{\\\\rm a}" or "\\\\mbox{a}" if "is_fname" flag is ``True``\n...
def latex_variable_name(x, is_fname=False): "\n Return latex version of a variable name.\n\n Here are some guiding principles for usage of this function:\n\n 1. If the variable is a single letter, that is the latex version.\n\n 2. If the variable name is suffixed by a number, we put the number\n ...
class LatexExamples(): "\n A catalogue of Sage objects with complicated ``_latex_`` methods.\n Use these for testing :func:`latex`, :func:`view`, the Typeset\n button in the notebook, etc.\n\n The classes here only have ``__init__``, ``_repr_``, and ``_latex_``\n methods.\n\n EXAMPLES::\n\n ...
def produce_latex_macro(name, *sample_args): '\n Produce a string defining a LaTeX macro.\n\n INPUT:\n\n - ``name`` -- name of macro to be defined, also name of corresponding Sage object\n\n - ``sample_args`` -- (optional) sample arguments for this Sage object\n\n EXAMPLES::\n\n sage: from...
def convert_latex_macro_to_mathjax(macro): "\n This converts a LaTeX macro definition (\\newcommand...) to a\n MathJax macro definition (MathJax.Macro...).\n\n INPUT:\n\n - ``macro`` -- LaTeX macro definition\n\n See the web page\n https://docs.mathjax.org/en/latest/input/tex/macros.html for a\...