LaTeX macros

AUTHORS:

  • John H. Palmieri (2009-03)

The code here sets up LaTeX macro definitions for use in the documentation. To add a macro, modify the list macros, near the end of this file, and then run ‘sage -b’. The entries in this list are used to produce sage_latex_macros, a list of strings of the form ‘\newcommand...’, and sage_js_macros, a list of strings of the form ‘jsMath.Macro...’. The LaTeX macros are produced using the _latex_ method for each Sage object listed in macros, and the jsMath macros are produced from the LaTeX macros. The list of LaTeX macros is used in the file SAGE_ROOT/devel/sage/doc/common/conf.py to add to the preambles of both the LaTeX file used to build the PDF version of the documentation and the LaTeX file used to build the HTML version. The list of jsMath macros is used in the file sage/server/notebook/notebook.py to define jsMath macros for use in the live documentation (and also in the notebook).

Any macro defined here may be used in docstrings or in the tutorial (or other pieces of documentation). In a docstring, for example, “ZZ” in backquotes (demarking math mode) will appear as “ZZ” in interactive help, but will be typeset as “\Bold{Z}” in the reference manual.

More details on the list macros: the entries are lists or tuples of the form [name] or [name, arguments], where name is a string and arguments consists of valid arguments for the Sage object named name. For example, ["ZZ"] and ["GF", 2] produce the LaTeX macros ‘\newcommand{\ZZ}{\Bold{Z}}’ and ‘\newcommand{\GF}[1]{\Bold{F}_{#1}}’, respectively. (For the second of these, latex(GF(2)) is called and the string ‘2’ gets replaced by ‘#1’, so ["GF", 17] would have worked just as well. ["GF", p] would have raised an error, though, because p is not defined, and ["GF", 4] would have raised an error, because to define the field with four elements in Sage, you also need to specify the name of a generator.)

To see evidence of the results of the code here, run sage -docbuild tutorial latex (for example), and look at the resulting LaTeX file in SAGE_ROOT/sage/doc/output/latex/en/tutorial/. The preamble should contain ‘newcommand’ lines for each of the entries in macros.

sage.misc.latex_macros.convert_latex_macro_to_jsmath(macro)

This converts a LaTeX macro definition (newcommand...) to a jsMath macro definition (jsMath.Macro...).

INPUT:

  • macro - LaTeX macro definition

See the web page http://www.math.union.edu/~dpvc/jsMath/authors/macros.html for a description of the format for jsMath macros.

EXAMPLES:

sage: from sage.misc.latex_macros import convert_latex_macro_to_jsmath
sage: convert_latex_macro_to_jsmath('\\newcommand{\\ZZ}{\\Bold{Z}}')
"jsMath.Macro('ZZ','\\\\Bold{Z}');"
sage: convert_latex_macro_to_jsmath('\\newcommand{\\GF}[1]{\\Bold{F}_{#1}}')
"jsMath.Macro('GF','\\\\Bold{F}_{#1}',1);"
sage.misc.latex_macros.convert_latex_macro_to_jsmath_easy(macro)

This converts a LaTeX macro definition (newcommand...) to a definition for jsMath’s easy/load.js macro array.

INPUT:

  • macro - LaTeX macro definition

EXAMPLES:

sage: from sage.misc.latex_macros import convert_latex_macro_to_jsmath_easy
sage: convert_latex_macro_to_jsmath_easy('\\newcommand{\\ZZ}{\\Bold{Z}}')
"ZZ : '{\\\\Bold{Z}}'"
sage: convert_latex_macro_to_jsmath_easy('\\newcommand{\\GF}[1]{\\Bold{F}_{#1}}')
"GF : ['{\\\\Bold{F}_{#1}}', 1]"
sage.misc.latex_macros.produce_latex_macro(name, *sample_args)

Produce a string defining a LaTeX macro.

INPUT:

  • name - name of macro to be defined, also name of corresponding Sage object
  • sample_args - (optional) sample arguments for this Sage object

EXAMPLES:

sage: from sage.misc.latex_macros import produce_latex_macro
sage: produce_latex_macro('ZZ')
'\\newcommand{\\ZZ}{\\Bold{Z}}'

If the Sage object takes arguments, then the LaTeX macro will accept arguments as well. You must pass valid arguments, which will then be converted to #1, #2, etc. in the macro definition. The following allows the use of “GF{p^n}”, for example:

sage: produce_latex_macro('GF', 37)
'\\newcommand{\\GF}[1]{\\Bold{F}_{#1}}'

If the Sage object is not in the global name space, describe it like so:

sage: produce_latex_macro('sage.rings.finite_rings.constructor.FiniteField', 3)
'\\newcommand{\\FiniteField}[1]{\\Bold{F}_{#1}}'

Previous topic

LaTeX printing support

Next topic

Installing and using SageTeX

This Page