LaTeX Commands
Mathfields support over 800 LaTeX commands.
To enter a LaTeX command in mathfield press the ESC key or \
to enter LaTeX editing mode. Press ESC to exit LaTeX editing mode.
To examine the LaTeX code for an expression, select it, then press ESC.
Text Zone, Math Zone and Math Style
Math Zone
When in a Math Zone, the content is laid out using typesetting rules specific to math.
For example, variables such as x
are displayed in italics, an appropriate amount
of space is inserted around some letters such as f
to improve their legibility,
and white spaces are ignored.
In a Math Zone, the layout and size of some math elements is adjusted based on the
context in which they are used. For example, superscripts and subscripts are
displayed using a smaller font size: 2^2
.
Inside a Math Zone, the Math Style indicate the size of the font used to display the content, and some layout options, such as placement of the limits of a sum or integral.
To override the default Math Style, use the following commands:
Math Style | |||
---|---|---|---|
\displaystyle For equations in their own paragraph/block | \displaystyle \sum_{i=0}^n \frac{a_i}{1+x} | \displaystyle \sum_{i=0}^n \frac{a_i}{1+x} | |
\textstyle Confusingly, for inline math, not for text content | \textstyle \sum_{i=0}^n \frac{a_i}{1+x} | \textstyle \sum_{i=0}^n \frac{a_i}{1+x} | |
\scriptstyle For subscripts and superscripts | \scriptstyle \sum_{i=0}^n \frac{a_i}{1+x} | \scriptstyle \sum_{i=0}^n \frac{a_i}{1+x} | |
\scriptscriptstyle For subscripts and superscripts of subscripts and superscripts | \scriptscriptstyle \sum_{i=0}^n \frac{a_i}{1+x} | \scriptscriptstyle \sum_{i=0}^n \frac{a_i}{1+x} |
Text Zone
To include some textual content, use the \text{}
or \textrm{}
commands to switch
to a Text Zone. Inside a Text Zone, white spaces are preserved and the spacing of characters is not adjusted.
The \text{}
command will use the font defined by the CSS font-family
property
of the enclosing mathfield. The size of the text will adjust depending on
the current math style (smaller in superscript/subscript).
The \textrm{}
command works like \text{}
but will use a serif (roman) font.
The \mbox{}
command uses the same font as \text
but its size does not
account for the current math style.
The \textnormal{}
command works like \text{}
. But it's longer to type.
When in a Text Zone, use $...$
to switch back to an Inline Math Zone or \\[...\\]
to switch
to a Display (block) Math Zone.
Fractions and Binomials
The \frac
command is used to represent a fraction. The first argument is the numerator,
the second argument is the denominator. It will size itself according to the
current math style (display, text (inline), script, scriptscript). The \dfrac
and
\tfrac
commands force the math style to be display or text (inline) style respectively.
The \cfrac
(continuous fraction) command has an optional argument, [l]
or
[r]
, that controls if the numerator is left-aligned or right-aligned.
The \pdiff
command is a convenient shortcut for partial differentials.
The \binom
command is used to represent a binomial coefficient. The \dbinom
and
\tbinom
commands force the math style to be display or text (inline) style respectively.
The following commands are supported but their usage is generally discouraged when creating modern LaTeX content.
Binary Operators
Some binary operators can also be used as a unary operator: +
, -
, etc...
Their spacing is adjusted accordingly. For example in \( -1-2 \)
there is less space between -
and 1
than there is between -
and 2
.
Functions
Trigonometry
Non-Standard Trig Functions
The commands in this section are not part of the standard LaTeX distribution
but are available in some packages. Use them with caution as they may not
be supported by all LaTeX engines. Consider using \operatorname{}
instead.
Bounds
Projections
Modulo
Custom Functions
To define a custom function use the \operatorname{}
command: the name of the function will be displayed in upright
font and with the appropriate spacing.
Unicode
If a symbol is not available as a LaTeX command, you can use the Unicode codepoint of the character. The commands below can be used to insert a Unicode character in a mathfield.
Command | |
---|---|
\unicode{} | The argument is a Unicode codepoint expressed as a number. To use a hexadecimal number, start the argument with x or " and use uppercase A -F for hexadecimal digits.
|
\char | The argument is also a Unicode codepoint, but the { ...} delimiters are optional when using " .
|
^^ ^^^^ | Followed by 2 or 4 hexadecimal digits with lowercase a -f to specify a Unicode codepoint.
|
The codepoint of the Unicode character ⨗ U+2A17 INTEGRAL WITH LEFTWARDS ARROW WITH HOOK is 10775 in decimal, 2A1716 in hexadecimal. The codepoint of the letter J
is 004A16 in hexadecimal. Learn more about Mathematical Operators and Symbols in Unicode on Wikipedia.
Large Operators
Large operators display their limits above and below or adjacent to the operator, depending on the math style (Display Style or Text Style) and on the operator.
The position of the limits can be controlled with \limits
, \nolimits
or
\displaylimits
after the operator. The \limits
command forces the display
of the limits above and below the operator, \nolimits
forces the display
of the limits adjacent to the operator, and \displaylimits
uses an
automatic position, based on the operator and current math style.
\limits | \nolimits | \displaylimits |
---|---|---|
\sum_{i=0}^n\limits | \sum_{i=0}^n\nolimits | \sum_{i=0}^n\displaylimits |
\sum_{i=0}^n\limits | \sum_{i=0}^n\nolimits | \sum_{i=0}^n\displaylimits |
\int_0^\infty\limits | \int_0^\infty\nolimits | \int_0^\infty\displaylimits |
\int_0^\infty\limits | \int_0^\infty\nolimits | \int_0^\infty\displaylimits |
In Display Style, the \intop
and \ointop
commands display their limits
above and below by default, while the \int
command display its limit adjacent.
Logic
Quantifiers
Unary/Binary Operators
Relational Operators
Arrows
Negated Arrows
Extensible Arrows
The length of the arrow commands above is fixed. The length of the commands in this section is determined by the length of the content above and below the arrows, which is specified as an argument (and optional argument):
Accents
Deprecated Accents
The following commands are supported for compatibility with existing content, but their use is generally discouraged when creating new LaTeX content when an equivalent Unicode character is available.
For example use é
rather than \'{e}
.
Extensible Accents
Regular accents have a fixed width and do not stretch. For example, compare:
Relational Operators
To display a vertical "stack" of two symbols as a relational operator, use the
\stackrel
command: a\stackrel{?}{=}b
a\stackrel{?}{=}b
.
Negated Relational Operators
To negate other relational operators, use the \not
command, e.g.
\( \not\equiv \) \not\equiv
.
Sets
To represent sets such as the natural numbers, integers, real numbers, etc., use the \mathbb
command for best compatibility, e.g.
\mathbb{N}
\mathbb{N}
or \mathbb{C}
\mathbb{C}
, etc...
Non standard commands, may not be supported by all LaTeX engines:
Set Operators
Relational Set Operators
Greek
Hebrew
Letterlike Symbols
Delimiters
A delimiter, also called a fence, is a symbol used to group some symbols, for example parentheses, brackets, braces, etc...
To grow delimiters based on their content, use \left...\right
.
Regular delimiters | \left...\right |
---|---|
\lbrace x \| \frac{x}{2} > 0\rbrace | \left\lbrace x \middle\| \frac{x}{2} > 0\right\rbrace |
\lbrace x | \frac{x}{2} > 0\rbrace | \left\lbrace x \middle| \frac{x}{2} > 0\right\rbrace |
The left and right delimiters do not have to match:
- \(\displaystyle \left\lparen \frac1x \right\rbrack\)
\left\lparen \frac1x \right\rbrack
To omit a delimiter, use .
:
- \(\displaystyle \left\lparen \frac1x \right.\)
\left\lparen \frac1x \right.
The argument to \left
, \right
and \middle
can be one of the
following commands.
Punctuation
Dots
Shapes
St Mary's Road Symbols for Theoretical Computer Science
Layout
These commands change the amount of space around a symbol: \mathop{}
treats its argument as if it was a large operator, \mathrel{}
a
relational operator, \mathbin{}
a binary operator, \mathopen{}
and \mathclose{}
an opening and closing delimiter, respectively, \mathpunct{}
a punctuation, \mathinner{}
a fraction, and \mathord{}
an ordinary symbol
Spacing
Decorations
Notations
\enclose
The \enclose
command is very flexible. It accepts three arguments, two of
which are required:
\enclose{<notation>}[<style>]{<body>}
<notation>
a list of whitespace-delimited values:
They can be combined:
<style>
an optional list of comma separated key-value pairs including:mathbackground="<color>"
background color of the expressionmathcolor="<color>"
color of the notation, for examplered
or#cd0030
orrgba(205, 0, 11, .4)
.padding="<dimension>"
"auto"
or an amount of padding around the contentshadow="<shadow>"
:"auto"
or"none"
or a CSSbox-shadow
expression for example,"0 0 2px rgba(0, 0, 0, 0.5)"
.- in addition the style property can include a stroke style expression that
follows the shorthand syntax of the CSS
border
property, for example"2px solid red"
.
<body>
a math expression that is "enclosed" by the specified notations
\enclose
is a LaTeX extension introduced by MathJax that follows the <menclose>
definition of MathML.
\cancel
, \bcancel
and \xcancel
Command... | is a shorthand for... |
---|---|
\cancel{body} $$\cancel{\unicode{"2B1A}}$$ | \enclose{updiagonalstrike}{body} |
\bcancel{body} $$\bcancel{\unicode{"2B1A}}$$ | \enclose{downdiagonalstrike}{body} |
\xcancel{body} $$\xcancel{\unicode{"2B1A}}$$ | \enclose{updiagonalstrike downdiagonalstrike}{body} |
The \cancel
, \bcancel
and \xcancel
commands are part of the
"cancel" LaTeX package.
Shortcuts
Some commands are shortcuts for common notations:
Command... | is a shorthand for... |
---|---|
\angl{body} \angl{body} | \enclose{actuarial}{body} |
\angln \angln | \enclose{actuarial}{n} |
\anglr \anglr | \enclose{actuarial}{r} |
\anglk \anglk | \enclose{actuarial}{k} |
Colors
To change the foreground color, use the \textcolor{}{}
command.
To change the background, use the \colorbox{}{}
command.
The first argument of these commands is a color specified as:
- one of
red
,orange
,yellow
,lime
,green
,teal
,blue
,indigo
,
purple
,magenta
,black
,dark-grey
,grey
,light-grey
, `white.
- a RGB color using the standard CSS format (
#d7170b
orrgb(240, 20, 10)
) - one of the 68 colors from dvips color name
(
CadetBlue
). Note that these names are case-sensitive. - one of the 10 Mathematica color from
ColorData[97, "ColorList"]
(M0
toM9
) - a color defined using the syntax from the
xcolor
package, for example:Blue!20!Black!30!Green
- if the color is prefixed with a
-
, the complementary color is used
The following color names are recommended:
These colors have been carefully selected for a balanced representation of the range of
hues on the color circle, with similar lightness and intensity. They will map
to different color values than the dvips
colors of the same name.
To have proper legibility based on usage, these color names will map to different values when used as a foreground color and a background color. To use a specific color value, use a RGB color instead.
For best portability between versions of TeX, limit yourself to this subset of
DVIPS colors: White
, Black
,
Gray
, Red
, Orange
, Yellow
, LimeGreen
, Green
, TealBlue
, Blue
,
Violet
, Purple
and Magenta
. Those names are case-sensitive.
Font Styling
Bold
Italic
Font Family
Typewriter / Monospace
Sans-Serif
Math Variants
MathJax HTML Extension
Mathfields support some commands from the MathJax HTML extension.
\class
When used in a <math-field>
component, the class names should refer to a
stylesheet defined with a <style>
tag inside the <math-field>
element.
<math-field>
<style>
#custom-CSS-class {
box-shadow: 0 0 10px #000; border-radius: 8px; padding: 8px;
}
</style>
\class{custom-CSS-class}{\frac{1}{x+1}}
</math-field>
\cssId
Apply an element ID to the expression. The element can then be styled using CSS.
#custom-CSS-class {
box-shadow: 0 0 4px #999;
border-radius: 8px;
padding: 8px;
}
\htmlData
The argument of this command is a comma-delimited list of key/value pairs, e.g.
\htmlData{foo=green,bar=blue}{x=0}
. A corresponding
foo
and bar
DOM attributes are attached to the rendered DOM element.
Other Extensions
\error
The argument of this command is a string that will be rendered with a red background and a red underline.
\texttip
The first argument is a math expression to display, the second argument is the text to display on hover.
\mathtip
The first argument is a math expression to display, the second argument is the a math expression to display on hover.
Others
The following commands are supported for compatibility with existing content, but their use is generally discouraged when creating new LaTeX content
Sizing
In LaTeX using the sizing commands below may not always achieve the expected result. In mathfields, the sizing commands are applied consistently to text and math mode.
These size are relative to the font-size
property of the mathfield.
The size of delimiters can be controlled manually with the commands below. The \left...\right...
commands calculate automatically the size of the
delimiters based on the content.
The command must be followed by a delimiter, for example (
or \lbrace
or \lbrack
. If the command is used on its own, nothing is displayed.
Various
MediaWiki (texvc.sty
package)
Mathfields support the commands used by MediaWiki pages, except for the deprecated ones.
Physics
Braket Notation
Mathfields support the commands of the braket
package
Chemistry (mhchem
package)
Mathfields support the commands of the mhchem
package.
Chemical Formulas
Charges
Stoichiometric numbers
Isotopes
Complex Examples
Macros
Environments / Matrixes
Environments are used to typeset a set of related items, for example cells in a matrix, or multi-line equations.
Each row in a tabular environment is separated by a \\
command.
Each column is separated by a &
.
Matrixes
array
A simple table with no delimiters.
The {lc}
argument specifies how many columns there are and how they should be
formated:
l
: left-alignedc
: centeredr
: right-aligned
To add a vertical line separating columns, add a |
character in the column format:
To add a double vertical line separating columns, add two |
characters in the
column format:
To add a dashed vertical line between two columns, use :
:
matrix
The matrix
environment is very similar to array
, but it does not have an
argument to specify the format of the columns.
To specify the format of the columns, use the starred version and an optional
argument. This applies to all the other matrix
environments.
pmatrix
A matrix with parentheses as delimiters.
bmatrix
A matrix with square brackets as delimiters.
Bmatrix
A matrix with braces (curly brackets) as delimiters.
vmatrix
A matrix with single bars as delimiters.
Vmatrix
A matrix with double bars as delimiters.
smallmatrix
A matrix typeset in a way that may be suitable on the same line as text.
Other Environments
cases
, dcases
and rcases
Use these environments to write piecewise functions:
To typeset the content in Display style, use dcases
instead:
To display the brace on the right, use rcases
.
gather
Consecutive equations without alignment
multline
The first line is left aligned, the last line is right aligned, and all the intermediate lines are centered.
align
Others
Avoid center
, use align
instead.
The following environments do not form a math environment by themselves but can be used as building blocks for more elaborate structures:
TeX Registers
The math typesetting is influenced by some "constants" that are stored
in "registers". Those registers can be set globally on a mathfield using
the mf.registers
property.
Register | Purpose |
---|---|
arrayrulewidth | Width of separator lines in array environments |
arraycolsep | Amount of space between separator lines |
arraystretch | Stretch factor between rows in an environment |
delimitershortfall | |
doublerulesep | Amount of space between adjacent separator lines |
jot | Vertical space between the lines for all math expressions which allow multiple lines |
fboxrule | Default width of the border with commands such as \boxed or \fbox |
fboxsep | Default padding between a box and its content |
medmuskip | Amount of space around a binary operator. See also thinmuskip , thickmuskip . |
nulldelimiterspace | Horizontal space of an empty delimiter |
thickmuskip | Amount of space around a relational operator. See also medmuskip , thinmuskip . |
thinmuskip | Amount of space around math punctuation. See also medmuskip , thickmuskip . |
TeX Primitives
The commands below are TeX primitives. Most are only useful when writing TeX packages or macros.
Command | |
---|---|
% | Anything after a % character and an end of line character is interpreted as a comment and ignored |
\limits \nolimits | |
\relax | |
\noexpand | |
\obeyspaces | In Math Mode, spaces are normally ignored. Using this command spaces will be preserved even in Math Mode. |
\bgroup \egroup | Begin/End group, synonym for open/close brace |
\string | |
\csname \endcsname | Turn the next tokens, until \endcsname , into a command |
\ensuremath{} | If in Math Mode, does nothing. Otherwise, switch to Math Mode. |