# Difference between revisions of "Using TeX Notation"

TeX (pronounced TEK) is a very widespread and popular way of representing Mathematics notation using only characters that you can type on a keyboard (see Wikipedia). This makes it a useful format to use in Moodle, since it can be entered anywhere you can type text, from forum posts to quiz questions.

TeX expressions can be entered in multiple ways:

• typing them directly into texts.
• using the Java-based Dragmath editor in Moodle's TinyMCE editor.
• using the HTML-based equation editor in Moodle's Atto editor (since Moodle 2.7).

Afterwards, TeX expressions are rendered into Mathematics notation:

• using the TeX filter in Moodle, which uses a TeX binary installed on the server to convert expressions into .gif images (or if that is not available, it falls back to a simple built-in mimetex binary).
• using the MimeTex filter which identifies TeX expressions and uses the MimeTex JS library to render them in browsers at display time (since Moodle 2.7).
• using other third-party solutions.

As you can imagine, the whole field is not simple as we'd like, especially because there are many flavours of TeX and slight variations between tools.

## Using TeX Notation with the Moodle Tex filter

For the most part, the TeX Notation has been built using a sub-set of characters from the TeX "default" character set. The trouble is there does not seem to be a "default" character set for TeX. This is one of the most confusing aspects of using TeX Notation in Moodle. When we realise that the documentation we are using is related to the creation of printed documents, and we want to use TeX on line, in Moodle, then further problems occur. There are no environment statements to be made. There are few \begins and \ends. If you go to Administration > Modules > Filters > Filter Manager you will see what filters have been enabled. If you then go to the TeX Notation page, the default preamble is editable via the text box. Using this tool you can add in or subtract font packages and other packages, change the default font package, etc.

## Superscripts, Subscripts and Roots

Superscripts are recorded using the caret, ^, symbol. An example for a Maths class might be:

 $$4^2 \ \times \ 4^3 \ = 4^5$$
This is a shorthand way of saying:
(4 x 4) x (4 x 4 x 4) = (4 x 4 x 4 x 4 x 4)
or
16 x 64 = 1024.

${\displaystyle 4^{2}\ \times \ 4^{3}\ =4^{5}}$


Subscripts are similar, but use the underscore character.

 $$3x_2 \ \times \ 2x_3$$

${\displaystyle 3x_{2}\ \times \ 2x_{3}}$


This is OK if you want superscripts or subscripts, but square roots are a little different. This uses a control sequence.

 $$\sqrt{64} \ = \ 8$$

${\displaystyle {\sqrt {64}}\ =\ 8}$


You can also take this a little further, but adding in a control character. You may ask a question like:

 $$If \ \sqrt[n]{1024} \ = \ 4, \ what \ is \ the \ value \ of \ n?$$

${\displaystyle If\ {\sqrt[{n}]{1024}}\ =\ 4,\ what\ is\ the\ value\ of\ n?}$


Using these different commands allows you to develop equations like:

 $$The \sqrt{64} \ \times \ 2 \ \times \ 4^3 \ = \ 1024$$

${\displaystyle The{\sqrt {64}}\ \times \ 2\ \times \ 4^{3}\ =\ 1024}$


Superscripts, Subscripts and roots can also be noted in Matrices.

## Fractions

Fractions in TeX are actually simple, as long as you remember the rules.

 $$\frac{numerator}{denominator}$$ which produces ${\displaystyle {\frac {numerator}{denominator}}}$ .


This can be given as:

 ${\displaystyle {\frac {5}{10}}\ is\ equal\ to\ {\frac {1}{2}}}$.


This is entered as:

 $$\frac{5}{10} \ is \ equal \ to \ \frac{1}{2}.$$


With fractions (as with other commands) the curly brackets can be nested so that for example you can implement negative exponents in fractions. As you can see,

 $$\frac {5^{-2}}{3}$$ will produce ${\displaystyle {\frac {5^{-2}}{3}}}$

 $$\left(\frac{3}{4}\right)^{-3}$$ will produce ${\displaystyle \left({\frac {3}{4}}\right)^{-3}}$  and

 $$\frac{3}{4^{-3}}$$ will produce ${\displaystyle {\frac {3}{4^{-3}}}}$

 You likely do not want to use $$\frac{3}{4}^{-3}$$ as it produces ${\displaystyle {\frac {3}{4}}^{-3}}$


You can also use fractions and negative exponents in Matrices.

## Brackets

As students advance through Maths, they come into contact with brackets. Algebraic notation depends heavily on brackets. The usual keyboard values of ( and ) are useful, for example:

  ${\displaystyle d=2\ \times \ (4\ -\ j)}$


This is written as:

 $$d = 2 \ \times \ (4 \ - \ j)$$


Usually, these brackets are enough for most formulae but they will not be in some circumstances. Consider this:

 ${\displaystyle 4x^{3}\ +\ (x\ +\ {\frac {42}{1+x^{4}}})}$


Is OK, but try it this way:

 ${\displaystyle 4x^{3}\ +\ \left(x\ +\ {\frac {42}{1+x^{4}}}\right)}$


This can be achieved by:

 $$4x^3 \ + \ \left(x \ + \ \frac{42}{1 + x^4}\right)$$


A simple change using the \left( and \right) symbols instead. Note the actual bracket is both named and presented. Brackets are almost essential in Matrices.

## Ellipsis

The Ellipsis is a simple code:

 ${\displaystyle x_{1},\ x_{2},\ \ldots ,\ x_{n}}$


Written like:

 $$x_1, \ x_2, \ \ldots, \ x_n$$


A more practical application could be:

Question:

 "Add together all the numbers from 1 ${\displaystyle \ldots }$ 38.
What is an elegant and simple solution to this problem?
Can you create an algebraic function to explain this solution?
Will your solution work for all numbers?"


Answer: The question uses an even number to demonstrate a mathematical process and generate an algebraic formula.

 Part 1: Part 2. Part 3. ${\displaystyle 1.\ 1\ +\ 38\ =\ 39}$ ${\displaystyle 2.\ 2\ +\ 37\ =\ 39}$ ${\displaystyle 3.\ 3\ +\ 36\ =\ 39}$ ${\displaystyle \ldots }$ ${\displaystyle 19.19\ +\ 20\ =\ 39}$ ${\displaystyle \therefore x\ =\ 39\ \times \ 19}$ ${\displaystyle \therefore x\ =\ 741}$ An algebraic function might read something like: ${\displaystyle t=(1+n)\times n/2}$ Where t = total and n = the last number. The solution is that, using the largest and the smallest numbers, the numbers are added and then multiplied by the number of different combinations to produce the same result adding the first and last numbers. The answer must depend on the number, ${\displaystyle {\frac {n}{2}}}$ being a whole number. Therefore, the solution will not work for an odd range of numbers, only an even range.