4077
$\begingroup$

(Deutsch: MathJax: LaTeX Basic Tutorial und Referenz)

To see how any formula was written in any question or answer, including this one, right-click on the expression and choose "Show Math As > TeX Commands". (When you do this, the '$' will not display. Make sure you add these: see the next point. There are also other ways to view the code for the formula or the whole post.)

To try formatting, visit the formatting sandbox post, select one of the answers that says “free for editing” and use the “edit” button to edit the answer however you like. Don't forget to change it back when you are finished, so it can be used again.

  1. For inline formulas, enclose the formula in $$. For displayed formulas, use $$$$.

    • These render differently. For example, type the following to show inline mode:
      $\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$
      $\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$
    • or type the following for display mode:
      $$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$
      $$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$
  2. For Greek letters, use \alpha, \beta, …, \omega: $\alpha$, $\beta$, …, $\omega$.

    • For uppercase letters, use \Gamma, \Delta, …, \Omega: $\Gamma$, $\Delta$, …, $\Omega$.
    • Other Greek capital letters are the same as the Latin ones: A,B,E,Z and so on: $A, B, E, Z$….
    • Some Greek letters have variant forms: \epsilon \varepsilon $\epsilon$, $\varepsilon$, \phi \varphi $\phi$, $\varphi$, and others.
  3. For superscripts and subscripts, use ^ and _. For example, x_i^2: $x_i^2$, \log_2 x: $\log_2 x$. For the prime symbol, use an apostrophe x' x'' x''': $x'\ x''\ x'''$.

  4. Groups. Superscripts, subscripts, and other operations apply only to the next “group”. A “group” is either a single symbol, or any formula surrounded by curly braces {}.

    • If you do 10^10, you will get a surprise: $10^10$. But 10^{10} gives what you probably wanted: $10^{10}$.
    • Use curly braces to delimit a formula to which a superscript or subscript applies: x^y^z is an error; {x^y}^z is ${x^y}^z$, and x^{y^z} is $x^{y^z}$. Observe the differences between x_i^2 $x_i^2$, x_{i^2} $x_{i^2}$ and {x_i}^2 ${x_i}^2$.
  5. Parentheses Ordinary symbols ()[] make parentheses and brackets $(2+3)[4+4]$. Use \{ and \} for curly braces $\{\}$.

    • These do not scale with the formula in between, so if you write (\frac{\sqrt x}{y^3}) the parentheses will be too small: $(\frac{\sqrt x}{y^3})$. Using \left(\right) will make the sizes adjust automatically to the formula they enclose: \left(\frac{\sqrt x}{y^3}\right) is $\left(\frac{\sqrt x}{y^3}\right)$.

    • \left and\right apply to all the following sorts of parentheses: ( and ) $(x)$, [ and ] $[x]$, \{ and \} $\{ x \}$, | $|x|$, \vert $\vert x \vert$, \Vert $\Vert x \Vert$, \langle and \rangle $\langle x \rangle$, \lceil and \rceil $\lceil x \rceil$, and \lfloor and \rfloor $\lfloor x \rfloor$. \middle can be used to add additional dividers. There are also invisible parentheses, denoted by .: use \left.x^2\right\rvert_3^5 = 5^2-3^2 to get $$\left.x^2\right\rvert_3^5 = 5^2-3^2$$

  6. Sums and integrals \sum and \int; the subscript is the lower limit and the superscript is the upper limit, so for example \sum_1^n $\sum_1^n$. Don't forget {} if the limits are more than a single symbol. For example, \sum_{i=0}^\infty i^2 is $\sum_{i=0}^\infty i^2$.

    • Similarly, \prod $\prod$, \int $\int$, \bigcup $\bigcup$, \bigcap $\bigcap$, \iint $\iint$, \iiint $\iiint$, \idotsint $\idotsint$.
  7. Fractions There are three ways to make fractions. \frac ab applies to the next two groups, and produces $\frac ab$; for more complicated numerators and denominators use {}: \frac{a+1}{b+1} is $\frac{a+1}{b+1}$.

    • If the numerator and denominator are complicated, you may prefer \over, which splits up the group that it is in: {a+1\over b+1} is ${a+1\over b+1}$.
    • For continued fractions, use \cfrac instead of \frac.
  8. Fonts

  • Use \mathbb or \Bbb for "blackboard bold": $\mathbb{CHNQRZ}$.
  • Use \mathbf for boldface: $\mathbf{CHNQRZ}$ $\mathbf{chnqrz}$.
    • For expression based characters, use \boldsymbol instead: $\boldsymbol{\alpha}$
  • Use \mathit for italics: $\mathit{CHNQRZ}$ $\mathit{chnqrz}$.
  • Use \pmb for boldfaced italics: $\pmb{CHNQRZ}$ $\pmb{chnqrz}$.
  • Use \mathtt for "typewriter" font: $\mathtt{CHNQRZ}$ $\mathtt{chnqrz}$.
  • Use \mathrm for roman font: $\mathrm{CHNQRZ}$ $\mathrm{chnqrz}$.
  • Use \mathsf for sans-serif font: $\mathsf{CHNQRZ}$ $\mathsf{chnqrz}$.
  • Use \mathcal for "calligraphic" letters: $\mathcal{CHNQRZ}$ (Uppercase only.)
  • Use \mathscr for script letters: $\mathscr{CHNQRZ}$ $\mathscr{chnqrz}$
  • Use \mathfrak for "Fraktur" (old German style) letters: $\mathfrak{CHNQRZ}$ $\mathfrak{chnqrz}$.
  1. Radical signs / roots Use sqrt, which adjusts to the size of its argument: \sqrt{x^3} $\sqrt{x^3}$; \sqrt[3]{\frac xy} $\sqrt[3]{\frac xy}$. For complicated expressions, consider using {...}^{1/2} instead.

  2. Some special functions such as "lim", "sin", "max", "ln", and so on are normally set in roman font instead of italic font. Use \lim, \sin, etc. to make these: \sin x $\sin x$, not sin x $sin x$. Use subscripts to attach a notation to \lim: \lim_{x\to 0} $$\lim_{x\to 0}$$ Nonstandard function names can be set with \operatorname{foo}(x) $\operatorname{foo}(x)$.

  3. There are a very large number of special symbols and notations, too many to list here; see the short listing $\LaTeX$ and $\mathcal{A}_{\Large\mathcal{M}}\mathcal{S}$-$\LaTeX$ Symbols prepared by Dr. Emre Sermutlu, or the exhaustive listing The Comprehensive $\LaTeX$ Symbol List by Scott Pakin. Some of the most common include:

  • \lt \gt \le \ge \neq $\lt$, $\gt$, $\le$, $\ge$,$\neq$. You can use \not to put a slash through almost anything: \not\lt $\not\lt$ but it often looks bad.

  • \times \div \pm \mp $\times$, $\div$, $\pm$, $\mp$. \cdot is a centered dot: $x\cdot y$

  • \cup \cap \setminus \subset \subseteq \subsetneq \supset \in \notin \emptyset \varnothing $\cup$, $\cap$, $\setminus$, $\subset$, $\subseteq$, $\subsetneq$, $\supset$, $\in$, $\notin$, $\emptyset$, $\varnothing$

  • {n+1 \choose 2k} or \binom{n+1}{2k} ${n+1 \choose 2k}$

  • \to \gets \rightarrow \leftarrow \Rightarrow \Leftarrow \mapsto \implies \iff $\to$, $\gets$, $\rightarrow$, $\leftarrow$, $\Rightarrow$, $\Leftarrow$, $\mapsto$, $\implies$, $\iff$

  • \land \lor \lnot \forall \exists \top \bot \vdash \vDash $\land$, $\lor$, $\lnot$, $\forall$, $\exists$, $\top$, $\bot$, $\vdash$, $\vDash$

  • \star \ast \oplus \circ \bullet $\star$, $\ast$, $\oplus$, $\circ$, $\bullet$

  • \approx \sim \simeq \cong \equiv \prec \lhd $\approx$, $\sim $, $\simeq$, $\cong$, $\equiv$, $\prec$, $\lhd$

  • \infty \aleph_0 $\infty\, \aleph_0$ \nabla \partial $\nabla$, $\partial$ \Im \Re $\Im$, $\Re$

  • For modular equivalence, use \pmod like this: a\equiv b\pmod n $a\equiv b\pmod n$. For the binary mod operator, use \bmod like this: a\bmod 17 $a\bmod 17$.

  • Use \dots for the triple dots in $a_1, a_2, \dots, a_n$ and $a_1+a_2+\dots+a_n$

  • Script lowercase l is \ell $\ell$.

    Detexify lets you draw a symbol on a web page and then lists the $\TeX$ symbols that seem to resemble it. These are not guaranteed to work in MathJax, but it's a good place to start. To check that a command is supported, note that MathJax.org maintains a list of currently supported $\LaTeX$ commands, and one can also check Dr. Carol JVF Burns's page of $\TeX$ Commands Available in MathJax.

  1. Spaces MathJax usually decides for itself how to space formulas, using a complex set of rules. Putting extra literal spaces into formulas will not change the amount of space MathJax puts in: a␣b and a␣␣␣␣b are both $a b$. To add more space, use \, for a thin space $a\,b$; \; for a wider space $a\;b$. \quad and \qquad are large spaces: $a\quad b$, $a\qquad b$.

    To set plain text, use \text{…}: $\{x\in s\mid x\text{ is extra large}\}$. You can nest $…$ inside of \text{…}, for example to access spaces.

  2. Accents and diacritical marks Use \hat for a single symbol $\hat x$, \widehat for a larger formula $\widehat{xy}$. If you make it too wide, it will look silly. Similarly, there are \bar $\bar x$ and \overline $\overline{xyz}$, and \vec $\vec x$ and \overrightarrow $\overrightarrow{xy}$ and \overleftrightarrow $\overleftrightarrow{xy}$. For dots, as in $\frac d{dx}x\dot x = \dot x^2 + x\ddot x$, use \dot and \ddot.

  3. Special characters used for MathJax interpreting can be escaped using the \ character: \\$ $\$$, \{ $\{$, \} $\}$, \_ $\_$, \# $\#$, \& $\&$. If you want \ itself, you should use \backslash (symbol) or \setminus (binary operation) for $\backslash$, because \\ is for a new line.

(Tutorial ends here.)


It is important that this note be reasonably short and not suffer from too much bloat. To include more topics, please create short addenda and post them as answers instead of inserting them into this post.

Contents

Alphabetical list of links to MathJax topics, by title:

$\endgroup$
83
  • 40
    $\begingroup$ Some capital Greek letters are the same as the Roman equivalents, so they are not separated in $\LaTeX$. For a capital beta, one must use something like \mathrm{B}: $\mathrm{B}$ $\endgroup$
    – robjohn Mod
    Commented Aug 28, 2012 at 2:06
  • 10
    $\begingroup$ Two related questions: How do I insert a table when asking a question? and How to show the integral symbol on this site? $\endgroup$ Commented Aug 28, 2012 at 13:26
  • 36
    $\begingroup$ A quick addition to point 11: If you want to use a $\sin$-like symbol that is not already defined, the command is \operatorname: e.g., \operatorname{Spec} A gives $\operatorname{Spec} A$. $\endgroup$ Commented Aug 28, 2012 at 16:45
  • 23
    $\begingroup$ It might be useful to mention hanging subscripts for things like _5C_3 $_5C_3$. You could also mention \frac vs \dfrac. $\endgroup$
    – axblount
    Commented Aug 29, 2012 at 18:09
  • 8
    $\begingroup$ My basic idea is that if a beginner can express a formula clearly, then someone else can come in and clean up the typesetting afterwards. I am considering getting rid of the section about \big, \left, and \right for this reason, and trimming the section on spacing. $\endgroup$
    – MJD
    Commented Aug 30, 2012 at 2:06
  • 10
    $\begingroup$ Most of the references to TeX or LaTeX in this and the answers ought to be to MathJaX (the exception that I can see being the output of Detexify). I know this is a bit pedantic, but would it be alright to correct this? $\endgroup$ Commented Sep 11, 2012 at 14:13
  • 6
    $\begingroup$ @AndrewStacey Thanks for pointing this out. Let's by all means be as correct as possible, particularly when there's no extra cost. $\endgroup$
    – MJD
    Commented Sep 11, 2012 at 14:15
  • 4
    $\begingroup$ @MJD Okay, I've had a go (also the answer about arrays). I wonder also whether or not it is worth a sentence at the end pointing out that whilst MathJaX does its best to emulate TeX, it isn't TeX and so while knowing how something is done in TeX gives you a starting point, it isn't a guarantee that the same thing works in MathJaX. (As a case in point, questions about MathJaX are generally off-topic over on TeX-SX.) $\endgroup$ Commented Sep 11, 2012 at 14:22
  • 7
    $\begingroup$ @AndrewStacey I wouldn't. They are close enough that it seems to me to be a needless refinement. I might even argue that MathJax is $\TeX$, although an alternative implementation. We're willing to accept that other programming languages (JavaScript, for example) that have slightly incompatible implementations are nevertheless the same language; why not in this case as well? $\endgroup$
    – MJD
    Commented Sep 11, 2012 at 14:35
  • 11
    $\begingroup$ @MJD Except that this is meant as a tutorial for those who aren't familiar with the distinction (and there really is a distinction: "slightly incompatible implementations" doesn't really fit the bill here). One thing tutorials often include is a "Where to find out more" section. This doesn't. Someone who doesn't know the distinction might be tempted to search for help on TeX or LaTeX instead and wonder why it doesn't work. $\endgroup$ Commented Sep 11, 2012 at 14:40
  • 7
    $\begingroup$ @AndrewStacey All the tips given here would work in any $\TeX$/$\LaTeX$ environment with the proper packages. MathJax is just the service used to render it. You wouldn't say "Miktex tutorial" or "texlive tutorial". $\endgroup$
    – axblount
    Commented Sep 11, 2012 at 15:01
  • 6
    $\begingroup$ @axblount But that's precisely the wrong way around to think about it! The likelihood is that someone will look at this tutorial to figure out how to write something on the Maths-SX site: i.e., to use MathJaX. If they can't find help here, where do they go? If they have the idea that MathJaX is "just a javascript implementation of TeX" then they might think to look for help with TeX, but that is quite possibly not going to be helpful. $\endgroup$ Commented Sep 11, 2012 at 15:08
  • 9
    $\begingroup$ @axblount For a start, you've changed the goalposts: "LaTeX math expressions". LaTeX is so much more than just a way of typesetting maths! Second, I don't really know but it wouldn't take me long to cook one up. I don't use MathJaX so I haven't explored it. But I know, for example, that it can't handle catcode changes. Which means that I can't make ( and ) automatically resizeable. I can in LaTeX. $\endgroup$ Commented Sep 11, 2012 at 16:04
  • 88
    $\begingroup$ I wish I saw this post when I first joined. This post should be a main link on the home page. There should be a button under each box: NEW TO LATEX, CLICK HERE FOR EXAMPLES. This is extremely useful, concise. $\endgroup$ Commented May 31, 2013 at 18:09
  • 16
    $\begingroup$ @MJD: I use \mathrm in many places; e.g. $\mathrm{d}x$ in integrals and derivatives and for operator names that don't need the full force of \operatorname. \mathrm was intended for roman symbols in math mode; \text was intended for text because of the way it spaces things. See this TEX thread. Since I don't believe we can use preambles in MathJax, we can't use \DeclareMathOperator, though we can use \newcommand, but that is orthogonal to the use of \mathrm vs \text for math symbols. $\endgroup$
    – robjohn Mod
    Commented Jun 10, 2013 at 16:23

39 Answers 39

1
2
16
$\begingroup$

Mixing code and MathJax formatting on lines

To give an example of how this might be useful, I wanted to express an algorithm in more or less the same indentation and symbolic way it appears in a paper.

On my desktop browsers (Chrome, Firefox) the following appears reasonably well spaced and indented, but loses indentation on my Android smartphone:

Input: positive integer $n$
Output: Tangent numbers $T_1,\ldots,T_n$
$T_1\gets 1$
for$k$ from $2$ to$n$
$T_k\gets (k−1)T_{k−1}$
for$k$ from $2$ to$n$
for$j$ from$k$ to$n$
$T_j\gets (j −k)T_{j−1} + (j −k+2)T_j$
return $\;T_1,T_2,\ldots,T_n$.

The source can be examined for specific techniques, but the basic trick is that a MathJax dollar-delimiter can follow a closing back-tick code delimiter, but an opening back-tick should be preceded by a space when following the (closing) dollar-sign delimiter.

Here is a version using \phantom rather than code monospacing to produce indents and tweaking the spacing between code and MathJax expressions with \;, so that the results appear clear on Android browsers:

Input: positive integer $n$
Output: Tangent numbers $T_1,\ldots,T_n$
$T_1\gets 1$
for $\;k\;$ from $2\;$ to $\;n$
$\phantom{{}++{}}$ $T_k\gets (k−1)T_{k−1}$
for $\;k\;$ from $2\;$ to $\;n$
$\phantom{{}++{}}$ for $\;j\;$ from $\;k\;$ to $\;n$
$\phantom{{}++{}}$ $\phantom{{}++{}}$ $T_j\gets (j −k)T_{j−1} + (j −k+2)T_j$
return $\;T_1,T_2,\ldots,T_n$.

$\endgroup$
6
  • 5
    $\begingroup$ But this is why we have \space, \quad, and \qquad $\endgroup$ Commented Nov 7, 2016 at 0:41
  • 3
    $\begingroup$ While those are among the ways $\LaTeX$ provides control over spacing, they do not suffice for mixing code and MathJax formatting on a line. $\endgroup$
    – hardmath
    Commented Nov 7, 2016 at 1:05
  • 2
    $\begingroup$ I'm not sure if the topic of mixing other code in is well-suited here. $\endgroup$ Commented Nov 7, 2016 at 2:05
  • 1
    $\begingroup$ I would write the code in TeX using \texttt if I were you. Regardless, this answer probably does not belong here. $\endgroup$
    – pzp
    Commented May 21, 2017 at 14:10
  • $\begingroup$ @pzp: Thanks, that is an interesting suggestion. $\endgroup$
    – hardmath
    Commented May 22, 2017 at 16:15
  • $\begingroup$ @hardmath you can shorten the <code></code> spacers a bit by writing <codde/>, at least in my Jupyter notebooks in Chrome. $\endgroup$
    – Reb.Cabin
    Commented Feb 6, 2018 at 22:28
14
$\begingroup$

Markov Chains

This is a heuristic solution for coding Markov chains in Mathjax using a combination of commutative diagrams, the encircle tool and font sizes. There are a few minor issues with this method, for instance the arrows' ends should be attached closer to their targets. Also, it lacks double-headed diagonal arrows and it is difficult to attach probabilities to diagonal arrows. Therefore, it's mostly useful for small chains.

$$ \require{enclose} \begin{array}{ccccccccc} \Large{\enclose{circle}{A}} & \xrightarrow{0.1} & \Large{\enclose{circle}{B}} & \xrightarrow{0.2} & \Large{\enclose{circle}{C}} & \xleftarrow{0.3} & \Large{\enclose{circle}{D}} & \xleftarrow{0.4} & \Large{\enclose{circle}{E}}\\\ \scriptsize{0.5}\large{\downarrow} & \scriptsize{0.6}\large{\searrow} & \scriptsize{0.7}\large{\downarrow} & \scriptsize{0.8}\large{\nearrow} & \scriptsize{0.9}\large{\downarrow} & \scriptsize{0.1}\large{\swarrow} & \scriptsize{0.2}\large{\downarrow} & \scriptsize{0.3}\large{\nwarrow} & \scriptsize{0.4}\large{\downarrow}\\\ \Large{\enclose{circle}{F}} & \xrightarrow[0.5]{} & \Large{\enclose{circle}{G}} & \xrightarrow[0.6]{} & \Large{\enclose{circle}{H}} & \xleftarrow[0.7]{} & \Large{\enclose{circle}{I}} & \xleftarrow[0.8]{} & \Large{\enclose{circle}{J}}\\ \circlearrowright\tfrac12\\ \end{array} $$

\require{enclose}
\begin{array}{ccccccccc}   
\Large{\enclose{circle}{A}} & \xrightarrow{0.1} & \Large{\enclose{circle}{B}} & \xrightarrow{0.2} & \Large{\enclose{circle}{C}} & \xleftarrow{0.3} & \Large{\enclose{circle}{D}} & \xleftarrow{0.4} & \Large{\enclose{circle}{E}}\\\
\scriptsize{0.5}\large{\downarrow} & \scriptsize{0.6}\large{\searrow} & \scriptsize{0.7}\large{\downarrow} & \scriptsize{0.8}\large{\nearrow} & \scriptsize{0.9}\large{\downarrow} & \scriptsize{0.1}\large{\swarrow} & \scriptsize{0.2}\large{\downarrow} & \scriptsize{0.3}\large{\nwarrow} & \scriptsize{0.4}\large{\downarrow}\\\  
\Large{\enclose{circle}{F}} & \xrightarrow[0.5]{} & \Large{\enclose{circle}{G}} & \xrightarrow[0.6]{} & \Large{\enclose{circle}{H}} & \xleftarrow[0.7]{} & \Large{\enclose{circle}{I}} & \xleftarrow[0.8]{} & \Large{\enclose{circle}{J}}\\
\circlearrowright\tfrac12\\ 
\end{array} 

Credit to Zev Chonoles for the commutative diagram.

$\endgroup$
1
  • $\begingroup$ Is there is code that generates Feynman diagrams? $\endgroup$ Commented Jul 12, 2021 at 14:55
12
$\begingroup$

Tables

W/ Sub-Variables

After spending too much time searching for a way to make tables of this form (to no avail), I spent even longer searching for the pieces (of which most were found here) to Frankenstein my own. I made this table for a combinatorics q on MSE...

$$ \begin{array}{l} \begin{array}{c|c} \hskip36.5pt & \hskip42.5pt\style{font-family:inherit}{\text{Ordering}} \end{array} \\[-7pt]\hline\hskip-5.5pt \begin{array}{c|c|c} \style{font-family:inherit}{\text{Repetition}} & \style{font-family:inherit}{\text{w/}} & \style{font-family:inherit}{\text{w/o}} \\\hline \style{font-family:inherit}{\text{w/}} & P_r^n=n^r & C_r^n=\left(\!\left(\begin{smallmatrix} n \\ r \end{smallmatrix}\right)\!\right)=\left(\begin{smallmatrix} n+r-1 \\ r \end{smallmatrix}\right) \\[0pt]\hline \style{font-family:inherit}{\text{w/o}} & nPr=\frac{n!}{(n-r)!} & nCr=\left(\begin{smallmatrix} n \\ r \end{smallmatrix}\right)=\frac{n!}{r!(n-r)!} \end{array}\hskip-5.5pt \end{array} $$

W/o Sub-Variables

While searching, I found several tables of this form...

$$ \begin{array}{c|c|c|c} \style{font-family:inherit}{\text{Day}} & \style{font-family:inherit}{\text{Credit}} & \style{font-family:inherit}{\text{Debit}} & \style{font-family:inherit}{\text{Total}}\\\hline 0 & 0 & 0 & 10000 \\\hline 1 & 100 & 500 & 9600 \\\hline 2 & 0 & 400 & 10000 \\\hline 3 & 1000 & 500 & 10500 \end{array} $$

$\endgroup$
3
  • $\begingroup$ I still consider myself a MathJax novice so please comment any code simplifications/corrections & I'll make the edit. $\endgroup$
    – Landon
    Commented Mar 20, 2019 at 5:21
  • 2
    $\begingroup$ Related: How do I insert a table when asking a question? $\endgroup$ Commented Mar 20, 2019 at 5:35
  • $\begingroup$ @MartinSleziak That was 1 of the questions I came across while searching for a way to make tables w/ sub-variables. $\endgroup$
    – Landon
    Commented Mar 20, 2019 at 6:17
7
$\begingroup$

Is there a way to make the Greek letters displayed upright (non-italic)?

Asked in comment. There is a way using unicode characters, for which one can search here: http://unicode-table.com/en. Normal use of phi is $\phi = ...$, which gives $\phi = ...$.
Looking up phi on the above site gives a couple of results, if one uses 'Greek Capital Letter Phi' and copy it with 'Click to copy and paste symbol', and use it like
$Φ = ...$, the result is $Φ = ...$.
One might need to experiment which symbol(s) look(s) right.

Is there a tool to visually edit (prepare) the formulas with pre-defined symbols and paste here?

For some of the formulas one can use a word processor app that supports formula edition. E.g. one can use MS Word to construct the formula, or even better use the existing pre-defined ones, like I did with the Binomial theorem, then simply select it, and copy-paste here between the desired number of $'s:

$$ \left(x+a\right)^n=\sum_{k=0}^{n}{\binom{n}{k}x^ka^{n-k}} $$

If it does not look right, it might still be less time to adjust the expression than starting it from scratch, or trying to draw by hand such a thing like the above.

$\endgroup$
1
  • 1
    $\begingroup$ It would be nice to use an upright greek font for the circular ratio, the golden ratio, the Euler–Mascheroni constant, and the Feigenbaum constants, leaving $\pi$, $\phi$, $\gamma$, $\delta$, and $\alpha$ to denote variables. $\endgroup$ Commented Oct 25, 2020 at 13:09
7
$\begingroup$

Tensor indices

T^{\alpha\beta}{}_{\gamma\delta}

$T^{\alpha\beta}{}_{\gamma\delta}$

T^{\alpha \beta}{}_{\gamma\delta}{}^{\lambda}

$T^{\alpha \beta}{}_{\gamma\delta}{}^{\lambda}$

So for instance, a $(2,2)$-tensor would act on two covectors ($\omega$, $\varphi$) and two vectors ($v$,$w$) to produce a real number like this:

$$[T^{\alpha \beta}{}_{\gamma\delta}e_\alpha\otimes e_\beta\otimes e^\gamma \otimes e^\delta](\omega,\varphi,v,w).$$

$\endgroup$
1
  • 4
    $\begingroup$ This trick of raising nothing to an exponent is also used by some to denote e.g. transposes, {}^t\! A yields ${}^t\! A$ $\endgroup$ Commented Oct 31, 2019 at 8:32
7
$\begingroup$

Overlaying symbols

(using negative spacing)

To overlay the $\wedge$ \wedge and the $\bigcirc$ \bigcirc, to make the Kulkarni Nomizu Product:

$$\mathbin{\rlap{\,\wedge}\bigcirc}$$

Which is \mathbin{\rlap{\,\wedge}\bigcirc}.


Just for another example: Overlaying of $\}$ \} and $\div$ \div: $$\rlap{\,\,\}}\div$$

Which is \rlap{\,\,\}}\div.


The command \rlap{c1}c2 prints the character c1 with zero-width on the right-hand side of the current position, so that c2 overlaps with c1. In practice, you might want to

  1. choose the widest character as c2
  2. adjust the horizontal spacing by prepending c1 with extra horizontal space \,.
  3. if necessary, wrap up the symbol with \mathbin so that MathJax treats the symbol like an operator, and the spacing around the symbol is correct.

As you can see, the number of \! is different, for exact overlaying of each symbol. \! makes the characters left and right to it move a little bit closer.

e.g, the code ab produces $ab$.
And the code a\!b produces $a\!b$

$\endgroup$
1
  • 1
    $\begingroup$ The required horizontal spacing is device dependent. An alternative construct is \overset{\bullet}{\smash{cup}}. This introduces a possibly device dependent vertical offset that cannot be adjusted, but I think(??) is always perfectly horizontally centered which is sometimes better. Using mathbin one can get $A\mathbin{\overset{\bullet}{\smash\cup}}B$ for instance. Somehow a further nesting is needed for a \bigcup version: \operatorname*{\overset{\bullet}{\smash{\overset{}{\bigcup}}}}_1^\infty U_i $\operatorname*{\overset{\bullet}{\smash{\overset{}{\bigcup}}}}_1^\infty U_i$ $\endgroup$ Commented Jul 13, 2022 at 12:59
7
$\begingroup$

Evaluated at (integrals):

To get a vertical bar to the right of an expression with the limits of integration, expressions such as $\Big |$$\Big |$ result in one-size-fits-all outputs.

\left. \right|_{}^{} works well as in the made up expression below to illustrate this feature:

$$\left. \left(3x\left(\frac{\left(\log(\frac{3x^2}{6}\right)^{\frac{-x^2}{8}}}{3x^{1/2}} \right) \right) \right|_{\;x=2}^{\;x=8}$$

$\endgroup$
2
  • 2
    $\begingroup$ Thanks for the tip. I used to use \bigg|, but did not know you could use a period as a delimiter $\endgroup$ Commented Jul 28, 2022 at 15:56
  • $\begingroup$ Upvoted. I added an answer about this here as well, only to then see your answer after-the-fact. That's okay though, as my answer expounds on it a bit more and provides additional insight. $\endgroup$ Commented Aug 27, 2022 at 4:55
6
$\begingroup$

Alternative Ways of Writing in $\Large\LaTeX$


TYPESET FONTS

As mentioned before, you can write $\mathtt{. . .}$ to generate fonts like $\mathtt{A}$, $\mathtt{B}$, $\mathtt{C}$ and etc.

You can also produce these fonts writing $\verb|. . .|$ which generates the same fonts $\verb|A|$, $\verb|B|$, $\verb|C|$ and etc.

And concerning different “angle fonts”, $\angle$ generates $\angle$, $\measuredangle$ generates $\measuredangle$ and last but not least, $\sphericalangle$ generates $\sphericalangle$. Also, $\langle...\rangle$ generates $\langle...\rangle$.

Concerning different “approximation fonts”, $\approx$ generates $\approx$ with $\thickapprox$ generating $\thickapprox$. In addition to that, $\sim$ generates $\sim$ and $\thicksim$ generates $\thicksim$ with $\backsim$ generating $\backsim$.

For a symbol of contradiction, you can write $\Rightarrow\Leftarrow$ to generate $\Rightarrow\Leftarrow$ or you can write $\unicode{x21af}$ to generate $\unicode{x21af}$, which is read as Scar (short for Harry Potter's scar, explaining why it looks like a lightning bolt).

$$***$$

INEQUALITY SIGNS

You can write $\lt$ or $<$ to generate $<$ and $\gt$ or $>$ to generate $>$, with $\le$ or $\leq$ to generate $\leq$.

You can also produce similar less than inequality signs with $\leqslant$ to generate $\leqslant$ and $\leqq$ to generate $\leqq$. The same applies for greater than inequality signs, for which we just rewrite the command as $\g...$ instead of $\l...$ which produces $\geq$, $\geqslant$ and $\geqq$.

By putting in an n, we could form commands like $\ngtr$ to generate $\ngtr$ and $\nless$ to generate $\nless$ as opposed to $\not>$ and $\not<$.

Also, $\ngeq$ = $\not\geq$ which generates $\ngeq$ and $\nleq$ = $\not\leq$, generating $\nleq$.

Furthermore, putting slant at the end of strictly the previous two commands generates $\ngeqslant$ and $\nleqslant$.

$$***$$

SET CONTAINMENT

You could write $\not\subseteq$ to generate $\not\subseteq$ or $\not\supseteq$ to generate $\not\supseteq$.

You can write $\subsetneq$ to generate $\subsetneq$ and $\supsetneq$ to generate $\supsetneq$.

Or, you can write $\subsetneqq$ to generate $\subsetneqq$ and $\supsetneqq$ to generate $\supsetneqq$.

By striking out the n in the previous commands with qq at the end, we can generate $\subseteqq$ and $\supseteqq$.

Instead of $\left\{. . .\right\}$ to generate $\left\{...\right\}$, you can write $\lbrace...\rbrace$ to generate the exact same thing. For sets that contain element(s) with a single number or letter, you can also write $\{. . .\}$ to generate strictly $\{. . .\}$ with no other smaller or larger brace sizes.

As another alternative to denoting the difference of two sets $A$ and $B$, you can write $\diagdown$ to generate $\diagdown$ in the set expression, $A\diagdown B$. This command though is mainly used for sets $A^n$ and $B^n$. There also exists $\diagup$ = $\diagup$ by the way to denote the division operation as opposed to the ordinary / or $\div$ = $\div$. $$***$$

OLD-STYLE

For old-style notation, you can write $\eqslantless$ to generate $\eqslantless$ and $\eqslantgtr$ to generate $\eqslantgtr$. These notations can be used to mean the same as $\leqslant$ and $\geqslant$ which is also the same as $\leq$ and $\geq$, but if used today, they commonly represent a not much less than or not much greater than inequality sign.

If you want to write that the statement, $x > y$ and thus $x\neq y$, without any words, then you can write $x \gvertneqq y$ to generate $x \gvertneqq y$. If, on the other hand, you want to then write the same statement for $x < y$ then you can write $x \lvertneqq y$ to generate $x \lvertneqq y$.

Suppose you have that $x\in \mathbb{R}$ but $x \neq 0$ $(\star)$ for example (like in this question), one could write it as follows: $x\in\mathbb{R}\setminus\{0\}$ with $\setminus$ to generate $\backslash$. There is an alternative way of writing $(\star)$, nonetheless.

You can write $\gtrless$ to generate $\gtrless$ which means less than and greater than. If $x\gtrless y$ then $x$ is equal to a number greater than $y$ or less than $y$. Therefore, $x \in\mathbb{R}\setminus\{0\}$ can also be written as $x\gtrless 0$. You can also write $\lessgtr$ to generate $\lessgtr$ which essentially means the same thing. The following commands and notation is unnecessary, for their definition is obvious.

$\gtreqless$ generates $\gtreqless$ and $\lesseqgtr$ generates $\lesseqgtr$.

$\gtreqqless$ generates $\gtreqqless$ and $\lesseqgtr$ generates $\lesseqqgtr$.

$\endgroup$
3
  • $\begingroup$ or $\setminus$ could be used. $\endgroup$
    – user645636
    Commented Sep 14, 2019 at 14:38
  • $\begingroup$ I removed the \backslash, as it is different from \setminus. The command \setminus is a binary operation, which means that it has spacing designed for things like $A\setminus B$, while \backslash is just the symbol itself, so $A\backslash B$ is more squashed. See here for more details. $\endgroup$
    – user1729
    Commented Oct 7, 2020 at 10:54
  • $\begingroup$ Is $\diagdown$ really recommended for difference of sets? 'I'd highly recommend $\setminus$ instead, both for semantic reasons and for type setting reasons. Shouödn't we adjust this recommendation? $\endgroup$ Commented May 15, 2022 at 15:17
6
$\begingroup$

How to draw a stretched vertical bar to indicate the bounds (upper and lower limits) after taking the anti-derivative of a definite integral

I'd like to also expound upon bullet 6 in the question, about parenthesis. I originally put my edit into the question there, but the primary editor of the question reverted my edits. I and others need this information and a good example, so here it is:

There are also invisible parentheses, denoted by ., as in \left. or \right.. These can take the place of any type of parenthesis whether it be (, [, or something else. Ex: \left.\frac12\right\rbrace is $\left.\frac12\right\rbrace$, and \left.\frac12\right) is $\left.\frac12\right)$.

To stretch a vertical bar to be tall, such as to plug in upper and lower limit values into a definite integral's antiderivative, add an invisible vertical bar on the left with \left., and a visible vertical bar on the right with \right|. For lower and upper limits of 0 and 4, respectively, the lower limit is set with _{\;0}, and the upper limit with ^{\;4}, where the \; is a wider space to shift the numbers to the right of the vertical bar.

Example: $$\left.{\left[\cfrac{x}{\cfrac{a+b}{c}}\right]}\right|_{\;0}^{\;4}$$ produces:

$$\left.{\left[\cfrac{x}{\cfrac{a+b}{c}}\right]}\right|_{\;0}^{\;4}$$

See also:

  1. This answer I just saw after writing all this: Evaluated at (integrals)
$\endgroup$
1
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .