2710
$\begingroup$

(Deutsch: MathJax: LaTeX Basic Tutorial und Referenz)

  1. To see how any formula was written in any question or answer, including this one, right-click on the expression it and choose "Show Math As > TeX Commands". (When you do this, the '$' will not display. Make sure you add these. See the next point.)

  2. For inline formulas, enclose the formula in $...$. For displayed formulas, use $$...$$.
    These render differently. For example, type
    $\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$
    to show $\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$ (which is inline mode) or type
    $$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$
    to show $$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$ (which is display mode).

  3. For Greek letters, use \alpha, \beta, …, \omega: $\alpha, \beta, … \omega$. For uppercase, use \Gamma, \Delta, …, \Omega: $\Gamma, \Delta, …, \Omega$.

  4. For superscripts and subscripts, use ^ and _. For example, x_i^2: $x_i^2$, \log_2 x: $\log_2 x$.

  5. 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^5^6 is an error; {x^y}^z is ${x^y}^z$, and x^{y^z} is $x^{y^z}$. Observe the difference between x_i^2 $x_i^2$ and x_{i^2} $x_{i^2}$.

  6. 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 .: \left.\frac12\right\rbrace is $\left.\frac12\right\rbrace$.

    If manual size adjustments are required: \Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr) gives $\Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr)$.

  7. 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$.

  8. Fractions There are three ways to make these. \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}$. Using \cfrac{a}{b} command is useful for continued fractions $\cfrac{a}{b}$, more details for which are given in this sub-article.

  9. Fonts

    • Use \mathbb or \Bbb for "blackboard bold": $\mathbb{CHNQRZ}$.
    • Use \mathbf for boldface: $\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$ $\mathbf{abcdefghijklmnopqrstuvwxyz}$.
    • Use \mathit for italics: $\mathit{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$ $\mathit{abcdefghijklmnopqrstuvwxyz}$.
    • Use \pmb for boldfaced italics: $\pmb{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$ $\pmb{abcdefghijklmnopqrstuvwxyz}$.
    • Use \mathtt for "typewriter" font: $\mathtt{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$ $\mathtt{abcdefghijklmnopqrstuvwxyz}$.
    • Use \mathrm for roman font: $\mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$ $\mathrm{abcdefghijklmnopqrstuvwxyz}$.
    • Use \mathsf for sans-serif font: $\mathsf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$ $\mathsf{abcdefghijklmnopqrstuvwxyz}$.
    • Use \mathcal for "calligraphic" letters: $\mathcal{ ABCDEFGHIJKLMNOPQRSTUVWXYZ}$
    • Use \mathscr for script letters: $\mathscr{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$
    • Use \mathfrak for "Fraktur" (old German style) letters: $\mathfrak{ABCDEFGHIJKLMNOPQRSTUVWXYZ} \mathfrak{abcdefghijklmnopqrstuvwxyz}$.
  10. Radical signs 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.

  11. 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}$$

  12. There are a very large number of special symbols and notations, too many to list here; see this shorter listing, or this exhaustive listing. Some of the most common include:

    • \lt \gt \le \leq \leqq \leqslant \ge \geq \geqq \geqslant \neq $\lt\, \gt\, \le\, \leq\, \leqq\, \leqslant\, \ge\, \geq\, \geqq\, \geqslant\, \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 \rightarrow \leftarrow \Rightarrow \Leftarrow \mapsto $\to\, \rightarrow\, \leftarrow\, \Rightarrow\, \Leftarrow\, \mapsto$
    • \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 \therefore $\approx\, \sim \, \simeq\, \cong\, \equiv\, \prec\, \lhd\, \therefore$
    • \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$.
    • \ldots is the dots in $a_1, a_2, \ldots ,a_n$ \cdots is the dots in $a_1+a_2+\cdots+a_n$
    • Some Greek letters have variant forms: \epsilon \varepsilon $\epsilon\, \varepsilon$, \phi \varphi $\phi\, \varphi$, and others. 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 are 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.

  13. 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{…}.

  14. 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.

  15. Special characters used for MathJax interpreting can be escaped using the \ character: \$ $\$$, \{ $\{$, \_ $\_$, etc. If you want \ itself, you should use \backslash $\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.

$\endgroup$
  • 26
    $\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 Aug 28 '12 at 2:06
  • 7
    $\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$ – Martin Sleziak Aug 28 '12 at 13:26
  • 25
    $\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$ – Charles Staats Aug 28 '12 at 16:45
  • 18
    $\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 Aug 29 '12 at 18:09
  • 5
    $\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 Aug 30 '12 at 2:06
  • 7
    $\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$ – Loop Space Sep 11 '12 at 14:13
  • 4
    $\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 Sep 11 '12 at 14:15
  • 3
    $\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$ – Loop Space Sep 11 '12 at 14:22
  • 5
    $\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 Sep 11 '12 at 14:35
  • 10
    $\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$ – Loop Space Sep 11 '12 at 14:40
  • 5
    $\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 Sep 11 '12 at 15:01
  • 5
    $\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$ – Loop Space Sep 11 '12 at 15:08
  • 8
    $\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$ – Loop Space Sep 11 '12 at 16:04
  • 70
    $\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$ – user1527227 May 31 '13 at 18:09
  • 10
    $\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 Jun 10 '13 at 16:23

33 Answers 33

9
$\begingroup$

Linear programming

Formulation

A theoretical LPP can be typeset as

\begin{array}{ll}
\text{maximize}  & c^T x \\
\text{subject to}& d^T x = \alpha \\
&0 \le x \le 1.
\end{array}

\begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array}

To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients.

\begin{alignat}{5}
  \max \quad        & z = &   x_1  & + & 12 x_2  &   &       &         && \\
  \mbox{s.t.} \quad &     & 13 x_1 & + & x_2     & + & 12x_3 & \geq 5  && \tag{constraint 1} \\
                    &     & x_1    &   &         & + & x_3   & \leq 16 && \tag{constraint 2} \\
                    &     & 15 x_1 & + & 201 x_2 &   &       & =    14 && \tag{constraint 3} \\
                    &     & \rlap{x_i \ge 0, i = 1, 2, 3}
\end{alignat}

\begin{alignat}{5} \max \quad & z = & x_1 & + & 12 x_2 & & & && \\ \mbox{s.t.} \quad & & 13 x_1 & + & x_2 & + & 12x_3 & \geq 5 && \tag{constraint 1} \\ & & x_1 & & & + & x_3 & \leq 16 && \tag{constraint 2} \\ & & 15 x_1 & + & 201 x_2 & & & = 14 && \tag{constraint 3} \\ & & \rlap{x_i \ge 0, i = 1, 2, 3} \end{alignat}

We treat $\max$, $z$, each variable, $\pm$ sign and RHS as one separate column, while leaving an extra empty column on the right. Then we count the number of separators &, add one into this number then divide it by two. (e.g. (9 + 1) ÷ 2 = 5)

\rlap is used so that the last row spans over one column.

Optional: \tag is used to label the constraints.

Change MATLAB/Octave matrices to $\rm\LaTeX$ code

To get fractions, execute format rat at the beginning.

Writing manually the $\rm\LaTeX$ code for a matrix with many rows and columns in Octave is tedious. The Octave function

strcat("\\begin{bmatrix}\n",strrep(strrep(mat2str(A)," "," & "), ...
";"," \\\\\n")(2:end-1),"\n\\end{bmatrix}\n")

converts

A = [1 2 2; 2 3 4; 4 4 2]
A =

   1   2   2
   2   3   4
   4   4   2

to

\begin{bmatrix}
1 & 2 & 2 \\
2 & 3 & 4 \\
4 & 4 & 2
\end{bmatrix}

so that pasting the generated code gives

$$ \begin{bmatrix} 1 & 2 & 2 \\ 2 & 3 & 4 \\ 4 & 4 & 2 \end{bmatrix}. $$

Simplex tableaux

Since the coefficient of the objective value variable $z$ never changes, my habit is to omit the $z$-column to save ink.

Normal simplex tableau

\begin{array}{rrrrrr|r}
               & x_1 & x_2 & s_1 & s_2 & s_3 &    \\ \hline
           s_1 &   0 &   1 &   1 &   0 &   0 &  8 \\
           s_2 &   1 &  -1 &   0 &   1 &   0 &  4 \\
           s_3 &   1 &   1 &   0 &   0 &   1 & 12 \\ \hline
               &  -1 &  -1 &   0 &   0 &   0 &  0
\end{array}

\begin{array}{rrrrrr|r} & x_1 & x_2 & s_1 & s_2 & s_3 & \\ \hline s_1 & 0 & 1 & 1 & 0 & 0 & 8 \\ s_2 & 1 & -1 & 0 & 1 & 0 & 4 \\ s_3 & 1 & 1 & 0 & 0 & 1 & 12 \\ \hline & -1 & -1 & 0 & 0 & 0 & 0 \end{array}

It can be stacked up to give an illustration of the entering of variables at different stages.

\begin{array}{rrrrrrr|rr}
      & x_1 & x_2 & s_1 & s_2 & s_3 &  w &    & \text{ratio} \\ \hline
  s_1 &   0 &   1 &   1 &   0 &   0 &  0 &  8 &            - \\
    w & 1^* &  -1 &   0 &  -1 &   0 &  1 &  4 &            4 \\
  s_3 &   1 &   1 &   0 &   0 &   1 &  0 & 12 &           12 \\ \hdashline
      &   1 &  -1 &   0 &  -1 &   0 &  0 &  4 &              \\ \hline
  s_1 &   0 &   1 &   1 &   0 &   0 &  0 &  8 &              \\
  x_1 &   1 &  -1 &   0 &  -1 &   0 &  1 &  4 &              \\
  s_3 &   0 &   2 &   0 &   2 &   1 & -1 &  8 &              \\ \hdashline
      &   0 &   0 &   0 &   0 &   0 & -1 &  0 &
\end{array}

\begin{array}{rrrrrrr|rr} & x_1 & x_2 & s_1 & s_2 & s_3 & w & & \text{ratio} \\ \hline s_1 & 0 & 1 & 1 & 0 & 0 & 0 & 8 & - \\ w & 1^* & -1 & 0 & -1 & 0 & 1 & 4 & 4 \\ s_3 & 1 & 1 & 0 & 0 & 1 & 0 & 12 & 12 \\ \hdashline & 1 & -1 & 0 & -1 & 0 & 0 & 4 & \\ \hline s_1 & 0 & 1 & 1 & 0 & 0 & 0 & 8 & \\ x_1 & 1 & -1 & 0 & -1 & 0 & 1 & 4 & \\ s_3 & 0 & 2 & 0 & 2 & 1 & -1 & 8 & \\ \hdashline & 0 & 0 & 0 & 0 & 0 & -1 & 0 & \end{array}

Dual simplex tableau

\begin{array}{rrrrrrrr|r}
             & x_1 & x_2 & x_3 & x_4 & x_5 & x_6 &  x_7 &        \\ \hline
         x_4 &   0 &  -3 &   7 &   1 &   0 &   0 &    2 & 2M  -4 \\
         x_5 &   0 &  -9 &   0 &   0 &   1 &   0 &   -1 & -M  -3 \\
         x_6 &   0 &   6 &  -1 &   0 &   0 &   1 & -4^* & -4M +8 \\
         x_1 &   1 &   0 &   1 &   0 &   0 &   0 &    1 &      M \\ \hline
             &   0 &   1 &   1 &   0 &   0 &   0 &    2 &     2M \\
\text{ratio} &     &     &   1 &     &     &     &  1/2 &
\end{array}

\begin{array}{rrrrrrrr|r} & x_1 & x_2 & x_3 & x_4 & x_5 & x_6 & x_7 & \\ \hline x_4 & 0 & -3 & 7 & 1 & 0 & 0 & 2 & 2M -4 \\ x_5 & 0 & -9 & 0 & 0 & 1 & 0 & -1 & -M -3 \\ x_6 & 0 & 6 & -1 & 0 & 0 & 1 & -4^* & -4M +8 \\ x_1 & 1 & 0 & 1 & 0 & 0 & 0 & 1 & M \\ \hline & 0 & 1 & 1 & 0 & 0 & 0 & 2 & 2M \\ \text{ratio} & & & 1 & & & & 1/2 & \end{array}

It can be stacked up to give a theoretical illustration of what happens in the upcoming steps.

\begin{array}{rrrrrrr|r} & x_1 & x_2 & x_3 & s_1 & s_2 & s_3 & \\ \hline s_1 & -2 & 0 & -2 & 1 & 0 & 0 & -60 \\ s_2 & -2 & -4^* & -5 & 0 & 1 & 0 & -70 \\ s_3 & 0 & -3 & -1 & 0 & 0 & 1 & -27 \\ \hdashline & 8 & 10 & 25 & 0 & 0 & 0 & 0 \\ \text{ratio} & -4 & -5/2 & -5 & & & & \\ \hline s_1 & -2^* & 0 & -2 & 1 & 0 & 0 & -60 \\ x_2 & 1/2 & 1 & 5/4 & 0 & -1/4 & 0 & 35/2 \\ s_3 & 3/2 & 0 & 11/4 & 0 & -3/4 & 1 & 51/2 \\ \hdashline & 3 & 0 & 25/2 & 0 & 5/2 & 0 & -175 \\ \text{ratio} & -3/2 & & 25/4 & & & & \\ \hline x_1 & 1 & 0 & 1 & -1/2 & 0 & 0 & 30 \\ x_2 & 0 & 1 & 3/4 & 1/4 & -1/4 & 0 & 5/2 \\ s_3 & 0 & 0 & 5/4 & 3/4 & -3/4^* & 1 & -39/2 \\ \hdashline & 0 & 0 & 19/2 & 3/2 & 5/2 & 0 & -265 \\ \text{ratio} & & & & & \dots & & \\ \hline x_1 & 1 & 0 & 1 & -1/2 & 0 & 0 & 30 \\ x_2 & 0 & 1 & 1/3 & 0 & 0 & -1/3 & 9 \\ s_2 & 0 & 0 & -5/3 & -1 & 1 & -4/3 & 26 \\ \hdashline & 0 & 0 & 41/3 & 4 & 0 & 10/3 & -330 \end{array}

Duality

A picture is worth a thousand words.

$$ \require{extpfeil} % produce extensible horizontal arrows \begin{array}{ccc} % arrange LPPs % first row % first LPP \begin{array}{ll} \max & z = c^T x \\ \text{s.t.} & A x \le b \\ & x \ge 0 \end{array} & \xtofrom{\text{duality}} & % second LPP \begin{array}{ll} \min & v = b^T y \\ \text{s.t.} & A^T y \ge c \\ & y \ge 0 \end{array} \\ ({\cal PC}) & & ({\cal DC}) \\ \text{add } {\Large \downharpoonleft} \text{slack var} & & \text{minus } {\Large \downharpoonright} \text{surplus var}\\ % Change to your favorite arrow style % % second row % third LPP \begin{array}{ll} \max & z = c^T x \\ \text{s.t.} & A x + s = b \\ & x,s \ge 0 \end{array} & \xtofrom[\text{some steps skipped}]{\text{duality}} & % fourth LPP \begin{array}{ll} \min & v = b^T y \\ \text{s.t.} & A^T y - t = c \\ & y,t \ge 0 \end{array} \\ ({\cal PS}) & & ({\cal DS}) % \end{array} $$

$\endgroup$
  • 2
    $\begingroup$ It must have taken more than a thousand words to write that picture though :D $\endgroup$ – Mr Pie Jul 20 '18 at 9:25
2
$\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$ or $\backslash$ 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$
2
$\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$
  • $\begingroup$ I still consider myself a MathJax novice so please comment any code simplifications/corrections & I'll make the edit. $\endgroup$ – Landon Mar 20 at 5:21
  • $\begingroup$ Related: How do I insert a table when asking a question? $\endgroup$ – Martin Sleziak Mar 20 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 Mar 20 at 6:17

You must log in to answer this question.

protected by MJD May 28 '15 at 17:18

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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