5.1 Writing formulas in TeX
From Förberedande kurs i matematik 1
m |
m |
||
Line 88: | Line 88: | ||
<tr> | <tr> | ||
<td></td> | <td></td> | ||
- | <td align="center"><span class="math">\frac{ | + | <td align="center"><span class="math">\frac{1}{2}</span></td> |
- | <td align="center"><tt>\frac{ | + | <td align="center"><tt>\frac{1}{2}</tt></td> |
- | <td align="left"> | + | <td align="left">Small fraction</td> |
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
+ | <td></td> | ||
+ | <td align="center"><span class="math">\dfrac{a}{b}</span></td> | ||
+ | <td align="center"><tt>\dfrac{a}{b}</tt></td> | ||
+ | <td align="left">Large fraction</td> | ||
+ | </tr> | ||
+ | <tr> | ||
<td></td> | <td></td> | ||
<td align="center"><span class="math">(a)</span></td> | <td align="center"><span class="math">(a)</span></td> | ||
<td align="center"><tt>(a)</tt></td> | <td align="center"><tt>(a)</tt></td> | ||
- | <td align="left">Scalable parantheses \left(...\right)</td> | + | <td align="left">Scalable parantheses: <tt>\left(...\right)</tt></td> |
</tr> | </tr> | ||
- | <tr> | + | <tr style="background:#E6E6E6;"> |
<td align="left">Relation signs</td> | <td align="left">Relation signs</td> | ||
<td align="center"><span class="math">a=b</span></td> | <td align="center"><span class="math">a=b</span></td> | ||
Line 104: | Line 110: | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
- | <tr | + | <tr> |
<td></td> | <td></td> | ||
<td align="center"><span class="math">a\ne b</span></td> | <td align="center"><span class="math">a\ne b</span></td> | ||
Line 110: | Line 116: | ||
<td>Alternatively: a\not= b</td> | <td>Alternatively: a\not= b</td> | ||
</tr> | </tr> | ||
- | <tr> | + | <tr style="background:#E6E6E6;"> |
<td></td> | <td></td> | ||
<td align="center"><span class="math">a< b</span></td> | <td align="center"><span class="math">a< b</span></td> | ||
Line 116: | Line 122: | ||
<td>NB: Space after "<" </td> | <td>NB: Space after "<" </td> | ||
</tr> | </tr> | ||
- | <tr | + | <tr> |
<td></td> | <td></td> | ||
<td align="center"><span class="math">a\le b</span></td> | <td align="center"><span class="math">a\le b</span></td> | ||
Line 122: | Line 128: | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
- | <tr> | + | <tr style="background:#E6E6E6;"> |
<td></td> | <td></td> | ||
<td align="center"><span class="math">a> b</span></td> | <td align="center"><span class="math">a> b</span></td> | ||
Line 128: | Line 134: | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
- | <tr | + | <tr> |
<td></td> | <td></td> | ||
<td align="center"><span class="math">a\ge b</span></td> | <td align="center"><span class="math">a\ge b</span></td> | ||
Line 134: | Line 140: | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
- | <tr> | + | <tr style="background:#E6E6E6;"> |
<td>Powers and roots</td> | <td>Powers and roots</td> | ||
<td align="center"><span class="math">x^{n}</span></td> | <td align="center"><span class="math">x^{n}</span></td> | ||
Line 140: | Line 146: | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
- | <tr | + | <tr> |
<td></td> | <td></td> | ||
<td align="center"><span class="math">\sqrt{x}</span></td> | <td align="center"><span class="math">\sqrt{x}</span></td> | ||
Line 146: | Line 152: | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
- | <tr> | + | <tr style="background:#E6E6E6;"> |
<td></td> | <td></td> | ||
<td align="center"><span class="math">\sqrt[n]{x}</span></td> | <td align="center"><span class="math">\sqrt[n]{x}</span></td> | ||
Line 152: | Line 158: | ||
<td>Write \sqrt[\scriptstyle n]{x} for bigger n</td> | <td>Write \sqrt[\scriptstyle n]{x} for bigger n</td> | ||
</tr> | </tr> | ||
- | <tr | + | <tr> |
<td>Index</td> | <td>Index</td> | ||
<td align="center"><span class="math">x_n</span></td> | <td align="center"><span class="math">x_n</span></td> | ||
Line 158: | Line 164: | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
- | <tr> | + | <tr style="background:#E6E6E6;"> |
<td>Logarithms</td> | <td>Logarithms</td> | ||
+ | <td align="center"><span class="math">\lg x</span></td> | ||
+ | <td align="center"><tt>\lg x</tt></td> | ||
+ | <td></td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td></td> | ||
<td align="center"><span class="math">\ln x</span></td> | <td align="center"><span class="math">\ln x</span></td> | ||
<td align="center"><tt>\ln x</tt></td> | <td align="center"><tt>\ln x</tt></td> | ||
Line 210: | Line 222: | ||
<td align="center"><span class="math">\Rightarrow</span></td> | <td align="center"><span class="math">\Rightarrow</span></td> | ||
<td align="center"><tt>\Rightarrow</tt></td> | <td align="center"><tt>\Rightarrow</tt></td> | ||
- | <td></td> | + | <td align="left">Implies</td> |
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
Line 216: | Line 228: | ||
<td align="center"><span class="math">\Leftarrow</span></td> | <td align="center"><span class="math">\Leftarrow</span></td> | ||
<td align="center"><tt>\Leftarrow</tt></td> | <td align="center"><tt>\Leftarrow</tt></td> | ||
- | <td></td> | + | <td align="left">Is implied by</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
Line 222: | Line 234: | ||
<td align="center"><span class="math">\Leftrightarrow</span></td> | <td align="center"><span class="math">\Leftrightarrow</span></td> | ||
<td align="center"><tt>\Leftrightarrow</tt></td> | <td align="center"><tt>\Leftrightarrow</tt></td> | ||
- | <td></td> | + | <td align="left">Is equivalent to</td> |
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
Line 228: | Line 240: | ||
<td align="center"><span class="math">\pi</span></td> | <td align="center"><span class="math">\pi</span></td> | ||
<td align="center"><tt>\pi</tt></td> | <td align="center"><tt>\pi</tt></td> | ||
+ | <td></td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td></td> | ||
+ | <td align="center"><span class="math">\alpha, \beta, \theta, \varphi</span></td> | ||
+ | <td colspan="2" align="left"><tt>\alpha, \beta, \theta, \varphi</tt></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
Line 240: | Line 258: | ||
<li><math>\tfrac{1}{2}y\ne x\le z\quad</math> is written <tt><nowiki><math></nowiki>\frac{1}{2}y\ne x\le z<nowiki></math></nowiki></tt></li> | <li><math>\tfrac{1}{2}y\ne x\le z\quad</math> is written <tt><nowiki><math></nowiki>\frac{1}{2}y\ne x\le z<nowiki></math></nowiki></tt></li> | ||
<li><math>2^{13}\sqrt{3}+\ln y\quad</math> is written <tt><nowiki><math></nowiki>2^{13}\sqrt{3}+\ln y<nowiki></math></nowiki></tt></li> | <li><math>2^{13}\sqrt{3}+\ln y\quad</math> is written <tt><nowiki><math></nowiki>2^{13}\sqrt{3}+\ln y<nowiki></math></nowiki></tt></li> | ||
- | <li><math>\tan 30^{\circ} | + | <li><math>\tan 30^{\circ}\quad</math> is written <tt><nowiki><math></nowiki>\tan 30^{\circ}<nowiki></math></nowiki></tt></li> |
</ol> | </ol> | ||
</div> | </div> | ||
Line 255: | Line 273: | ||
<li><math>\sqrt{x+2}\quad</math> is written <tt><nowiki><math></nowiki>\sqrt{x+2}<nowiki></math></nowiki></tt></li> | <li><math>\sqrt{x+2}\quad</math> is written <tt><nowiki><math></nowiki>\sqrt{x+2}<nowiki></math></nowiki></tt></li> | ||
<li><math>(a^2)^3=a^6\quad</math> is written <tt><nowiki><math></nowiki>(a^2)^3=a^6<nowiki></math></nowiki></tt></li> | <li><math>(a^2)^3=a^6\quad</math> is written <tt><nowiki><math></nowiki>(a^2)^3=a^6<nowiki></math></nowiki></tt></li> | ||
- | <li><math>2^{2^2}\quad</math> is written <tt><nowiki><math></nowiki>2^{2^2}<nowiki></math></nowiki></tt></li> | + | <li><math>2^{(2^2)}\quad</math> is written <tt><nowiki><math></nowiki>2^{(2^2)}<nowiki></math></nowiki></tt></li> |
<li><math>\sin\sqrt{x}\quad</math> is written <tt><nowiki><math></nowiki>\sin\sqrt{x}<nowiki></math></nowiki></tt></li> | <li><math>\sin\sqrt{x}\quad</math> is written <tt><nowiki><math></nowiki>\sin\sqrt{x}<nowiki></math></nowiki></tt></li> | ||
</ol> | </ol> |
Revision as of 07:24, 13 March 2009
Theory | Exercises |
Contents:
- LaTeX maths
Learning outcomes:
After this section you will have learned how to:
- Write simple maths formulas in LaTeX.
- Avoid common mistakes when coding maths in LaTeX.
To write mathematics efficiently on a computer in your individual assignment and the group task you will need to write the maths in a coded form called LaTeX syntax. In this section you will learn the fundamentals of constructing LaTeX code that yields simple maths formulas.
How to write basic expressions
To indicate the start of math formatting, use the tag <math>. To end math formatting, use the tag </math>. For example, if you want the formula \displaystyle a+b, in the text box write <math>a+b</math>.
Simple mathematical formulas are written in a straight-forward manner.
Example 1
- \displaystyle 1+2-3\quad is written <math>1+2-3</math>
- \displaystyle 5/2\quad is written <math>5/2</math>
- \displaystyle 4/(2+x)\quad is written <math>4/(2+x)</math>
- \displaystyle 4 < 5\quad is written <math>4 < 5</math>
When you need to use symbols that are not available on the keyboard or construct formulas that are not simple you use special commands that start with a backslash, e.g. \le is a command that gives you \displaystyle \le.
The table below shows some of the most commonly used maths commands in LaTeX.
Example | LaTeX-code | Comment | ||
Simple operations | a+b | a+b | ||
a-b | a-b | |||
a\pm b | a\pm b | |||
a\times b | a\times b | |||
a/b | a/b | |||
\frac{1}{2} | \frac{1}{2} | Small fraction | ||
\dfrac{a}{b} | \dfrac{a}{b} | Large fraction | ||
(a) | (a) | Scalable parantheses: \left(...\right) | ||
Relation signs | a=b | a=b | ||
a\ne b | a\ne b | Alternatively: a\not= b | ||
a< b | a< b | NB: Space after "<" | ||
a\le b | a\le b | |||
a> b | a>b | |||
a\ge b | a\ge b | |||
Powers and roots | x^{n} | x^{n} | ||
\sqrt{x} | \sqrt{x} | |||
\sqrt[n]{x} | \sqrt[n]{x} | Write \sqrt[\scriptstyle n]{x} for bigger n | ||
Index | x_n | x_{n} | ||
Logarithms | \lg x | \lg x | ||
\ln x | \ln x | |||
\log x | \log x | |||
\log_{a} x | \log_{a} x | |||
Trigonometry | 30^{\circ} | 30^{\circ} | ||
\cos x | \cos x | |||
\sin x | \sin x | |||
\tan x | \tan x | |||
\cot x | \cot x | |||
Arrows | \Rightarrow | \Rightarrow | Implies | |
\Leftarrow | \Leftarrow | Is implied by | ||
\Leftrightarrow | \Leftrightarrow | Is equivalent to | ||
Various symbols | \pi | \pi | ||
\alpha, \beta, \theta, \varphi | \alpha, \beta, \theta, \varphi |
Example 2
- \displaystyle 1\pm3\times 5\quad is written <math>1\pm 3\times 5</math>
- \displaystyle \tfrac{1}{2}y\ne x\le z\quad is written <math>\frac{1}{2}y\ne x\le z</math>
- \displaystyle 2^{13}\sqrt{3}+\ln y\quad is written <math>2^{13}\sqrt{3}+\ln y</math>
- \displaystyle \tan 30^{\circ}\quad is written <math>\tan 30^{\circ}</math>
How to write complex expressions
By combining simple expressions, we may form more complex expressions.
Example 3
- \displaystyle \sqrt{x+2}\quad is written <math>\sqrt{x+2}</math>
- \displaystyle (a^2)^3=a^6\quad is written <math>(a^2)^3=a^6</math>
- \displaystyle 2^{(2^2)}\quad is written <math>2^{(2^2)}</math>
- \displaystyle \sin\sqrt{x}\quad is written <math>\sin\sqrt{x}</math>
Example 4
- \displaystyle \sqrt{x+\sqrt{x}}\quad is written <math>\sqrt{x+\sqrt{x}}</math>
- \displaystyle \dfrac{x-x^2}{\sqrt{3}}\quad is written <math>\dfrac{x-x^2}{\sqrt{3}}</math>
- \displaystyle \dfrac{x}{x+\dfrac{1}{x}}\quad is written <math>\dfrac{x}{x+\dfrac{1}{x}}</math>
- \displaystyle x_{1,2}=-\dfrac{p}{2}\pm\sqrt{\left(\dfrac{p}{2}\right)^2-q}\quad is written <math>x_{1,2}=-\dfrac{p}{2}\pm\sqrt{\left(\dfrac{p}{2}\right)^2-q}</math>
How to avoid common mistakes
One of the most common mistakes when editing math in the wiki is to forget the start <math> tag and the end </math> tag.
Remember also to start commands with a backslash (\) and to add a space after the commands (unless they are followed immediately by a new command).
Another frequent mistake is to use an asterisk (*) instead of a proper multiplication sign \displaystyle \times (\times in TeX).
Example 5
LaTeX | Result | |
| sin x | \displaystyle sin x |
| \sinx | Error |
| \sin x | \displaystyle \sin x |
| 4*3 | \displaystyle 4*3 |
| 4\times 3 | \displaystyle 4\times 3 |
| a\times b | \displaystyle a\times b |
| ab | \displaystyle ab |
Exponents and indices
When writing exponents you use ^ followed by the exponent and to write indices you use _ followed by the index. If the exponent or index consists of more than one symbol it must be enclosed with braces {}.
A special kind of exponent is the degree sign (°) which is written as ^{\circ}.
Example 6
LaTeX | Result | |
| a2 | \displaystyle a2 |
| a^2 | \displaystyle a^2 |
| x1 | \displaystyle x1 |
| x_1 | \displaystyle x_1 |
| a^22 | \displaystyle a^22 |
| a^{22} | \displaystyle a^{22} |
| 30^{o} | \displaystyle 30^{o} |
| 30^{0} | \displaystyle 30^{0} |
| 30^{\circ} | \displaystyle 30^{\circ} |
Delimiters
In more complex expressions you need to make sure to balance each opening parenthesis ( with a closing parenthesis ).
A pair of parenthesis that delimits a tall expression should be as large as the expression. You should therefore prefix the opening parenthesis with \left and the closing parenthesis with \right to get a pair of extensible parentheses that adjust its height to the expression.
Note also that braces {} and not parentheses () are used in commands to delimits arguments.
Example 7
LaTeX | Result | |
| (1-(1-x) | \displaystyle (1-(1-x) |
| (1-(1-x)) | \displaystyle (1-(1-x)) |
| (\dfrac{a}{b}+c) | \displaystyle (\dfrac{a}{b}+c) |
| \left(\dfrac{a}{b}+c\right) | \displaystyle \left(\dfrac{a}{b}+c\right) |
| \frac(1)(2) | \displaystyle \tfrac(1)(2) |
| \frac{1}{2} | \displaystyle \tfrac{1}{2} |
| \sqrt(a+b) | \displaystyle \sqrt(a+b) |
| \sqrt{(a+b)} | \displaystyle \sqrt{(a+b)} |
| \sqrt{a+b} | \displaystyle \sqrt{a+b} |
Fractions
As a rule of thumb you should write fractions where the numerator and denominator consist only of a few digits as a small fraction (i.e. with \frac), while other fractions should be large (i.e. with \dfrac).
If an exponent or index contains a fraction then that fraction should be written in a slashed form (e.g. \displaystyle 5/2 instead of \displaystyle \tfrac{5}{2}) to enhance the legibility.
Example 8
LaTeX | Result | |
| \dfrac{1}{2} | \displaystyle \dfrac{1}{2} |
| \frac{1}{2} | \displaystyle \tfrac{1}{2} |
| ||
| \frac{a}{b} | \displaystyle \tfrac{a}{b} |
| \dfrac{a}{b} | \displaystyle \dfrac{a}{b} |
| \frac{\sqrt{3}}{2} | \displaystyle \tfrac{\sqrt{3}}{2} |
| \dfrac{\sqrt{3}}{2} | \displaystyle \dfrac{\sqrt{3}}{2} |
| a^{\frac{1}{2}} | \displaystyle a^{\frac{1}{2}} |
| a^{1/2} | \displaystyle a^{1/2} |
Study advice
A tip is to try out your maths formulas in the forum or in the wiki where you work on your individual assignment.
Useful web sites
- A more thorough list of LaTeX maths commands can be found on Wikipedias help page
- Two more thorough texts om LaTeX maths can be found in a chapter of the book The LaTeX Companion and a text by Herbert Voss.
- If you want to know more about LaTeX you can visit these sites: Wikipedia, The not so Short Introduction to LaTeX and LaTeX Wikibook.
- The actual implementation of LaTeX math that is used in the wiki is jsMath.