Docsity

Aprendendo LaTeX - Códigos Gerais, Notas de estudo de Física

Toggle sidebar
bg1
Math mode - v.2.32
Herbert Voß∗
February 29, 2008
Abstract
It is often said that T
E
X was designed for mathematical or technical
purposes. This may be true when we remember the reasons why
Donald Knuth created T
E
X. But nowadays there are many examples in
which T
E
X is used for publications with no mathematical or technical
background content. However, writing publications with such material
is one of the important advantages of T
E
X. Because it seems impossible
to know all existing macros and options of (L
A
)T
E
X and the several
additional packages, especially of
AMS
math. This is the reason why
I have attempted to gather all the relevant facts in this paper. An
advanced german version of this paper is available as a book [25].
Please report typos or any other comments to this documentation to
This file can be redistributed and/or modified under the terms of
the L
A
T
E
X Project Public License Distributed from
CTAN
archives in
directory CTAN://macros/latex/base/lppl.txt.
∗Thanks for the feedback to: Hendri Adriaens; Juan Mari Alberdi; Heiko Bauke; Neal
Becker; Andrea Blomenhofer; Alexander Boronka; Walter Brown; Christian Faulhammer;
José Luis Gómez Dans; Zongbao Fang; Sabine Glaser; Sven Gleich; Azzam Hassam; Gernot
Hassenpflug; Henning Heinze; Martin Hensel; Mathias Hoffmann; Jon Kirwan; Morten
Høgholm; M. Kalidoss; Dan Lasley; Angus Leeming; Vladimir Lomov; Tim Love; Dan
Luecking; Hendrik Maryns; Heinz Mezera; David Neuway; Luis Trucco Passadore; Joachim
Punter; Carl Riehm; Will Robertson; Christoph Rumsmüller; José Carlos Santos; Arnaud
Schmittbuhl; Rainer Schöpf; Jens Schwaiger; Uwe Siart; Martin Sievers; Heiko Stamer;
Uwe Stöhr; Carsten Thiel; Juan Luis Varona; David Weenink; Philipp Wook; Michael
Zedler; Zou Yuan-Chuan; and last but not least a special thanks to Monika Hattenbach for
her excellent job of proofreading.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe Aprendendo LaTeX - Códigos Gerais e outras Notas de estudo em PDF para Física, somente na Docsity!

Math mode - v.2.

Herbert Voß∗

February 29, 2008

Abstract It is often said that TEX was designed for mathematical or technical purposes. This may be true when we remember the reasons why Donald Knuth created TEX. But nowadays there are many examples in which TEX is used for publications with no mathematical or technical background content. However, writing publications with such material is one of the important advantages of TEX. Because it seems impossible to know all existing macros and options of (LA)TEX and the several additional packages, especially of AMSmath. This is the reason why I have attempted to gather all the relevant facts in this paper. An advanced german version of this paper is available as a book [25].

Please report typos or any other comments to this documentation to [email protected]. This file can be redistributed and/or modified under the terms of the LATEX Project Public License Distributed from CTAN archives in directory CTAN://macros/latex/base/lppl.txt.

∗Thanks for the feedback to: Hendri Adriaens; Juan Mari Alberdi; Heiko Bauke; Neal Becker; Andrea Blomenhofer; Alexander Boronka; Walter Brown; Christian Faulhammer; José Luis Gómez Dans; Zongbao Fang; Sabine Glaser; Sven Gleich; Azzam Hassam; Gernot Hassenpflug; Henning Heinze; Martin Hensel; Mathias Hoffmann; Jon Kirwan; Morten Høgholm; M. Kalidoss; Dan Lasley; Angus Leeming; Vladimir Lomov; Tim Love; Dan Luecking; Hendrik Maryns; Heinz Mezera; David Neuway; Luis Trucco Passadore; Joachim Punter; Carl Riehm; Will Robertson; Christoph Rumsmüller; José Carlos Santos; Arnaud Schmittbuhl; Rainer Schöpf; Jens Schwaiger; Uwe Siart; Martin Sievers; Heiko Stamer; Uwe Stöhr; Carsten Thiel; Juan Luis Varona; David Weenink; Philipp Wook; Michael Zedler; Zou Yuan-Chuan; and last but not least a special thanks to Monika Hattenbach for her excellent job of proofreading.

CONTENTS CONTENTS

Contents

2 THE INLINEMODE

Part I

Standard LATEX math mode

1 Introduction

The following sections describe all the math commands which are available without any additional package. Most of them also work with special packages and some of them are redefined. At first some important facts for typesetting math expressions.

2 The Inlinemode

As the name says there are always math expressions which are in a standard textline, like this one: f (x) =

´ (^) b a

sin x x dx. There are no limitations for the height of the math expressions, so that the layout may be very lousy if you

insert a big matrix in an inline mode like this: A =

a b c d e f g h i

. In this

case it is better to use the \smallmatrix environment A =

[

a b c d e f g h i

]

from the AMSmath package (see section 26.6 on page 65) or the displaymath mode (section 3 on page 14). This inline mode is possible with three different commands:

∑n i=1 i^ =^

1 2 n^ ·^ (n^ + 1) ∑n i=1 i^ =^ 1 2 n^ ·^ (n^ + 1) ∑n i=1 i^ =^

1 2 n^ ·^ (n^ + 1)

1 (\ sum _{ i =1}^{ n } i =\ frac {1}{2} n \ cdot ( n +1) ) \[10 pt ] 2 $\ sum _{ i =1}^{ n } i =\ frac {1}{2} n \ cdot ( n +1) $\[10 pt ] 3 \ begin { math } 4 \ sum _{ i =1}^{ n } i =\ frac {1}{2} n \ cdot ( n +1) 5 \ end { math }

  1. ( ... ) , the problem is that ( is not a robust macro (see sec- (...) tion 2.3 on the following page).
  2. $ ... $ $...$
  3. \begin{math} ... \end{math}, also not robust \begin{math} ... In general $...$ is the best choice, but this does not work in environments^ \end{math} like verbatim or alltt. In this case (...) works.

2.1 Limits 2 THE INLINEMODE

2.1 Limits

In the inline mode the limits are by default only in super or subscript mode and the fractions are always in the scriptstyle´ 1 font size. For example: ∞ 1

1 x^2 dx^ = 1, which is not too big for the textline. You can change this^ \limits with the command \limits, which must follow a math operator^2 like an \int \lim \prod \sum

integral (\int), a sum (\sum), a product (\prod) or a limes (\lim). But this ´^ ∞ 1

1 x^2 dx^ = 1^ ($\int\limits_{1}^...) does not look very nice in a text line when it appears between two lines, especially when there are multiline limits.^3

2.2 Fraction command

For inlined formulas the fractions are by default in the scriptstyle (see tabular 8 on page 38), which is good for typesetting y = (^) b+1a , because the linespacing is nearly the same, but not optimal, when the formula shows some important \frac facts. There are two solutions to get a better reading:

  1. choose the display mode instead of the inline mode, which is the better one;
  2. set the fontstyle to \displaystyle, which makes the fraction y = a b + 1 more readable but the linespacing increases which is always a bad solution and should only be used when the first solution makes no sense.^4

y = (^) b+1a =

a b + 1

1 $ y =\ frac { a }{ b +1}={\ displaystyle \ frac { a }{ b +1}}$

2.3 Math in∏ \part, \chapter, \section, ... titles like f (x) =

n i=

i − 21 i

All commands which appear in positions like contents, index, header, ... must be robust^5 which is the case for $...$ but not for (...). The latest package fixltx2e defines an macro for declaring existing commands to be robust. The package itself does this already for: 1 \ MakeRobust ( 2 \ MakeRobust ) 3 \ MakeRobust [ (^1) See section 12 on page 38. (^2) To define a new operator see page 75 (^3) For more information about limits see section 6.1 on page 25 or section 35 on page 72. (^4) For an abbreviation see section 29 on page 67, there is a special \dfrac macro. (^5) robust means that the macro is not expanded before it is moved into for example the tableofcontents file (*.toc). No robustness is often a problem, when a macro is part of another macro.

2.6 Linebreak 2 THE INLINEMODE

2.6 Linebreak

LATEX can break an inline formula only when a relation symbol (=, <, >,.. .) or a binary operation symbol (+, −,.. .) exists and at least one of these symbols appears at the outer level of a formula. Thus $a+b+c$ can be broken across lines, but ${a+b+c}$ not.

  • The default: f (x) = anxn^ + an− 1 xn−^1 + an− 2 xn−^2 +... + aixi^ + a 2 x^2 + a 1 x^1 + a 0
  • The same inside a group {...}: f (x) = anxn^ + an− 1 xn−^1 + an− 2 xn−^2 +... + aixi^ + a 2 x^2 + a 1 x^1 +
  • Without any symbol: f (x) = an (an− 1 (an− 2 (.. .).. .).. .)

If it is not possible to have any mathsymbol, then split the inline formula in two or more pieces ($...$ $...$). If you do not want a linebreak for the whole document, you can set in the preamble: \relpenalty= \binoppenalty= which is the extreme case of grudgingly allowing breaks in extreme cases, or \relpenalty= \binoppenalty= for absolutely no breaks.

2.7 Whitespace

LATEX defines the length \mathsurround with the default value of 0pt. This length is added before and after an inlined math expression (see table 1).

foo f (x) =

1

1 x^2 dx^ = 1^ bar^

1 foo \ fbox {$ f ( x ) =\ int _1^{\ infty }\ frac {1}{ x ^2}\ ,\ mathrm { d } x =1 $} bar

foo f (x) =

1

1 x^2 dx^ = 1^ bar

1 foo \ rule {20 pt }{\ ht \ strutbox }\ fbox {$ f ( x ) =\ int _1^{\ infty }\ frac {1}{ x ^2}\ ,\ mathrm { d } x =1 $}\ rule {20 pt }{\ ht \ strutbox } bar

foo f (x) =

1

1 x^2 dx^ = 1^ bar

1 \ setlength {\ mathsurround }{20 pt } 2 foo \ fbox {$ f ( x ) =\ int _1^{\ infty }\ frac {1}{ x ^2}\ ,\ mathrm { d } x =1 $} bar

Table 1: Meaning of \mathsurround

2.8 AMSmath for the inline mode

None of the AMSmath-functions are available in inline mode.

3 DISPLAYMATH MODE

3 Displaymath mode

This means, that every formula gets its own paragraph (line). There are some differences in the layout to the one from the title of 2.3.

3.1 equation environment

For example:

f (x) =

∏^ n

i=

i −

2 i

1 \ begin { equation } 2 f ( x ) =\ prod _{ i =1}^{ n }\ left (i -\ frac {1}{2 i }\ right ) 3 \ end { equation }

The delimiters \begin{equation} ... \end{equation} are the only difference to the inline version. There are some equivalent commands for the display-math mode: \begin{displaymath}

...

  1. \begin{displaymath}... \end{displaymath}, same as [... ]^ \end{displaymath}
  2. [...]. (see above) the short form of a displayed formula, no number [...]

f (x) =

∏^ n

i=

i −

2 i

displayed, no number. Same as 1.

  1. \begin{equation}...\end{equation} \begin{equation} ... \end{equation} f (x) =

∏^ n

i=

i −

2 i

displayed, a sequential equation number, which may be reset when starting a new chapter or section.

(a) There is only one equation number for the whole environment. (^) \nonumber (b) There exists no star-version of the equation environment because [... ] is the equivalent. With the tag \nonumber it is possible to suppress the equation number:

f (x) = [...]

1 \ begin { equation } 2 f ( x ) = [...] \ nonumber 3 \ end { equation }

3.3 Equation numbering 3 DISPLAYMATH MODE

y = d y = cx + d y = bx^2 + cx + d y = ax^3 + bx^2 + cx + d (7)

1 \ begin { eqnarray } 2 y & = & d \ nonumber \ 3 y & = & cx + d \ nonumber \ 4 y & = & bx ^{2}+ cx + d
nonumber \ 5 y & = & ax ^{3}+ bx ^{2}+ cx + d 6 \ end { eqnarray }

3.2.1 Short commands It is possible to define short commands for the eqnarray environment 1 \ makeatletter 2 \ newcommand {\ be }{ % 3 \ begingroup 4 % \ setlength {\ arraycolsep }{2 pt } 5 \ eqnarray % 6 \ @ifstar {\ nonumber }{} % 7 } 8 \ newcommand {\ ee }{\ endeqnarray \ endgroup } 9 \ makeatother

Now you can write the whole equation as

f (x) =

sin x x

dx (8)

1 \be 2 f(x) &=& \int\frac{\sin x}{x},\mathrm{d}x 3 \ee

or, if you do not want to have a numbered equation as

f (x) =

sin x x dx

1 \be* 2 f(x) &=& \int\frac{\sin x}{x},\mathrm{d}x 3 \ee

3.3 Equation numbering

For all equations which can have one or more equation numbers (for every \nonumber line/row) the numbering for the whole equation can be disabled with switching from the unstarred to the star version. This is still for the whole formula and doesn’t work for single rows. In this case use the \nonumber tag.

  • This doc is written with the article-class, which counts the equations continuously over all parts/sections. You can change this behaviour in different ways (see the following subsections).
  • In standard LATEX it is a problem with too long equations and the equation number, which may be printed with the equation one upon the other. In this case use the AMSmath package, where the number is set above or below of a too long equation (see equation 28 on page 28).
  • For counting subequations see section 33.1 on page 71.

3.3 Equation numbering 3 DISPLAYMATH MODE

3.3.1 Changing the style \theequation With the beginning of Section 25.2 on page 53 the counting changes from “44” into the new style “II-51”. The command sequence is

1 \ renewcommand \ theequation {\ thepart -\ arabic { equation }}

See section 33 on page 70 for the AMSmath command.

3.3.2 Resetting a counter style Removing a given reset is possible with the remreset.^6 Write into the preamble @removefromreset 1 \ makeatletter 2 \ @removefromreset { equation }{ section } 3 \ makeatother

or anywhere in the text. Now the equation counter is no longer reset when a new section starts. You can see this after section 26.4 on page 62.

3.3.3 Equation numbers on the left side Choose package leqno^7 or have a look at your document class, if such an option exists.

3.3.4 Changing the equation number style

The number style can be changed with a redefinition of

\def@eqnnum{{\normalfont \normalcolor (\theequation)}}

For example: if you want the numbers not in parentheses write 1 \ makeatletter 2 \ def \ @eqnnum {{\ normalfont \ normalcolor \ theequation }} 3 \ makeatother

For AMSmath there is another macro, see section 33 on page 70.

3.3.5 More than one equation counter

You can have more than the default equation counter. With the following code you can easily toggle between roman and arabic equation counting.

(^6) CTAN://macros/latex/contrib/supported/carlisle/remreset.sty (^7) CTAN://macros/latex/unpacked/leqno.sty

3.5 Frames 3 DISPLAYMATH MODE

  • There is one restriction for the label names, they cannot include one of LATEX’s command characters.^8
  • The label names are replaced by the equation number. \tag If you do not want a reference to the equation number but to a self defined name then use the AMSmath command \tag..., which is described in section 34 on page 72.

3.5 Frames

Similiar to the inline mode, displayed equations can also be framed with the \fbox command, like equation 13. The only difference is the fact, that the equation must be packed into a parbox or minipage. It is nearly the same for a colored box, where the \fbox{...} has to be replaced with \colorbox{yellow}{...}. The package color.sty must be loaded and –important – the calc package to get a correct boxwidth.

f (x) =

1

x^2 dx = 1 (13)

1 \ noindent \ fbox {\ parbox {\ linewidth -2\ fboxsep -2\ fboxrule }{ % 2 \ begin { equation }\ label { eq : frame 0} 3 f ( x ) =\ int _1^{\ infty }\ dfrac {1}{ x ^2}\ ,\ mathrm { d } x = 4 \ end { equation } % 5 }}

If the equation number should not be part of the frame, then it is a bit complicated. There is one tricky solution, which puts an unnumbered equation just beside an empty numbered equation. The \hfill is only useful for placing the equation number right aligned, which is not the default. The following four equations 14-17 are the same, only the second one written with the \myMathBox macro which has the border and background color as optional arguments with the defaults white for background and black for the frame. If there is only one optional argument, then it is still the one for the frame color (15). 1 \ makeatletter 2 \ def \ myMathBox {\ @ifnextchar [{\ my@MBoxi }{\ my@MBoxi [ black ]}} 3 \ def \ my@MBoxi [#1]{\ @ifnextchar [{\ my@MBoxii [#1]}{\ my@MBoxii [#1][ white ]}} 4 \ def \ my@MBoxii [#1][#2]#3#4{ % 5 \ par \ noindent % 6 \ fcolorbox {#1}{#2}{ % 7 \ parbox {\ linewidth -\ labelwidth -2\ fboxrule -2\ fboxsep }{#3} % 8 } % (^8) $ _ ˆ \ & % { }

4 ARRAY ENVIRONMENT

9 \ parbox {\ labelwidth }{ % 10 \ begin { eqnarray }\ label {#4}\ end { eqnarray } % 11 } % 12 \ par % 13 } 14 \ makeatother

f (x) = x^2 + x (14)

f (x) = x^2 + x (^) (15)

f (x) = x^2 + x (^) (16)

f (x) = x^2 + x (^) (17)

1 \ begin { equation }\ label { eq : frame 2} 2 f ( x ) = x ^2 + x 3 \ end { equation } 4 \ myMathBox [ red ]{[ f ( x ) = x ^2 + x ]}{ eq : frame 3} 5 \ myMathBox [ red ][ yellow ]{[ f ( x ) = x ^2 + x ]}{ eq : frame 4} 6 \ myMathBox {[ f ( x ) = x ^2 + x ]}{ eq : frame 5}

If you are using the AMSmath package, then try the solutions from section 39 on page 79.

4 array environment \begin{array} ... \end{array}

This is simply the same as the eqnarray environment only with the possibility of variable rows and columns and the fact, that the whole formula has only one equation number and that the array environment can only be part of another math environment, like the equation environment or the displaymath environment. With @{} before the first and after the last column the additional space \arraycolsep is not used, which maybe important when using left aligned equations.

a) y = c (constant) b) y = cx + d (linear) c) y = bx^2 + cx + d (square) d) y = ax^3 + bx^2 + cx + d (cubic)

Polynomes (18)

1 \ begin { equation } 2 \ left. % 3 \ begin { array }{ @ {} r@ {\ quad } ccrr@ {}} 4 \ textrm { a }) & y & = & c & ( constant ) \