| |
| TeX tutorial |
View previous topic :: View next topic |
| Author |
Message
|
| JaneBennet |
Posted: Sun Jul 06, 2008 6:05 pm Post subject: TeX tutorial |
|
|
 Forum Ph.D.

Joined: 06 Apr 2008 Posts: 765
|
So a new feature has been implemented, called TeX. A new formatting button has also been added for it. So, some of you may ask, what is TeX, and how to use it? Okay, Ill try and explain. Suggestions, comments and corrections welcome.
(i) What is TeX?
TeX is a neat way of formatting mathematical equations and other expressions in posts by means of GIF or PNG images (in this forum its PNG). These images are compact and can be inserted in lines of text. Although it is mostly used in mathematics, it can also be used in other areas for example, in chemistry:(ii) How do I use TeX?
Simply wrap your TeX expression in [tex] [/tex] tags. Notice that there is a new TeX formatting button available for this. For example, if you wrapin TeX tags, you get this:
Neat, huh? Notice a couple of things:
(1) The TeX formatter ignores spacing and single line breaks. It automatically parses your equation and inserts relevant spaces so you dont have to do it yourself. In the example above, there is a space before and after the = and before and after each +.
(2) TeX follows typographical convention by formatting all variables in .
(iii) What expressions can I type using TeX?
In our example above, the caret symbol ^ is used to format superscript. Similarly the underscore _ is used to format subscript:x^2 gives
x_0 gives  Note that only the character immediately following the ^ or _ is formatted. If you wish to format more than one character in super-/subscript, you must enclose the characters in braces { }. For example, if you typeyou would getIf you mean x to the power of 12 instead, you must type x^{12}:x^{12} gives 
The backslash \ generally precedes TeX commands. Here are a few examples of commonly typed expressions in TeX:\frac{1}{2} gives
\sqrt{2} gives
\sqrt[3]{2} gives (NB: square brackets [ ] around the 3, braces { } around the 2)
\alpha, \beta, \gamma, \delta etc give , , , etc
\mathbb{Z}, \mathbb{Q}, \mathbb{R}, \mathbb{C} give
, , ,  It is important to note that all TeX commands are case-sensitive. _________________
A problem worthy of attack
Proves its worth by fighting back.
(Piet Hein)
Did You Know?
Fact of the day: Homotopy
Last edited by JaneBennet on Thu Aug 07, 2008 3:55 am; edited 4 times in total |
|
| Back to top |
|
 |
| JaneBennet |
Posted: Sun Jul 06, 2008 6:40 pm Post subject: |
|
|
 Forum Ph.D.

Joined: 06 Apr 2008 Posts: 765
|
Now suppose you want to type an expression like z = cos(x); + isin(x). If you simply wrap that expression in TeX tags, you would get this:Doesnt look pretty, does it? As Ive said, TeX will format all variables in italics; if you dont tell the formatter what youre doing, it will interpret what you type as variables by default. In the formula above, you dont really wnat your cos and sin to be in italics.
Fortunately, there are special TeX commands to take care of common functions like sine and cosine. Simply type \cos and \sin:z=\cos(x)+i\sin(x) gives  Also, you might want to remove the brackets. But there is some minor thing to note here: if you type \cosx and \sinx, the formatter will try and parse these as TeX commands and youll end up with a TeX error as cosx and sinx arent valid TeX commands. To tell the formatter what to do, you have to insert a space before the x:z=\cos x+i\sin x gives  Although the formatter generally ignores spaces, so you dont generally need to type them, this is a case where the space is important: it serves to separate a TeX command from the variables you are using.
TeX commands for other commonly used functions include \tan, \cot, \sec, \lim, \max, \min, \gcd, etc. _________________
A problem worthy of attack
Proves its worth by fighting back.
(Piet Hein)
Did You Know?
Fact of the day: Homotopy
Last edited by JaneBennet on Thu Aug 07, 2008 4:01 am; edited 2 times in total |
|
| Back to top |
|
 |
| Guitarist |
Posted: Mon Jul 07, 2008 7:28 am Post subject: |
|
|
Forum Ph.D.

Joined: 08 Jun 2005 Posts: 713
|
\in =
\ni =
\subseteq =
\subset =
\supseteq =
\supset = Actually I generally prefer
and its analogue
\ne =
\ge =
\le =
\to =
\Rightarrow =
f \cdot g =
f \circ g =
\times =
\otimes =
\oplus =
\equiv =
\cong =
\mathcal{X} =
\overline{X} =
\hat{i} =
\vec{v} =  |
|
| Back to top |
|
 |
| JaneBennet |
Posted: Mon Jul 07, 2008 7:31 am Post subject: |
|
|
 Forum Ph.D.

Joined: 06 Apr 2008 Posts: 765
|
Useful TeX expressions in set theory:
x\in A gives
A\subset B gives
A\subseteq B gives
A\cup B gives (union)
A\cap B gives (intersection)
A\times B gives (Cartesian product)
f:A\to B gives  There are two symbols for the empty set:\emptyset gives
\O gives  I prefer the latter because not only is it easier to type, it also looks much nicer than the other one.
To type the negation of a symbol, you can use the TeX command \not e.g.x\not\in A gives 
To be continued
[Oops, clash of posting with Guitarist. ] _________________
A problem worthy of attack
Proves its worth by fighting back.
(Piet Hein)
Did You Know?
Fact of the day: Homotopy
Last edited by JaneBennet on Thu Aug 07, 2008 3:57 am; edited 1 time in total |
|
| Back to top |
|
 |
| Guitarist |
Posted: Mon Jul 07, 2008 7:56 am Post subject: |
|
|
Forum Ph.D.

Joined: 08 Jun 2005 Posts: 713
|
No worries! I learned something. I had never encountered \O = . Thanks.
You can learn something too, Jane; \notin = , i.e. you don't need the extra slash.
While I am here, let's all say a HUGE thanks to In(Sanity) for making this facility available.
I mean it, man - I also think (hope) it will bring the truckers in for breakfast dinner and tea! |
|
| Back to top |
|
 |
| bit4bit |
Posted: Tue Jul 08, 2008 10:47 am Post subject: |
|
|
 Forum Ph.D.

Joined: 14 Jul 2007 Posts: 623
|
Thanks IS...bout time I learned to use it properly _________________ Chance favours the prepared mind. |
|
| Back to top |
|
 |
| JaneBennet |
Posted: Tue Jul 08, 2008 6:20 pm Post subject: |
|
|
 Forum Ph.D.

Joined: 06 Apr 2008 Posts: 765
|
| Guitarist wrote: |
You can learn something too, Jane; \notin = , i.e. you don't need the extra slash. |
Thanks for the tip. I was howeer making the point that the command \not can be used in general cases, especially when the symbol to be negated is not in common use and so doesnt have its own TeX command: e.g. \not\cong = .
On to more examples. (NB: \displaystyle is there only to improve the appearance of some TeX expressions; it can be omitted if you dont need to be overly neat in your TeX formatting. )\{
\}
\sim
\infty
\displaystyle\sum_{n=1}^k a_n
\displaystyle\prod_{n=1}^k a_n
\displaystyle\bigcup_{\lambda\in\Lambda}C_\lambda
\displaystyle\bigcap_{\lambda\in\Lambda}C_\lambda
\int_a^b\sin x\:dx  Notice the command \: in the last line? I use it to add a small space between the x and the dx otherwise the characters after the sin would be all bunched up together like this: , which isnt quite so neat. This brings us to this useful topic:
Adding and removing spaces in TeX
Although TeX parses what you type and adds relevant spaces, you can add extra spaces of your own. The command \, adds a small space, \: adds a slightly bigger space and \; adds a still slightly bigger space, while \ followed an ordinary space adds an ordinary-sized space:To add a wide space, use \quad:a\quad b  And if youre a real precisionist, you can even specify exactly how wide you want your space to be by using \hspace followed by a precise measurement in curly brackets:a\hspace{10mm}b  Note however that these space commands will only work between characters in a TeX expression. They will be ignored if theyre used right at the beginning or right at the end of your expression.
Now, what if you want to remove spaces in TeX? For example, if you type a+b in TeX, you get with a little space before and after the + sign. However, if you really want to bunch the three characters together without any spaces in between, then use \! before each space you want to remove:a\!+\!b  More to come.  _________________
A problem worthy of attack
Proves its worth by fighting back.
(Piet Hein)
Did You Know?
Fact of the day: Homotopy
Last edited by JaneBennet on Thu Aug 07, 2008 4:02 am; edited 5 times in total |
|
| Back to top |
|
 |
| William McCormick |
Posted: Tue Jul 08, 2008 6:55 pm Post subject: |
|
|
 Forum Ph.D.

Joined: 03 Apr 2008 Posts: 1011
|
Is how I learned the formula for ammonia. I like it. I like it. Nice work.
Sincerely,
William McCormick _________________ http://www.Rockwelder.com
Last edited by William McCormick on Wed Jul 09, 2008 7:01 pm; edited 1 time in total |
|
| Back to top |
|
 |
| (In)Sanity |
Posted: Tue Jul 08, 2008 8:18 pm Post subject: |
|
|
 Forum Cosmic Wizard

Joined: 19 Oct 2004 Posts: 2139 Location: Phoenix AZ
|
| Guitarist wrote: |
No worries! I learned something. I had never encountered \O = . Thanks.
You can learn something too, Jane; \notin = , i.e. you don't need the extra slash.
While I am here, let's all say a HUGE thanks to In(Sanity) for making this facility available.
I mean it, man - I also think (hope) it will bring the truckers in for breakfast dinner and tea! |
Welcome, sorry it took so long. I spent about 12 hours of my long weekend trying to get the thing working. It should have been about an hours work, but Murphy stepped in and made it about 12  _________________ "I don't know, I was really drunk at the time" |
|
| Back to top |
|
 |
| JaneBennet |
Posted: Tue Jul 08, 2008 9:18 pm Post subject: |
|
|
 Forum Ph.D.

Joined: 06 Apr 2008 Posts: 765
|
| William McCormick wrote: |
Is how I learned the formula for ammonia. I like it. I like it. Nice work. |
Not exactly, William. If you want the formula for ammonia, you should type this:\mbox{NH}_3  Well, Im glad to know youre enjoying TeX as well.
And this brings us nicely to another topic:
Text formatting in TeX
TeX format raw letters of the alphabet in italics: wrapping the tags around abc de gives (with the space removed). Suppose you want regular font, no italics? Well, there are at least four ways of formatting regular font in TeX. One of them, as Ive used above, is the command \mbox. The others are \text, \textrm and \mathrm.\mbox{abc de}
\text{abc de}
\textrm{abc de}
\mathrm{abc de}  Notice that the typed space is ignored in the last one, \mathrm. In fact, with \mathrm, the whole input is parsed like any TeX expression, with relevant spaces added and redundant spaces removed, the sole exception being that variables are not italicized. Example:G=6.674\times10^{-11}\ \mathrm{m^3\:kg^{-1}\:s^{-2}} =  With the other three, what you type is parsed as plain text. If you need to format a small amout of your text as a math or math-type expression, it is handy to enclose it within a pair of dollar ($) signs:\textrm{Water is H$_2$O.}  In a moment, we shall see that \mbox together with $ has a very special property of its own.
To format TeX expressions in italics, use \textit or \mathit. Since letters of the alphabet are already formatted in italics by default, this will probably be used for formatting other characters, particularly numerals.\textit{123 45}
\mathit{123 45}  Bold is \textbf and \mathbf.\textibf{abc 123}
\mathbf{abc 123}  And with a bit of ingenuity, you can combine the two.\textbf{$\textit{123 45}$}  Finally, a word about \mbox{$$}. This has the property that it preserves the size of whatever it is formatting. Take an example: X^X gives . The superscripted X is slightly smaller than the other X. Suppose you want both Xs to be of the same size? Then use \mbox{$$}!  X^X
X^\mbox{$X$}  Note: the dollar signs can be omitted if only numerals are being formatted. This is particularly handy when you have fractions within a fraction and you dont want TeX to make things too small to be legible:\frac{1}{1+\frac{1}{2}}
\frac{\mbox{1}}{\mbox{$1+\frac{\mbox{1}}{\mbox{2}}}$}  The down side, obviously, is that your expression can quickly become too complicated with too many mboxes, so this will probably be something youll only want to use occasionally.
EDIT: Ive just learnt that with fractions, you can actually use \dfrac rather than \frac:\dfrac{1}{1+\dfrac{1}{2}}  _________________
A problem worthy of attack
Proves its worth by fighting back.
(Piet Hein)
Did You Know?
Fact of the day: Homotopy
Last edited by JaneBennet on Thu Aug 07, 2008 4:00 am; edited 2 times in total |
|
| Back to top |
|
 |
| bit4bit |
Posted: Wed Jul 09, 2008 6:19 am Post subject: |
|
|
 Forum Ph.D.

Joined: 14 Jul 2007 Posts: 623
|
| JaneBennet wrote: |
| William McCormick wrote: |
Is how I learned the formula for ammonia. I like it. I like it. Nice work. |
Not exactly, William. If you want the formula for ammonia, you should type this:\mbox{NH}_3  Well, I’m glad to know you’re enjoying TeX as well.  |
Whats more, " " is not a valid molecular formula. It should be for nitrogen dioxide, for nitrous oxide (laughing gas), or for two moles of Nitric oxide. _________________ Chance favours the prepared mind. |
|
| Back to top |
|
 |
| Ophiolite |
Posted: Thu Jul 10, 2008 3:05 am Post subject: |
|
|
 Forum Radioactive Isotope

Joined: 25 Jul 2005 Posts: 4486 Location: Scotland
|
Irrelevant posts by William McCormick have been moved to the Chemistry section. _________________ The Universe is not only weirder than we imagine it is weirder than we can imagine. J.B.S.Haldane. |
|
| Back to top |
|
 |
| JaneBennet |
Posted: Thu Jul 10, 2008 3:52 am Post subject: |
|
|
 Forum Ph.D.

Joined: 06 Apr 2008 Posts: 765
|
Thanks Ophi!
Williams off-topic posts, originally posted here, have been moved to here. So lets crack on here.
Variable-sized brackets
Consider this(x-1)(\dfrac{1}{x-2)+\dfrac{1}{x-3})
 The first pair of brackets are fine, but the second pair look funny: theyre a bit too small! To rectify the problem, use the commands \left and \right.(x-1)\left(\dfrac{1}{x-2)+\dfrac{1}{x-3}\right)
 \left and \right can also be used with square brackes [ and ], angle brackets < and > and curly brackets \{ and \} (note that you need a backslash for curly brackets); they also work with the pipe |.
You can even use one or other of them on its own (use \left\. if you dont want the left bracket to show).y=\left\{\begin{array}{ll}1&x\ge0\\0&x<0\end{array}
\left.\begin{array}{c}ax+by=0\\cx+dy=0\end{array}\right\}
 Which introduces this gadget \begin{array}. Thats the tool used for doing matrices but well leave it for next time.  _________________
A problem worthy of attack
Proves its worth by fighting back.
(Piet Hein)
Did You Know?
Fact of the day: Homotopy
Last edited by JaneBennet on Thu Aug 07, 2008 4:03 am; edited 1 time in total |
|
| Back to top |
|
 |
| JaneBennet |
Posted: Sat Jul 12, 2008 7:20 am Post subject: |
|
|
 Forum Ph.D.

Joined: 06 Apr 2008 Posts: 765
|
Arrays and tables
This is going to be the most complicated of all the things discussed in this tutorial so far, so pay attention.
Here is a sample matrix:\left(
\begin{array}
{rcl}
1 & 2 & 3 \\
11 & 22 & 33 \\
111 & 222 & 333
\end{array}
\right)
 I have added spaces and linebreaks to help you see better whats going on. When you type the code yourself, you can ignore some or all of the spaces and linebreaks. Basically, you follow these steps:
Step 1: Type \begin{array} to start.
Step 2: Specify the number of columns and alignment of text within each column. This is done by typing l, r and/or c within curly brackets { and }; l = left, r = right, c = centred. The number of l/r/cs will be the number of columns in your array.
In the example above, there are three columns: text is right-aligned in the first column, centre-aligned in the middle column, and left-aligned in the third column.
Step 3: Type the first row of your array, separating the contents of different columns with an ampersand &. If you have N columns, there should N−1 &s. You can type {} for a blank cell in a column of your row.
Step 4: If you have another row to enter, type \\ (double backslash). You can type \\\\ (double double backslash) for a bigger line spacing, \\\\\\ for an even bigger line spacing, etc. The number of backslashes should always be even.
Step 5: Type \end{array} to finish.
You can enclose an array in brackets. Use \left and \right with the type of brackets you want to use; you can also use the pipe | to enclose an array within vertical lines:\left|
\begin{array}{cc}a & b\\c & d\end{array}
\right|
=ad-bc
 The array method can also be used to build tables. In a table, you may often want to separate columns and/or rows with lines.
(i) To separate adjacent columns with a vertical line, use the pipe | in Step 2 in the instructions for doing an array above.
(ii) To separate adjacent rows with a horizontal line, type \hline after \\ in Step 4 above.
The following example (a table of the multiplication of the nonzero integers modulo 5) will demonstrate how its done.\begin{array}
{c|cccc}
\times_5 & 1 & 2 & 3 & 4 \\
\hline
1 & 1 & 2 & 3 & 4 \\
2 & 2 & 4 & 1 & 3 \\
3 & 3 & 1 & 4 & 2 \\
4 & 4 & 3 & 2 & 1
\end{array}
 _________________
A problem worthy of attack
Proves its worth by fighting back.
(Piet Hein)
Did You Know?
Fact of the day: Homotopy
Last edited by JaneBennet on Thu Aug 07, 2008 4:04 am; edited 3 times in total |
|
| Back to top |
|
 |
| Guitarist |
Posted: Tue Jul 15, 2008 1:08 pm Post subject: |
|
|
Forum Ph.D.

Joined: 08 Jun 2005 Posts: 713
|
For straightforward matrices, the following is a nice shortcut:
\begin{pmatrix}
a & b &c\\
d & e & f\\
g & h & i
\end{pmatrix}
Giving
I believe, though I haven't checked, that bmatrix uses [ ] as delimiters, Bmatrix uses { } and vmatrix uses | | |
|
| Back to top |
|
 |
|
|
|
  |
Goto page 1, 2 Next |
Page 1 of 2 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|