5.1 Writing formulas in TeX
From Förberedande kurs i matematik 1
Line 30: | Line 30: | ||
To indicate the '''start''' of math formatting, use the tag <b><tt><math></tt></b>. To '''end''' math formatting, use the tag <b><tt></math></tt></b>. For example, if you want the formula <math>a+b</math>, in the text box write <tt><math>a+b</math></tt>. | To indicate the '''start''' of math formatting, use the tag <b><tt><math></tt></b>. To '''end''' math formatting, use the tag <b><tt></math></tt></b>. For example, if you want the formula <math>a+b</math>, in the text box write <tt><math>a+b</math></tt>. | ||
- | <table cellpadding="6" cellspacing="0" class="normalText" width="70%" | + | <table cellpadding="6" cellspacing="0" class="normalText" width="70%" |
align="center"> | align="center"> | ||
+ | <colgroup> | ||
+ | <col width="25%"> | ||
+ | <col width="15%"> | ||
+ | <col width="20%"> | ||
+ | <col width="40%"> | ||
+ | </colgroup> | ||
<tr> | <tr> | ||
<td></td> | <td></td> | ||
<td align="center"><b>Example</b></td> | <td align="center"><b>Example</b></td> | ||
<td align="center"><b>LaTeX-code</b></td> | <td align="center"><b>LaTeX-code</b></td> | ||
- | <td align="center"><b>Button</b></td> | ||
<td align="left"><b>Comment</b></td> | <td align="left"><b>Comment</b></td> | ||
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
<td align="left">Simple operations</td> | <td align="left">Simple operations</td> | ||
- | |||
<td align="center"><span class="math">a+b</span></td> | <td align="center"><span class="math">a+b</span></td> | ||
<td align="center"><tt>a+b</tt></td> | <td align="center"><tt>a+b</tt></td> | ||
- | <td></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
Line 50: | Line 53: | ||
<td></td> | <td></td> | ||
<td align="center"><span class="math">a-b</span></td> | <td align="center"><span class="math">a-b</span></td> | ||
- | |||
<td align="center"><tt>a-b</tt></td> | <td align="center"><tt>a-b</tt></td> | ||
- | <td></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
Line 59: | Line 60: | ||
<td align="center"><span class="math">a\pm b</span></td> | <td align="center"><span class="math">a\pm b</span></td> | ||
<td align="center"><tt>a\pm b</tt></td> | <td align="center"><tt>a\pm b</tt></td> | ||
- | <td align=center><img src="../images/buttons/pm.gif" /></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
Line 66: | Line 66: | ||
<td align="center"><span class="math">a\cdot b</span></td> | <td align="center"><span class="math">a\cdot b</span></td> | ||
<td align="center"><tt>a\cdot b</tt></td> | <td align="center"><tt>a\cdot b</tt></td> | ||
- | + | <td></td> | |
</tr> | </tr> | ||
- | |||
<tr style="background:#E6E6E6;"> | <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> | ||
<td align="center"><tt>a/b</tt></td> | <td align="center"><tt>a/b</tt></td> | ||
- | <td></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td></td> | <td></td> | ||
- | |||
<td align="center"><span class="math">\frac{a}{b}</span></td> | <td align="center"><span class="math">\frac{a}{b}</span></td> | ||
<td align="center"><tt>\frac{a}{b}</tt></td> | <td align="center"><tt>\frac{a}{b}</tt></td> | ||
- | <td align=center><img src="../images/buttons/frac.gif" /></td> | ||
<td align="left">Use \displaystyle\frac{a}{b} for a larger sized fraction</td> | <td align="left">Use \displaystyle\frac{a}{b} for a larger sized fraction</td> | ||
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
<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></td> | ||
<td align="left">Scalable parantheses \left(...\right)</td> | <td align="left">Scalable parantheses \left(...\right)</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<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> | ||
<td align="center"><tt>a=b</tt></td> | <td align="center"><tt>a=b</tt></td> | ||
- | + | <td></td> | |
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
<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> | ||
- | |||
<td align="center"><tt>a\ne b</tt></td> | <td align="center"><tt>a\ne b</tt></td> | ||
- | + | <td>Alternatively: a\not= b</tt></td> | |
- | <td>Alternatively: a\not= b</td> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td></td> | <td></td> | ||
<td align="center"><span class="math">a< b</span></td> | <td align="center"><span class="math">a< b</span></td> | ||
- | |||
<td align="center"><tt>a< b</tt></td> | <td align="center"><tt>a< b</tt></td> | ||
- | + | <td>NB: Space after "<" </td> | |
- | <td>NB: Space after " | + | |
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
<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> | ||
- | |||
<td align="center"><tt>a\le b</tt></td> | <td align="center"><tt>a\le b</tt></td> | ||
- | + | <td></td> | |
</tr> | </tr> | ||
<tr> | <tr> | ||
Line 126: | Line 114: | ||
<td align="center"><span class="math">a> b</span></td> | <td align="center"><span class="math">a> b</span></td> | ||
<td align="center"><tt>a>b</tt></td> | <td align="center"><tt>a>b</tt></td> | ||
- | <td></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
Line 133: | Line 120: | ||
<td align="center"><span class="math">a\ge b</span></td> | <td align="center"><span class="math">a\ge b</span></td> | ||
<td align="center"><tt>a\ge b</tt></td> | <td align="center"><tt>a\ge b</tt></td> | ||
- | <td align=center><img src="../images/buttons/ge.gif" /></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
- | |||
<tr> | <tr> | ||
<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> | ||
<td align="center"><tt>x^{n}</tt></td> | <td align="center"><tt>x^{n}</tt></td> | ||
- | <td align=center><img src="../images/buttons/pow.gif" /></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
- | |||
<td></td> | <td></td> | ||
<td align="center"><span class="math">\sqrt{x}</span></td> | <td align="center"><span class="math">\sqrt{x}</span></td> | ||
<td align="center"><tt>\sqrt{x}</tt></td> | <td align="center"><tt>\sqrt{x}</tt></td> | ||
- | + | <td></td> | |
</tr> | </tr> | ||
<tr> | <tr> | ||
<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> | ||
- | |||
<td align="center"><tt>\sqrt[n]{x}</tt></td> | <td align="center"><tt>\sqrt[n]{x}</tt></td> | ||
- | <td align=center><img src="../images/buttons/sqrtn.gif" /></td> | ||
<td>Write \sqrt[\scriptstyle n]{x} for bigger n</td> | <td>Write \sqrt[\scriptstyle n]{x} for bigger n</td> | ||
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
<td>Logarithms</td> | <td>Logarithms</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> | ||
- | + | <td></td> | |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td></td> | <td></td> | ||
<td align="center"><span class="math">\log x</span></td> | <td align="center"><span class="math">\log x</span></td> | ||
- | |||
<td align="center"><tt>\log x</tt></td> | <td align="center"><tt>\log x</tt></td> | ||
- | + | <td></td> | |
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
Line 177: | Line 156: | ||
<td align="center"><span class="math">\log_{a} x</span></td> | <td align="center"><span class="math">\log_{a} x</span></td> | ||
<td align="center"><tt>\log_{a} x</tt></td> | <td align="center"><tt>\log_{a} x</tt></td> | ||
- | <td align=center><img src="../images/buttons/logn.gif" /></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
Line 184: | Line 162: | ||
<td align="center"><span class="math">30^{\circ}</span></td> | <td align="center"><span class="math">30^{\circ}</span></td> | ||
<td align="center"><tt>30^{\circ}</tt></td> | <td align="center"><tt>30^{\circ}</tt></td> | ||
- | + | <td></td> | |
- | <td></td> | + | |
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
Line 191: | Line 168: | ||
<td align="center"><span class="math">\cos x</span></td> | <td align="center"><span class="math">\cos x</span></td> | ||
<td align="center"><tt>\cos x</tt></td> | <td align="center"><tt>\cos x</tt></td> | ||
- | <td align=center><img src="../images/buttons/cos.gif" /></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
- | |||
<td></td> | <td></td> | ||
<td align="center"><span class="math">\sin x</span></td> | <td align="center"><span class="math">\sin x</span></td> | ||
<td align="center"><tt>\sin x</tt></td> | <td align="center"><tt>\sin x</tt></td> | ||
- | <td align=center><img src="../images/buttons/sin.gif" /></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
Line 205: | Line 179: | ||
<td></td> | <td></td> | ||
<td align="center"><span class="math">\tan x</span></td> | <td align="center"><span class="math">\tan x</span></td> | ||
- | |||
<td align="center"><tt>\tan x</tt></td> | <td align="center"><tt>\tan x</tt></td> | ||
- | <td align=center><img src="../images/buttons/tan.gif" /></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
Line 214: | Line 186: | ||
<td align="center"><span class="math">\cot x</span></td> | <td align="center"><span class="math">\cot x</span></td> | ||
<td align="center"><tt>\cot x</tt></td> | <td align="center"><tt>\cot x</tt></td> | ||
- | <td align=center><img src="../images/buttons/cot.gif" /></td> | ||
<td></td> | <td></td> | ||
</tr> | </tr> | ||
<tr style="background:#E6E6E6;"> | <tr style="background:#E6E6E6;"> | ||
- | <td>Various | + | <td>Various symbolsr</td> |
<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> | |
- | <td></td> | + | |
</tr> | </tr> | ||
</table> | </table> |
Revision as of 13:34, 27 January 2009
Theory | Exercises |
Contents:
- What is TeX/LaTeX?
- Common expressions
- Common mistakes
Learning outcomes:
After this section you will have learned how to:
- Write formulas in TeX
What is TeX/LaTeX?
Common expressions
To write mathematics efficiently on a computer, one uses some sort of coding. We have chosen to use jsMath's LaTeX-code. Below are some basic examples of useful code snippets. For more examples, see for example Wikipedia's help page.
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>.
Example | LaTeX-code | Comment | |
Simple operations | a+b | a+b | |
a-b | a-b | ||
a\pm b | a\pm b | ||
a\cdot b | a\cdot b | ||
a/b | a/b | ||
\frac{a}{b} | \frac{a}{b} | Use \displaystyle\frac{a}{b} for a larger sized fraction | |
(a) | (a) | Scalable parantheses \left(...\right) | |
Relation signs | a=b | a=b | |
a\ne b | a\ne b | Alternatively: a\not= b</tt> |
Example | Latex-code |
ax^2+bx+c | ax^2+bx+c |
(a^2)^3=a^6 | (a^2)^3=a^6 |
\sqrt{x+2} | \sqrt{x+2} |
\sqrt{x+\sqrt{x}} | \sqrt{x+\sqrt{x}} |
\displaystyle\frac{a+b}{c-d} | \displaystyle\frac{a+b}{c-d} |
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
TeX | 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
TeX | 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
TeX | 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 \tfrac), while other fractions should be large (i.e. with \frac).
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
TeX | 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
Useful web sites
- A video course in mathematical writing by Donald Knuth (A compendium accompaning the course is avalable in source form or in excerpts from Google books).
