Материал готовится,

пожалуйста, возвращайтесь позднее

пожалуйста, возвращайтесь позднее

Getting to Grips with LaTeX

Mathematics - Part 2

by Andrew Roberts

This tutorial builds on the basic foundations presented in the previous tutorial. If you often include a lot of maths in your documents, then you will probably find that you wish to have slightly more control over presentation issues. Some of the topics covered make writing equations more complex - but who said typesetting mathematics was easy?!

Adding text to equations

I doubt it will be every day that you will need to include some text within an equation. However, sometimes it needs to be done. Just sticking the text straight in the maths environment won't give you the results you want. For example:

\begin{equation}

50 apples \times 100 apples = lots of apples

\end{equation}

There are two noticeable problems. Firstly, there are no spaces between numbers and text, nor spaces between multiple words. Secondly, the words don't look quite right — - the letters are more spaced out than normal. Both issues are simply artifacts of the maths mode, in that it doesn't expect to see words. Any spaces that you type in maths mode are ignored and LaTeX spaces elements according to its own rules. It is assumed that any characters represent variable names. To emphasise that each symbol is an individual, they are not positioned as closely together as with normal text.

There are a number of ways that text can be added properly. The typical way is to wrap the text with the \mbox{...} command. This command hasn't been introduced before, however, it's job is basically to create a text box just width enough to contain the supplied text. Text within this box cannot be broken across lines. Let's see what happens when the above equation code is adapted:

The text looks better. However, there are no gaps between the numbers and the words. Unfortunately, you are required to explicitly add these. There are many ways to add spaces between maths elements, however, for the sake of simplicity, I find it easier, in this instance at least, just to literally add the space character in the affected \mbox(s) itself (just before the text.)

\begin{equation}

50 \mbox{ apples} \times 100 \mbox{ apples} =

\mbox{lots of apples}

\end{equation}

Formatted text

Using the \mbox is fine and gets the basic result. Yet, there is an alternative that offers a little more flexibility. You may recall from the Formatting Tutorial, the introduction of font formatting commands, such as \textrm, \textit, \textbf, etc. These commands format the argument accordingly, e.g., \textbf{bold text} gives bold text. These commands are equally valid within a maths environment to include text. The added benefit here is that you can have better control over the font formatting, rather than the standard text achieved with \mbox.

\begin{equation}

50 \textrm{ apples} \times 100 \textbf{ apples} =

\textit{lots of apples}

\end{equation}

However, as is the case with LaTeX, there is more than one way to skin a cat! There are a set of formatting commands very similar to the font formatting ones just used, except they are aimed specifically for text in maths mode. So why bother showing you \textrm and co if there are equivalents for maths? Well, that's because they are subtly different. The maths formatting commands are:

Command Format Example

\mathrm{...} Roman

\mathit{...} Italic

\mathbf{...} Bold

\mathsf{...} Sans serif

\mathtt{...} Typewriter

\mathcal{...} Calligraphy

Mathematics - Part 2

by Andrew Roberts

This tutorial builds on the basic foundations presented in the previous tutorial. If you often include a lot of maths in your documents, then you will probably find that you wish to have slightly more control over presentation issues. Some of the topics covered make writing equations more complex - but who said typesetting mathematics was easy?!

Adding text to equations

I doubt it will be every day that you will need to include some text within an equation. However, sometimes it needs to be done. Just sticking the text straight in the maths environment won't give you the results you want. For example:

\begin{equation}

50 apples \times 100 apples = lots of apples

\end{equation}

There are two noticeable problems. Firstly, there are no spaces between numbers and text, nor spaces between multiple words. Secondly, the words don't look quite right — - the letters are more spaced out than normal. Both issues are simply artifacts of the maths mode, in that it doesn't expect to see words. Any spaces that you type in maths mode are ignored and LaTeX spaces elements according to its own rules. It is assumed that any characters represent variable names. To emphasise that each symbol is an individual, they are not positioned as closely together as with normal text.

There are a number of ways that text can be added properly. The typical way is to wrap the text with the \mbox{...} command. This command hasn't been introduced before, however, it's job is basically to create a text box just width enough to contain the supplied text. Text within this box cannot be broken across lines. Let's see what happens when the above equation code is adapted:

The text looks better. However, there are no gaps between the numbers and the words. Unfortunately, you are required to explicitly add these. There are many ways to add spaces between maths elements, however, for the sake of simplicity, I find it easier, in this instance at least, just to literally add the space character in the affected \mbox(s) itself (just before the text.)

\begin{equation}

50 \mbox{ apples} \times 100 \mbox{ apples} =

\mbox{lots of apples}

\end{equation}

Formatted text

Using the \mbox is fine and gets the basic result. Yet, there is an alternative that offers a little more flexibility. You may recall from the Formatting Tutorial, the introduction of font formatting commands, such as \textrm, \textit, \textbf, etc. These commands format the argument accordingly, e.g., \textbf{bold text} gives bold text. These commands are equally valid within a maths environment to include text. The added benefit here is that you can have better control over the font formatting, rather than the standard text achieved with \mbox.

\begin{equation}

50 \textrm{ apples} \times 100 \textbf{ apples} =

\textit{lots of apples}

\end{equation}

However, as is the case with LaTeX, there is more than one way to skin a cat! There are a set of formatting commands very similar to the font formatting ones just used, except they are aimed specifically for text in maths mode. So why bother showing you \textrm and co if there are equivalents for maths? Well, that's because they are subtly different. The maths formatting commands are:

Command Format Example

\mathrm{...} Roman

\mathit{...} Italic

\mathbf{...} Bold

\mathsf{...} Sans serif

\mathtt{...} Typewriter

\mathcal{...} Calligraphy

Загрузка...

Выбрать следующее задание

Ты добавил

Выбрать следующее задание

Ты добавил