Outils pour utilisateurs

Outils du site


issue192:latex

Ceci est une ancienne révision du document !


Donald Knuth developed Tex because he was dissatisfied with the way the math in his books was being typeset. He wanted to make a typesetting application that would be easy to use and would work across multiple operating systems. He ended up with an application that writes a set of interlinked text files, readable in any text editor in any operating system. The output can be sent to any screen or printer that understands the PDF command set. For an author this had the added benefit that the produced file could not be changed without the author's knowledge. PDF files were often acceptable to printing shops in the 1970s and 1980s, a time when most word processing formats were not acceptable.

Because of this history Latex / Tex has a comprehensive set of methods and tools to display mathematical expressions. In this issue we are going to explore some of them. If you use TexStudio or a similar IDE you will probably be able to duplicate what you see here and expand on it.

There is an inline math method. It uses dollar signs to wrap around the math expression. A simple example is: $x^{2}+y^{2}=1 $. And there is what is called the display mode \[ x^{2}+y^{2}=1 \] The display mode surrounds the math expression with backslash and square brackets. The expression is centered on a line of its own.

In TexStudio there is also a Latex inline math mode. It uses backslash with parentheses (round brackets) to surround the math expression. A simple example is: \(x^{2}+y^{2}=1 \). It does exactly the same thing as the inline method using square brackets.

To make the expression a little more complicated without your eyes glazing over if you regard mathematics as evil I will set up the formula for determining the length of the hypotenuse of a right-angle triangle (do you remember Pythagoras from school?).

To calculate the length of the hypotenuse use the following formula:

$ c = \sqrt{a^{2}+b^{2}} $

That was not so bad. Now let's try the formula for finding the roots of a quadratic equation. (Again you probably saw this on the board in school.) To find the roots of a quadratic equation first put it into standard form:

$f(x) = ax^{2}+bx+c$

Then use the following formula substituting in the values of $a, b, c$:

$x = \frac{-b+-\sqrt{b^{2}-4ac}}{2a}$

I hope you can see the text around this equation is normal but the equation is reduced to fit into one text line. That reduction makes it hard to read. Let's use the display math mode.

Then use the following formula substituting in the values of a, b, c:

\[ x = \frac{-b \pm \sqrt{b^{2}-4ac}}{2a} \].

The instructions for typesetting are in the same order used when writing the formula by hand. • Make a fraction • numerator $ -b \pm $ • square root • b-squared - 4ac • denominator 2a

With the manual method in mind look at the code needed to make this simple formula. \frac{numerator}{denominator} sets up a fraction \sqrt{} puts the square root sign over whatever is inside its curly braces. \pm inserts the plus-minus sign

Let's get a little more complicated and introduce some trigonometric functions. For example, here is the Pythagorean identity

[ \sin^{2}\theta + \cos^{2}\theta = 1 \]

This can be used to find the sine of an angle.

[ \sin\theta = \pm \sqrt{1- \cos\theta}\]

Because both of these expressions take up only a single line they could use the inline math method without much loss of legibility. $ \sin^{2}\theta + \cos^{2}\theta = 1 $. Normally the lowercase theta is used to represent angular distance. In other applications an uppercase theta is needed. To get an uppercase theta simply make theta start with an uppercase T: $ \Theta $. (Note theta is part of the math environment in Latex / Tex. It must have either dollar signs or backslash - square brackets before and after it even when it is a single character.) This method of getting an uppercase Greek letter by using an uppercase letter to start the letter name works with Greek letters in general.

We can move from trigonometry to calculus with a short explanation of differentiation.

The derivative of a function will yield the slope of the line graph generated by the function. The derivative can be expressed as $ \frac{dy}{dx} $ or more commonly as $ f'(x) $. The general equation for a derivative is

\[ f'(x) = \stackrel{\lim}{h\rightarrow0}\frac{f(x+h)-f(x)}{h} \]

Solving this expression using $ f(x) = x^{2} $ Generates the following equation.

$\stackrel{\lim}{h\rightarrow0} = 2x + h $.

When h = 0 then f'(x) = 2x. This answer should not surprise you if you have done this much math at school.

Here is a simple example of the use of math typesetting. This is a problem I set for my college students. If a processor has a speed (frequency) of 2.2GHz how long does one processing cycle take? In mathematical terms (or physics terms if you prefer) if f=2.2GHz how long is one processing cycle, 1~Hz? One way to solve the problem is to set up a proportion (a pair of equal ratios) and solve for the unknown.

As we all should know, 2.2GHz=2.2*10^{9} cycles per second.

\[\frac{2.2*10^{9}~cycles}{second}=\frac{1~cycle}{x~second}\]

\[2.2*10^{9}x~cycle-sec= 1~cycle-sec \]

\[x = \frac{1}{2.2*10^{9}}\]

\[x=0.454545…*10^{-9}~seconds\]

In common computer terms, 1 processing cycle takes 454.5 picoseconds, less than half a nanosecond.

Above is the Latex code for this little calculation. Figure 5 shows the result in a Latex-generated PDF. Here is what it looks like in LibreOffice.

I hope you enjoyed or at least endured this short visit to the math facilities of Latex. Next time we will explore how to use Latex in chemistry class.

issue192/latex.1682786734.txt.gz · Dernière modification : 2023/04/29 18:45 de auntiee