Insert Equations into the Live Editor - MATLAB & Simulink (original) (raw)

To describe a mathematical process or method used in your code, insert equations into your live script or function. Only text lines can contain equations. If you insert an equation into a code line, MATLAB® places the equation into a new text line directly under the selected code line.

Live script with text and two equations that describe the calculations being performed in the code below

There are two ways to insert an equation into a live script or function.

Insert Equation Interactively

To insert an equation interactively:

  1. Go to the Insert tab and click Equation.
    A blank equation appears.
    Live script in the Live Editor with a blank code line and a text box prompting you to enter your equation
  2. Build your equation by selecting symbols, structures, and matrices from the options displayed in the Equation tab. View additional options by clicking the drop-down arrow to the right of each section.
    When adding or editing a matrix, a context menu appears, which you can use to delete and insert rows and columns. You also can use the context menu to change or remove matrix delimiters.
  3. Format your equation using the options available in theText section. Formatting is only available for text within the equation. Numbers and symbols cannot be formatted. The formatting option is disabled unless the cursor is placed within text that can be formatted.

Keyboard Shortcuts for Equation Editing

The equation editor provides a few shortcuts for adding elements to your equation:

Insert LaTeX Equation

To insert a LaTeX equation:

  1. Go to the Insert tab, clickEquation , and select .
  2. Enter a LaTeX expression in the dialog box that appears. For example, you can enter \sin(x) = \sum_{n=0}^{\infty}{\frac{(-1)^n x^{2n+1}}{(2n+1)!}}.
    The preview pane shows a preview of equation as it would appear in the live script.
    Edit Equation dialog box with LaTeX equation code, its corresponding preview, and a description of the equation in the Alt Text field
  3. To include a description of the LaTeX equation when exporting the live script to HTML, add text to the Alt Text field. For example, you can enter the text Maclaurin series for sin(x).
    The description specifies alternative text for the equation and is saved as an alt attribute in the HTML document. It is used to provide additional information for the equation if, for example, a user is using a screen reader.
  4. Press OK to insert the equation into your live script.

LaTeX expressions describe a wide range of equations. This table shows several examples of LaTeX expressions and their appearance when inserted into a live script.

LaTeX Expression Equation in Live Script
a^2 + b^2 = c^2 a2+b2=c2
\int_{0}^{2} x^2\sin(x) dx ∫02x2sin(x)dx
\sin(x) = \sum_{n=0}^{\infty}{\frac{(-1)^n x^{2n+1}}{(2n+1)!}} sin(x)=∑n=0∞(−1)nx2n+1(2n+1)!
{a,b,c} \neq \{a,b,c\} a,b,c≠{a,b,c}
x^{2} \geq 0\qquad \text{for all}x\in\mathbf{R} x2≥0 for all x∈R
\matrix{a & b \cr c & d} abcd

Supported LaTeX Commands

MATLAB supports most standard LaTeX math mode commands. These tables show a list of supported LaTeX commands.

Non-ASCII Letters

Symbol LaTeX Command Symbol LaTeX Command Symbol LaTeX Command
ø o œ oe å aa
Ø O Œ OE Å AA
ł l æ ae ß ss
Ł L Æ AE

Greek/Hebrew Letters

Symbol LaTeX Command Symbol LaTeX Command Symbol LaTeX Command
α alpha ν nu ξ xi
β beta ω omega ζ zeta
χ chi о omicron ɛ varepsilon
δ delta ϕ phi φ varphi
ε epsilon π pi ϖ varpi
η eta ψ psi ϱ varrho
v gamma ρ rho ς varsigma
ι iota σ sigma ϑ vartheta
κ kappa τ tau א aleph
λ lambda θ theta
μ mu υ upsilon
Δ Delta Φ Phi Θ Theta
Γ Gamma Π Pi ϒ Upsilon
Λ Lambda Ψ Psi Ξ Xi
Ω Omega Σ Sigma

Operator Symbols

Symbol LaTeX Command Symbol LaTeX Command Symbol LaTeX Command
* ast ± pm wr
star mp cap
· cdot ⨿ amalg cup
circ odot uplus
bullet ominus sqcap
diamond oplus sqcup
setminus oslash wedge, land
× times otimes vee, lor
÷ div bigoplus triangleleft
bot, perp bigotimes triangleright
top bigodot bigtriangleup
prod biguplus bigtriangledown
coprod bigcap bigvee
sum bigcup bigwedge
int, intop oint bigsqcup
intbar

Relation Symbols

Symbol LaTeX Command Symbol LaTeX Command Symbol LaTeX Command
equiv < lt > gt
cong le, leq ge, geq
neq, ne,not= not< not>
sim prec succ
simeq preceq succeq
approx ll gg
asymp subset supset
doteq subseteq supseteq
propto sqsubseteq sqsupseteq
models mid in
bowtie parallel notin
vdash iff ni, owns
dashv

Note

Some commands can be combined with the not command to create the negated version of the symbol. For example,\not\leq creates the symbol ≰. The commands that can be combined includeleq, geq,equiv, cong,approx, sim, simeq,models, ni,parallel, succ,succeq, prec,preceq, subset,supset, subseteq,supseteq, sqsubseteq, andsqsupseteq.

Arrows

Symbol LaTeX Command Symbol LaTeX Command Symbol LaTeX Command
leftarrow rightarrow uparrow
Leftarrow Rightarrow Uparrow
longleftarrow longrightarrow downarrow
Longleftarrow Longrightarrow Downarrow
hookleftarrow hookrightarrow updownarrow
leftharpoondown rightharpoondown Updownarrow
leftharpoonup rightharpoonup leftrightarrow
swarrow nearrow Leftrightarrow
nwarrow searrow longleftrightarrow
mapsto longmapsto Longleftrightarrow

Brackets

Symbol LaTeX Command Symbol LaTeX Command Symbol LaTeX Command
{ lbrace } rbrace | vert
[ lbrack ] rbrack Vert
langle rangle \ backslash
lceil rceil
lfloor rfloor
llbracket rrbracket
Sample LaTeX Command Sample LaTeX Command Sample LaTeX Command
Sample big left brace big, bigl,bigr, bigm Sample bigg left brace bigg, biggl,biggr, biggm {abc} brace
Sample Big left brace Big, Bigl,Bigr, Bigm Sample Bigg left brace Bigg, Biggl,Biggr, Biggm [abc] brack

Misc Symbols

Symbol LaTeX Command Symbol LaTeX Command Symbol LaTeX Command
infty forall wp
nabla exists angle
partial emptyset triangle
Im ı i lozenge
Re ȷ j hbar
ell ı imath prime
dots, ldots,hellip ȷ jmath ¬ lnot, neg
cdots : colon surd
ddots cdotp gets
vdots . ldotp to
because therefore varpropto
° degree clubsuit varclubsuit
dag, dagger heartsuit varheartsuit
ddag, ddagger diamondsuit vardiamondsuit
ldsh spadesuit varspadesuit
§ mathsection

Note

The exists command can be combined with thenot command to create the negated version of the symbol. For example, \not\exists creates the symbol ∄.

Text Symbols

Sample LaTeX Command Sample LaTeX Command Sample LaTeX Command
£ pounds,textsterling ¿ textquestiondown quotedblbase
¢ textcent ¡ textexclamdown backprime
texteuro « flqq,guillemotleft space
¥ yen » frqq,guillemotright permil
® textregistered § S \ backslash
trademark,texttrademark P ¦ brokenvert
© copyright

Accents

Symbol LaTeX Command Symbol LaTeX Command Symbol LaTeX Command
á acute dot tilde
bar ddot a→ vec
a⌣ breve a⃛ dddot à grave
check a⃜ ddddot a^ hat

Functions

Sample LaTeX Command Sample LaTeX Command Sample LaTeX Command
arccos arccos det det ln ln
arcsin arcsin dim dim log log
arctan arctan exp exp max max
arg arg gcd gcd min min
cos cos hom hom Pr Pr
cosh cosh ker ker sec sec
cot cot lg lg sin sin
coth coth lim lim sinh sinh
csc csc liminf liminf sup sup
deg deg limsup limsup tan tan

Math Constructs

Sample LaTeX Command Sample LaTeX Command Sample LaTeX Command
abcxyz frac ba stackrel,overset ab over
abc sqrt ba underset [ab] overwithdelims
mod a bmod (ab) binom, choose abc← overleftarrow
(moda) pmod (abcd) pmatrix abc→ overrightarrow
abc^ widehat abcd matrix abc↔ overleftrightarrow
abc˜ widetilde abcd begin{array} ab¯cd¯ hline
〈abc| bra {abcd begin{cases} ∑i=010 limits
|abc〉 ket {a2|b2} left, middle,right ∑i=010 nolimits
〈ab|cd〉 braket

Note

To create a matrix using the matrix andpmatrix commands, use the & symbol to separate columns, and \cr to separate rows. For example, to create a 2–by–2 matrix, use the expression \matrix{a & b \cr c & d}.

For large operators, MATLAB automatically adjusts the position of limits depending on whether or not there is text inline with the equation. To force the display of the limits above and below the operator, use thelimits command. To force the display of the limits adjacent to the operator, use the \nolimits command. For example, the expression \sum\limits_{i=0}^{10} displays the limits of the summation operator above and below the operator. The expression \sum\nolimits_{i=0}^{10} displays the limits of the summation operator adjacent to the operator.

∑i=010∑i=010

White Space

Sample LaTeX Command Sample LaTeX Command Sample LaTeX Command
ab negthinspace abc mathord a[b mathopen
ab thinspace a∑b mathop a]b mathclose
a b enspace a+b mathbin a | b mathinner
a b hspace a=b mathrel a b quad
a b kern,mkern a,b mathpunct a b qquad

Text Styling

Sample LaTeX Command Sample LaTeX Command Sample LaTeX Command
Sample sum symbol in display style displaystyle ABCDE text, textnormal,textup ABCDE texttt
Sample sum symbol in text style textstyle ABCDE bf, textbf,mathbf ABCDE textsf
Sample sum symbol in script style scriptstyle ABCDE it, textit,mathit AℬCDℰ cal, mathcal
Sample sum symbol in scriptscript style scriptscriptstyle ABCDE rm, textrm,mathrm ABℂD mathbb
ABCDE hbox, mbox ABℭD mathfrak

See Also

Topics

External Websites