Processing Math: Done
To print higher-resolution math symbols, click the
Hi-Res Fonts for Printing button on the jsMath control panel.

jsMath

5.1 Writing formulas in TeX

From Förberedande kurs i matematik 1

(Difference between revisions)
Jump to: navigation, search
Line 444: Line 444:
* [http://www.maths.abdn.ac.uk/tex/latex_course/intro.htm How to write and use LaTeX ]
* [http://www.maths.abdn.ac.uk/tex/latex_course/intro.htm How to write and use LaTeX ]
-
* [http://www.latex-project.org/ LaTeX - project]
+
* '''[http://www.latex-project.org/ LaTeX - project]'''
* For the ambitious [http://theoval.sys.uea.ac.uk/~nlct/latex/thesis/ Using LaTeX to Write a PhD Thesis]
* For the ambitious [http://theoval.sys.uea.ac.uk/~nlct/latex/thesis/ Using LaTeX to Write a PhD Thesis]
</div>
</div>

Revision as of 14:45, 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 a+b, in the text box write <math>a+b</math>.


Example LaTeX-code Comment
Simple operations a+b a+b
ab a-b
ab a\pm b
ab a\cdot b
ab a/b
ba \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=b a\ne b Alternatively: a\not= b
ab a< b NB: Space after "<"
ab a\le b
ab a>b
ab a\ge b
Powers and roots xn x^{n}
x  \sqrt{x}
nx  \sqrt[n]{x} Write \sqrt[\scriptstyle n]{x} for bigger n
Logarithms lnx \ln x
logx \log x
logax \log_{a} x
Trigonometry 30 30^{\circ}
cosx \cos x
sinx \sin x
tanx \tan x
cotx \cot x
Various symbolsr \pi


By combining these simple expressions, we may form more complex expressions. The table below shows some examples.


Example Latex-code
ax2+bx+c ax^2+bx+c
(a2)3=a6 (a^2)^3=a^6
x+2  \sqrt{x+2}
x+x  \sqrt{x+\sqrt{x}}
cda+b \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 (\times in TeX).

Example

TeX Result
  1. Don't write
sin x sinx
  1. Don't write
\sinx Error
  1. Do write
\sin x sinx
  1. Don't write
4*3 43
  1. Do write
4\times 3 43
  1. Don't write
a\times b ab
  1. Do write
ab 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
  1. Don't write
a2 a2
  1. Do write
a^2 a2
  1. Don't write
x1 x1
  1. Do write
x_1 x1
  1. Don't write
a^22 a22
  1. Do write
a^{22} a22
  1. Don't write
30^{o} 30o
  1. Don't write
30^{0} 300
  1. Do write
30^{\circ} 30

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. Don't write
(1-(1-x) (1(1x)
  1. Do write
(1-(1-x)) (1(1x))
  1. Don't write
(\dfrac{a}{b}+c) (ba+c)
  1. Do write
\left(\dfrac{a}{b}+c\right) ba+c 
  1. Don't write
\frac(1)(2) (1)(2)
  1. Do write
\frac{1}{2} 21
  1. Don't write
\sqrt(a+b) (a+b) 
  1. Don't write
\sqrt{(a+b)} (a+b) 
  1. Do write
\sqrt{a+b} 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. 52 instead of 25) to enhance the legibility.

Example

TeX Result
  1. Don't write
\dfrac{1}{2} 21
  1. Do write
\frac{1}{2} 21
  1. (Exception: If the fraction is next to a large expression you should, however, write the fraction as a large fraction.)
  1. Don't write
\frac{a}{b} ba
  1. Do write
\dfrac{a}{b} ba
  1. Don't write
\frac{\sqrt{3}}{2} 23 
  1. Do write
\dfrac{\sqrt{3}}{2} 23 
  1. Don't write
a^{\frac{1}{2}} a21
  1. Do write
a^{1/2} a12