Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ ¹ ² ³ °
 

You are not logged in. #1 20060922 09:04:35
LaTeX  A Crash Course
Often on this forum you will see equations embedded into the text of posts. Some are quite complex, others are simple. They are not produced by magical elves that live in the poster's computer  they are produced using a typesetting language called Latex (often written LaTeX or , but pronounced as "Latec"), and what is produced might look like this:
or even: Latex itself is actually designed for writing whole documents  you can set out paragraph structure, tables, footnotes and all sorts of other things that normally go into a text document. This forum, however, borrows some of the Latex language, specifically that part used for typesetting mathematical equations. This post will give you an introduction to the basics of Latex and is looseley grouped into two parts. The first two chapters cover the basic syntax (what the input should be like) and structure for Latex. This is obviously the sort of stuff you need to know before you can use Latex, so do take the time to look at the examples and see if you can understand what's going on. After the syntax has been covered, all that's left is the specifics of what you can do with Latex  how to insert symbols, equations, text and so forth, and this is the subject of the remaining chapters. 1) Using LaTeX To use Latex on this forum, you have to place the Latex code between opening and closing math tags  you would type something in the format that's in the code box: Code:[math]<Latex commands go in between these tags>[/math] Note that normally, writing the above would have made something that looks like this: the only reason it didn't is because it's in the code box  to get the output for the following examples, type exactly what you see inside the code boxes, remembering that Latex is case sensitive. Two important things about how Latex will format your equations: 1) It ignores spaces, and spaces characters how it thinks best  so you can spread out the comands you type to make them easier to read whilst you are typing, but they will produce the same output. 2) Latex also ignores carriage returns, where you start a new line  to start a new line in Latex, use the command: Code:\\ For example, the following two codes will both give the same output: Code:[math] v = u + a t \\ F = m a [/math] Code:[math]v=u+at\\F=ma[/math] Shown here: and: Note that the first line will be indented by default  if you want to remove this, simply place the "\\" command before the first line. So: Code:[math] \\ v = u + a t \\ F = m a [/math] Gives: 2) Basic Expressions As you've seen from above, basic expressions are typed in exactly as you would do when normally typing. You can use brackets, equals, minus, vertical bars "", and so on. Some things you cannot use directly are curled braces, like "{" or "}". Other characters that cannot be directly used are: Code:# $ % & ~ _ ^ \ as these all mean something special in the Latex language. If you want your output to display one of these characters, for example: you have to preceed that character with a backslash, "\". The above was produced using: Code:[math]a = 50 \%[/math] The one exception to this is if you want to output the backslash character itself. This is done using the following command: Code:\backslash . Code:[math]x_1 = y^2 = z^4_1[/math] Note that you can attatch both a sub and superscript to the same charachter as in the above example. The superscript and subscript characters normally just read the next character along, then go back to normal text formatting. For example, typing x_ijk in your code would give you . To include more than one character, enclose them in curly braces "{" and "}". So: Code:[math]x_{ijk}[/math] gives: You can embed sub/superscripts within sub/superscripts, as in  just remember to use braces where neccessary. The previous example was generated from: Code:[math]e^{x^{2_i}}[/math] . are done using the function: Code:[math]\frac{numerator}{denominator}[/math] Just as with sub/superscripts, they can be embedded within other fractions. They are input using commands  words preceeded by backslash charachters. For example, typing "\pi" would output , "\sum" would produce , etc. A fairly thorough list of symbols can be found here. 6) Text in Latex Text can be input in math mode, so you don't have to come out of it to say something. Text is done within the "\mbox{}" command, so: Code:[math]V_{sphere} = \frac{4}{3} \pi r^3 \mbox{ is a formula for the volume of the sphere with radius }r[/math] Would give an output of: 7) Special Functions  Trigonometry, Limits, Integrals, Sums and Roots Here are some special functions that deserve some special treatment. First of all, basic trig functions  if you were to write just "cos x" in part of your code, it would look a bit funny. Like this: . However, by using the special symbol "\cos", the cos in the output will not be in italics, it will look like this: . The same applies to tan, sin, and some other functions, as listed in the list of symbols, which can be found here. Note that, if you use the "\lim" function followed by a subscript, the subscript will be placed directly underneath the "lim" text when it is output. For example: Code:[math]\lim_{x \rightarrow \infty} \frac{1}{x} = 0[/math] Gives: Now onto integrals. The text "\int" will give an integral sign, , which can then be used with super/subscripts in the normal way to give boundaries. For example: Code:[math]\int_0^{\pi} \cos x dx = 0[/math] Gives: When the sumation symbol, "\sum", is used with super/subscripts, the text is placed directly above or below the sumation symbol. For example: Code:[math]\sum_{n=0}^{\infty} n[/math] Gives: Roots can be done using the "\sqrt{}" command, where whatever you want to contain within the square root sign goes in the curled braces. For example: Code:[math]r = \sqrt{ x^2 + y^2 }[/math] Gives: You can also utilise cube roots, nth roots. To do this, you still use the "\sqrt" command, but you put the expression you want before the root in square braces before the curled braces, so would be given by "\sqrt[a]{b}". The expression in the square braces, as well as in the curly braces, can be as complicated as you like. So: Code:[math]r^{ \frac{ 1 }{ n^2 + 2 } } = \sqrt[ n^2 + 2 ]{r}[/math] Gives: 8) Dynamic Braces Dynamic braces are handy when you have large fractions or large symbols (e.g. integrals, sums, etc). They automatically adjust to the size they should be. If you wanted braces around a fraction, you would normally just type something like: Code:[math]( \frac{n+2}{3} )[/math] But this looks mildly strange, like this: Dynamic braces provide a "fix" for this, so your output can look like this instead: The above braces were produced using the "\left(" command for the opening brace, and the "\right)" command for the closing brace. This works in a similar fasion for square braces, "[]" and straight braces are treated the same, "". If you want to produce dynamic curled braces, you still have to put a backslash before you type in the brace symbol itself (the same as with normal braces), like "\left\{" and "\right\}". You can "nest" braces within braces, but dynamic braces must be paired up (each opeing brace must have a closing brace and vice versa, though they do not have to be of the same type) or you will get an error as an output. If you wish to only have an opening  or closing  brace next to an expression, you can use one of the null braces, which are "\left." and "\right.". So, for example: Code:[math] \left. \frac{ n^2 + n}{ n^2  n} \right\} [/math] Gives: 9) Matrices Matrices in Latex are done as arrays inside dynamic braces (see part (8), above). (They do not have to be done inside braces, but they almost always are. Either way, you get to choose what type of braces to put them in, if any.) When you type in your Latex code, first you'll put an opening brace (if you so wish) and then use the command "\begin{array}". Next, you have to define how many columns you want, and whether you want them aligned by the left, right, or center. The alignment is only important when you have equations and other longwinded expressions as elements in your matrix, for the following examples we'll keep everything aligned to the center for simplicity. To define how many columns you want, use an opening brace, followed by some letters  use "r", "l" or "c" for each column, indicating how you wish to align each column. For example, if you wanted a matrix with five columns, all aligned to the centre, the opening statement for your matrix will look like this: Code:\left( \begin{array}{c c c c c} ... If you wanted three columns with the first two aligned to the right, and the last one aligned to the center, you'd use "{r r c}" instead of the "{c c c c c}" command above. Code:[math] \left( \begin{array}{cc} a & b \\ c & d \end{array} \right) [/math] Gives: The code: Code:[math] \left \begin{array}{c c c} \lambda  1 & 4 & 3 \\ 5 & \lambda + 6 & 7 \\ 8 & 4 & \lambda  2 \end{array} \right [/math] Gives: Also note that, although it's the case in the above examples, the number of rows in your matrix does not need to be the same as the number of columns. Arrays can be tricky to get the hang of as they can become fairly cumbersome quite easily, but take your time getting to grips with the basics and you'll soon master them. Last edited by Dross (20061011 09:33:44) Bad speling makes me [sic] #2 20060925 14:32:26
Re: LaTeX  A Crash CourseJust playing around here to try it out. Feel free to delete this in the efforts of tidiness. Code:x^2 + y^2 = z^2 \mbox { sure looks nicer than x**2 + y**2 = z**2} Is there any easy way to see what your reply will look like before you submit it? #3 20060925 18:16:43
Re: LaTeX  A Crash Course
Ah, no... that's just my rubbish spelling! Thanks for changing it so I look less of a fool Bad speling makes me [sic] #4 20060925 19:23:16
Re: LaTeX  A Crash CoursePractice Using/Abusing LaTeX! 2) (note: command for is "\pi") 3) 4) 5) 6) 7) 8) 9) (note  command for is "\to" or "\rightarrow") 10) 11) (note  command for is "\infty") 12) (note  command for is "\ldots") 13) [note: more to come soon  watch this space!] Last edited by Dross (20061017 18:36:37) Bad speling makes me [sic] #5 20061003 08:34:31
Re: LaTeX  A Crash CourseThanks for this great tutorial, hope its ok to 'practice' on this thread. But i wonder, im getting some odd behaviour: if i add lots of newlines inside the math tag, the interpreter gives me something like 'math?' in latex font. e.g. this does not work because of the newlines inside the math tag: Code:[math] e^{i\theta} = cos\theta + i\sin\theta\\ \cos\theta = \frac{e^{i\theta} + e^{i\theta}}{2}\\ \sin\theta = \frac{e^{i\theta}  e^{i\theta}}{2i}\\ [/math] what could be wrong? #8 20061011 09:41:06
Re: LaTeX  A Crash CourseJust added, hotoffthepress sections to the original post above: Last edited by Dross (20061011 09:41:31) Bad speling makes me [sic] #10 20061012 20:04:35
Re: LaTeX  A Crash CourseA peicewise function is done using two of the techniques explained above, namely arrays and dynamic braces. The following code is used: Code:[math]f(x) = \left\{ \begin{array}{c l} 1 & x\mbox{ rational} \\ 0 & x\mbox{ irrational} \end{array} \right. [/math] Note the second column of the array is alligned to the left, so the conditions are aligned all "nice". The following code was used: Code:[math]g(x) = \left\{ \begin{array}{c l} x^2 + x + 1 & x \in (1,0]\\ x^2 + x & x \in (0,1)\\ x^2 & x \not\in (1,1) \end{array} \right. [/math] Last edited by Dross (20061012 20:12:08) Bad speling makes me [sic] #12 20061226 11:11:40
Re: LaTeX  A Crash Course//just a test... Last edited by krassi_holmz (20061226 11:45:17) IPBLE: Increasing Performance By Lowering Expectations. #13 20070206 05:30:03
Re: LaTeX  A Crash CourseAnother useful thing to know, is that '\!' will clear space between objects, and '\ ' will add space, for example: Code:\int\int\int Code:\int\!\!\!\int\!\!\!\int Code:\int\ \ \int\ \ \int Last edited by lucadeltodesco (20070206 05:30:26) The Beginning Of All Things To End. The End Of All Things To Come. #14 20070225 11:40:34
Re: LaTeX  A Crash CourseTry this parent directory and near the bottom is "symbols.pdf" Last edited by John E. Franklin (20070225 11:56:33) igloo myrtilles fourmis #15 20070225 12:15:22
Re: LaTeX  A Crash CourseHere's a text file of many of them from somewhere's else. Last edited by John E. Franklin (20070225 12:41:32) igloo myrtilles fourmis #17 20070227 13:53:42
Re: LaTeX  A Crash Course
Indeed. #19 20070228 16:06:31
Re: LaTeX  A Crash CourseWhat does the slash exclamation point do? Strange spaceing before a Q? or first letter? Last edited by John E. Franklin (20070228 16:12:21) igloo myrtilles fourmis #20 20070301 03:25:48
Re: LaTeX  A Crash Course\! removes some space between charachters: Code:y = m x + c \\\\ y \! = \! m \! x \! + \! c (remember latex ignores whitespace) You can put more spacing between charachters using (in increacing order of the amount of space it'll give you) "\,", "\:", "\;", "\quad" and "\qquad". Code:a b \, c \: d \; e \quad f \qquad g Edit: Oh yeah, strange spacing is before the first line, but only if there's more than one line It's just a forum thing  put a doublebackslash as the first thing in your mathtags and it's not a problem. Last edited by Dross (20070301 03:27:44) Bad speling makes me [sic] #21 20070301 09:16:20
Re: LaTeX  A Crash CourseYou can even specify exactly how much spacing you want. For example, if you want exactly 30 mm of white space, Code:\hspace{30mm} Thus: Last edited by JaneFairfax (20070301 09:18:56) #22 20070302 17:01:32
Re: LaTeX  A Crash CourseHow come my as the beginning and end of the sentence when I first post it, but then later it might.Last edited by John E. Franklin (20070302 17:05:15) igloo myrtilles fourmis #23 20070312 02:10:12
Re: LaTeX  A Crash CourseI’ve just learnt a handy little trick. You can use the doubledollar $$ to make part of your text smaller. For example, if you type It looks fine except that the fraction appears a little oversized in the formula. To make it smaller and the formula neater, put $$ before and after the code for the fraction: \cos{x}=0\Leftrightarrow x\in\{(n+$$\frac{1}{2}$$)\pi:n\in\mathbb{Z}\} #24 20070312 03:42:40
Re: LaTeX  A Crash Coursewow didn't know about that, ive also learnt how to do the proper Z now :p using \mathbb{#} The Beginning Of All Things To End. The End Of All Things To Come. #25 20070401 08:50:08
Re: LaTeX  A Crash CourseI have a question, but first I must know this: does anyone here use Miktex and WinShell? 