Hot answers tagged

384

Matrices Use $$\begin{matrix}…\end{matrix}$$ In between the \begin and \end, put the matrix elements. End each matrix row with \\, and separate matrix elements with &. For example, $$ \begin{matrix} 1 & x & x^2 \\ 1 & y & y^2 \\ 1 & z & z^2 \\ \end{matrix} $$ produces: $$ \begin{matrix} 1 & x &...


273

Aligned equations Often people want a series of equations where the equals signs are aligned. To get this, use \begin{align}…\end{align}. Each line should end with \\, and should contain an ampersand at the point to align at, typically immediately before the equals sign. For example, \begin{align} \sqrt{37} & = \sqrt{\frac{73^2-1}{12^2}} \\ & = ...


226

Definitions by cases (piecewise functions) Use \begin{cases}…\end{cases}. End each case with a \\, and use & before parts that should be aligned. For example, you get this: $$f(n) = \begin{cases} n/2, & \text{if $n$ is even} \\ 3n+1, & \text{if $n$ is odd} \end{cases}$$ by writing this: f(n) = \begin{cases} n/2, & \text{if $n$ is ...


157

Arrays It is often easier to read tables formatted in MathJax rather than plain text or a fixed width font. Arrays and tables are created with the array environment. Just after \begin{array} the format of each column should be listed, use c for a center aligned column, r for right aligned, l for left aligned and a | for a vertical line. Just as with ...


150

Fussy spacing issues These are issues that won't affect the correctness of formulas, but might make them look significantly better or worse. Beginners should feel free to ignore this advice; someone else will correct it for them, or more likely nobody will care. Don't use \frac in exponents or limits of integrals; it looks bad and can be confusing, which is ...


124

Crossing things out Use \require{cancel} in the first formula in your post that requires cancelling; you need it only once per page. Then use: $$\require{cancel}\begin{array}{rl} \verb|y+\cancel{x}| & y+\cancel{x}\\ \verb|\cancel{y+x}| & \cancel{y+x}\\ \verb|y+\bcancel{x}| & y+\bcancel{x}\\ \verb|y+\xcancel{x}| & y+\xcancel{x}\\ \verb|y+\...


113

System of equations Use \begin{array}…\end{array} and \left\{…\right.. For example, you get this: $$ \left\{ \begin{array}{c} a_1x+b_1y+c_1z=d_1 \\ a_2x+b_2y+c_2z=d_2 \\ a_3x+b_3y+c_3z=d_3 \end{array} \right. $$ by writing this: $$ \left\{ \begin{array}{c} a_1x+b_1y+c_1z=d_1 \\ a_2x+b_2y+c_2z=d_2 \\ a_3x+b_3y+c_3z=d_3 \end{array} \right. $$ ...


108

Colors Named colors are browser-dependent; if a browser doesn't know a particular color name, it may render the text as black. The following colors are standard in HTML4 and CSS2 and should be interpreted the same by most browsers: $$\begin{array}{|rc|} \hline \verb+\color{black}{text}+ & \color{black}{text} \\ \verb+\color{gray}{text}+ & \color{...


106

Additional decorations $\def\demo#1#2{#1{#2}\ #1{#2#2}\ #1{#2#2#2}}$ \overline: $\demo\overline A$ \underline: $\demo\underline B$ \widetilde: $\demo\widetilde C$ \widehat: $\demo\widehat D$ \fbox: $\demo\fbox {$E$}$ \underleftarrow: $\demo\underleftarrow{F}\qquad$ variant: \xleftarrow{}: $\xleftarrow{abc}$ \underrightarrow: $\demo\underrightarrow{...


103

Commutative diagrams AMScd diagrams must start with a "require": $\require{AMScd}$ \begin{CD} A @>a>> B\\ @V b V V= @VV c V\\ C @>>d> D \end{CD} to get this diagram: $\require{AMScd}$ \begin{CD} A @>a>> B\\ @V b V V= @VV c V\\ C @>>d> D \end{CD} @>>> is used for arrow right @<<< is used for arrow ...


88

Continued fractions To make a continued fraction, use \cfrac, which works just like \frac but typesets the results differently: $$ x = a_0 + \cfrac{1^2}{a_1 + \cfrac{2^2}{a_2 + \cfrac{3^2}{a_3 + \cfrac{4^4}{a_4 + \cdots}}}}$$ Don't use regular \frac or \over, or it will look awful: $$ x = a_0 + \frac{1^2}{a_1 + \frac{2^2}{...


85

Using \newcommand I would like to remark that it is possible to define LaTeX commands as you do in your TeX files. I felt so happy when I first discovered it! It's enough to insert something like $ \newcommand{\SES}[3]{ 0 \to #1 \to #2 \to #3 \to 0 } $ $ \newcommand{\SES}[3]{ 0 \to #1 \to #2 \to #3 \to 0 }$ at the top of your post (remember the dollars!). ...


84

Tags & References For longer calculations (or referring to other post's results) it is convenient to use the tagging/labelling/referencing system. To tag an equation use \tag{yourtag}, and if you want to refer to that tag later on, add \label{somelabel} right after the \tag. It is not necessary that yourtag and somelabel are the same, but it usually is ...


79

\implies ($\implies$) is a marginally preferable alternative to \Rightarrow ($\Rightarrow$) for implication. There's also \iff $\iff$ and \impliedby $\impliedby$. \to ($\to$) is preferable to \rightarrow or \longrightarrow for things like $f\colon A \to B$. The reverse is \gets ($\gets$).


69

Big braces Use \left and \right to make braces - (round), [square] and {curly} - scale up to be the size of their arguments. Thus $$ f\left( \left[ \frac{ 1+\left\{x,y\right\} }{ \left( \frac{x}{y}+\frac{y}{x} \right) \left(u+1\right) }+a \right]^{3/2} \right) $$ renders as $$ f\left(\left[ \frac{...


66

Limits To make a limit (like $\lim \limits_{x \to 1} \frac{x^2-1}{x-1}$), use this syntax: First, start off with $\lim. This renders as $\lim$. The backslash is there to prevent things like $lim$, where the letters are slanted. Second, add \limits_{x \to 1} inside. The code now looks like $\lim \limits_{x \to 1}$, and renders as $\lim \limits_{x \to 1}$. ...


57

Arbitrary operators If an operator is not available as a built-in command, use \operatorname{…}. So for things like $$\operatorname{arsinh}(x)$$ write \operatorname{arsinh}(x) since \arsinh(x) will give an error and arsinh(x) has wrong font and spacing: $arsinh(x)$. This was already mentioned in a comment by Charles Staats. You might consider this an ...


55

Highlighting equation To highlight an equation, \bbox can be used. E.g, $$ \bbox[yellow] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1) } $$ produces $$ \bbox[yellow] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1) } $$ By default, the bounding box is "tight", so it doesn't extend beyond the characters used in the ...


52

From typographical point of view, the question whether d in dx is upright or italic is not clear at all, it varies from author to author, from sub-field to sub-field and from journal to journal. Therefore I think that we should not unify the style across the site and rather leave it to the authors. What is not questionable, though, is that dx has to be ...


49

Absolute values and norms The absolute value of some expression can be denoted as \lvert x\rvert or, more generally, as \left\lvert … \right\rvert. It renders as $\lvert x\rvert$. The norm of a vector (or similar) can be denoted as \lVert v\rVert or, more generally, as \left\lVert … \right\rVert. It renders as $\lVert v\rVert$. (You may also write \left\|…\...


48

Giving reasons on each line of a sequence of equations To produce this: \begin{align} v + w & = 0 &&\text{Given} \tag 1\\ -w & = -w + 0 && \text{additive identity} \tag 2\\ -w + 0 & = -w + (v + w) && \text{equations $(1)$ and $(2)$} \end{align} write this: \begin{align} v + w & = 0 &&\text{...


44

Pack of cards If you are asking (or answering) a combinatorics question involving packs of cards you can make it look more elegant by using \spadesuit, \heartsuit, \diamondsuit, \clubsuit in math mode: $$\spadesuit\quad\heartsuit\quad\diamondsuit\quad\clubsuit$$ Or if you're really fussy: \color{red}{\heartsuit} and \color{red}{\diamondsuit} $$\color{red}{\...


42

First, as explained in this meta post, you should always mark your formulas as math using dollar signs or the such. This is for people with screen readers, automatic processing of posts... A bare θ, if it's supposed to represent a math variable, is no good. (Of course if you're writing something in Greek then you should not mark it as math.) Now, MathJax ...


39

Left and Right Implication Arrows Another way to display the arrows for right and left implication instead of using $\Rightarrow$, $\Leftarrow$ and $\Leftrightarrow$ which produces $\Rightarrow$, $\Leftarrow$ and $\Leftrightarrow$ respectively, you can use $\implies$ for $\implies$, $\impliedby$ for $\impliedby$ and $\iff$ for $\iff$ The latter of which ...


39

At present: I do not think KaTeX is yet a viable option. At issue is feature parity. For comparison: MathJax supports on the order of ~800 built-in commands, plus the ability to define new macros using \def or \newcommand. Currently, the link given in Lipis's comment shows around ~250 commands supported. Mathjax also supports environments defined in the ...


36

In addition to the below title-specific $\rm\LaTeX$ guidelines, there is of course the MathJax tutorial and quick reference. The primary rule for using $\rm\LaTeX$ in titles is to be vertically terse. Try to make your title take up as little vertical space as possible (the height of $\sum\limits_{n=1}^\infty$ is an approximate upper bound for what is ...


35

As other answers have already explained, LaTeX and MathJax are related markup languages for preparing mathematical documents. In particular, MathJax is designed to be readily usable by people who know LaTeX. However, MathJax does not support the full power of LaTeX because (1) doing so would be very computationally intensive (2) doing so would be ...


35

You can experiment with the CD environment by including $\require{AMScd}$ in your post, and then using \begin{CD}...\end{CD}, as below. Here is an example using CD:$\require{AMScd}$ \begin{CD} A @>a>> B\\@VVbV @VVcV\\ C @>d>> D \end{CD}


33

This is supposed to be an all-purpose math site, and obviously not everyone in the world who has a math question knows how to use latex. Although learning latex is not so very hard, it is not trivial either, and assuming that people must have this skill in order to get continued service seems like a clear violation of the intended scope of the site. Also,...


Only top voted, non community-wiki answers of a minimum length are eligible