# How To Put Math In a Wiki

This is a fairly brief explanation of how to embed math in Wikispaces. What I will try to do here is present enough for someone who is not familiar with the formatting methods used to be able to add simple expressions to a page. This is not an in-depth tutorial on LaTeX. For a more on the subject see http://blog.wikispaces.com/2007/05/math-in-wikispaces.html which also refers you to a few other resources.

# Introduction

There is a limit to what you can do in HTML (what is used to write a regular web page), for anything much beyond a=b you will probably need something else. What Wikispaces (and many other wikis) provides is a method to typeset a complicated mathematical expression and then include an image of the finished expression in the page. For example, since the equation for average acceleration involves a complicated fraction you can either try to show it as aavg=(vf-vi)/(tf-ti) or you could do this:
$\displaystyle a_{\mathit{avg}}=\frac{v_f-v_i}{t_f-t_i}$
This was entered into the wiki as:
[[math]]
\displaystyle a_{\mathit{avg}}=\frac{v_f-v_i}{t_f-t_i}
[[math]]
As you can see, there's some special commands in there to tell Wikispaces how to format things to be presented to your browser. You can also see the main part of that (everything between the [[math]] tags) by hovering your mouse over the displayed equation. It might look complicated at first but it'll be simpler to go through it a piece at a time.

The [[math]] tags have to be on a line alone, if they're on a line with other text they don't get interpreted properly.

# Subscripts & Superscripts

To add a subscript to a letter (such as an 'i' on a 't' to indicate initial time) all you have to do is enter it as t_i (inside the [[math]] tags of course). Entering superscripts (or exponents, but it's not limited to just that) is similar, x squared would be entered as x^2.
 To get Enter $t_i$ t_i $x^2$ x^2
There is a quirk to the interface to be aware of, only the next element following the ^ or _ will become the superscript or subscript, all remaining characters will be back to normal. To group multiple characters in a superscript or subscript just put the entire superscript or subscript in curly braces ({ and }) like x_{avg} or t^{10}:
 To get Enter $x_avg$ x_avg $x_{avg}$ x_{avg} $t^10$ t^10 $t^{10}$ t^{10}
This method of grouping things will work in other areas as well, they'll be addressed as they come up.

# Fractions

To produce a fraction the command is frac{}{} - whatever is in the first pair of braces becomes the numerator, whatever is in the second becomes the denominator. Examples are \frac{1}{2} or \frac{v_f-v_i}{t_f-t_i} which would show up as
$\displaystyle \frac{1}{2} \quad\mathrm{or}\quad \frac{v_f-v_i}{t_f-t_i}$

# Special Symbols

Some mathematical symbols can be typed directly from the keyboard such as + - = ! / ( ) [ ] < > | ' and :

Others need to be entered as a special command. Most of the Greek alphabet falls into that category, the commands are just the names of the letters, all lowercase for lowercase letters (\alpha, \theta, \omega, etc.) and capitalized for the uppercase ones (\Delta, etc.). Some capital letters are the same as letters in the latin alphabet (alpha, epsilon, eta, mu, nu, etc.), they do not exist as special letters so you just use the latin versions for them.

Other symbols that may be useful are >= (\ge), <= (\le), infinity (\infty), arrows (\rightarrow, \longrightarrow, etc.) and many others. There are hundreds available, see the LaTeX symbol references for lists of mathematical symbols. Some of the common ones are:
 $\ge$ \ge $\le$ \le $\infty$ \infty $\rightarrow$ \rightarrow $\longrightarrow$ \longrightarrow $\leftarrow$ \leftarrow $\cdot$ \cdot $\alpha$ \alpha $\delta$ \delta $\Delta$ \Delta $\theta$ \theta $\omega$ \omega $\Omega$ \Omega
Special symbols can be used just like any other letter anywhere one could appear, you only need to leave a space after them before the next letter to indicate the end of the command. For example, the mathematically meaningless \omega^{\frac{\alpha}{t}}{\theta_{\Delta t\le 5}} would show up on screen as
$\displaystyle\omega^{\frac{\alpha}{t}}{\theta_{\Delta t\le 5}}$

# Vectors and Other Accents

Sometimes it is necessary to print a vector symbol or other accent over something, to do that there's another set commands, one for each accent. For example, a vector symbol (an arrow to the right over something) is entered as \vec{x} which would become
$\vec{x}$

Normally all the spacing will be taken care of for you and the output will be pretty good. Sometimes though the spacing will need help, perhaps because you're doing something the program doesn't expect, or perhaps because you're going beyond what it knows how to do. If you need to fix the spacing you have a few commands available: "\ " (a backslash before a space) means put a regular space in (spaces are normally ignored), \, means put in a very small space, \! means a small negative space (it will close up what was too large of a space), and for larger spaces there is \quad (a space 4 times the x-height of the font, about 3 spaces) and \qquad (2 quads, about 6 spaces). As examples:
 $xx$ xx $x\ x$ x\ x $x\,x$ x\,x $x\!x$ x\!x $x\quad x$ x\quad x $x\qquad x$ x\qquad x
There are no commands currently (January, 2009) available to adjust the positioning of the expressions on the web page. They always print flush with the left side of the text. The only exception I've found is if you put the equations in a table but even so they're still printed flush left in their cells with the table flush left.

There's not much to do to adjust vertical spacing. A small space will be left before and after mathematical expressions automatically. Normally the expressions are typeset in what is known as inline style, they can also be made larger (display style) or smaller. The commands to do this are \displaystyle (large, most variables are kept full-sized and everything else is sized accordingly), \textstyle (inline style - the whole expression is sized to more or less fit in a single text line, this is the default), \scriptstyle (the base size of the variables is sized to match a normal superscript), and \scriptscriptstyle (the base size of the variables is sized to match a superscript on a superscript, this is probably too small).
 $\displaystyle x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$ \displaystyle x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} $\textstyle x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$ \textstyle x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} $\scriptstyle x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$ \scriptstyle x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} $\scriptscriptstyle x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$ \scriptscriptstyle x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
Using the \displaystyle option usually gives the best results for a displayed equation, since displayed equations are the only option in Wikispaces then that's probably the one to use for most multi-line or otherwise complicated expressions.

# Roman Type In Math

Most expressions set all letters of the latin alphabet in italic type, but you may have noticed that some of the expressions I have shown have bits that are in regular roman type. If you need alternate styles of type you can get them with the commands \mathrm{x} (put x in roman type), \mathit{x} (put x in italic type, this is close to the default except inside \mathit the spacing will be better for words instead of individual variables), and \mathbf{x} (put x in boldface type). There are others but those three will cover most of your needs. As an example
$this\ is\ done\ without\ any\ type\ specification,\ see\ the\ difference\ if\ you$
$\mathrm{try\ it\ again\ with\ mathrm}$
$\mathbf{or\ again\ with\ mathbf}$
$\mathit{or\ again\ with\ mathit\ -\ quite\ a\ difference,\ isn't\ it?}$
If you look closely at the first and last lines you'll see that the main difference between them is spacing, look at the word "difference" itself in both lines and you will see the spacing between the double-f and the i in particular has changed.

# Trig (and Similar) Functions

There are special commands to print sin, cos, tan, log, lim, and related functions. All they do is print those letters but they put them in roman type and add spacing around them to improve the appearance. To use them you just type "\sin x" or the like and you will get something like this:
$\sin x\quad\cos x\quad\tan x\quad\log x\quad\lim x$

# Roots

Square roots (and other roots) have their own command - \sqrt{x} will print x under a square root symbol and since x is in a pair of braces it can be any quantity you want to use, either a single variable or something more complex. There's also a variation for roots other than 2, if you want to show a cube root of x then you would type \sqrt[3]{x} - the [3] is an optional argument to the command that tells it to make that the root, once again any expression could go there. As examples:
 $\sqrt{x}$ \sqrt{x} $\sqrt[3]{x}$ \sqrt[3]{x} $\sqrt[3]{ax^2+bx+c}$ \sqrt[3]{ax^2+bx+c}

# Parentheses, Braces, and Brackets

If all you need are simple parentheses they can be entered straight from the keyboard. A problem can arise when putting parentheses around elements taller than regular letters, the normal parentheses don't look right around taller elements. A set of commands, \left(, \left[, \left{, and \left| (along with the corresponding \right... commands), will address that problem. If you type (\frac{1}{2}) you get small parentheses, if you instead type \left(\frac{1}{2}\right) it will enlarge them to match their contents as you can see here:
 $\displaystyle (\frac{1}{2})$ \displaystyle(\frac{1}{2}) $\displaystyle\left(\frac{1}{2}\right)$ \displaystyle\left(\frac{1}{2}\right) $\displaystyle[\frac{1}{2}]$ \displaystyle[\frac{1}{2}] $\displaystyle\left[\frac{1}{2}\right]$ \displaystyle\left[\frac{1}{2}\right] $\displaystyle|\frac{1}{2}|$ \displaystyle|\frac{1}{2}| $\displaystyle\left|\frac{1}{2}\right|$ \displaystyle\left|\frac{1}{2}\right|

# Calculus

Calculus introduces additional symbols for limits, derivatives/differentiation, and integrals. Most of calculus will not look very good in anything besides display style, anything else will compress it too much.

Limits are done as if they were a trig function (\sin, \cos, etc.) with a subscript - \lim_{x\rightarrow 0}\frac{1}{x}=\infty will produce
$\displaystyle \lim_{x\rightarrow 0}\frac{1}{x}=\infty$

Derivatives would seem like they could be done as just a fraction (\frac{dx}{dt}) but that produces poor output, a better way is to set the 'd's in roman type (\frac{\mathrm{d}x}{\mathrm{d}t}) - you can see the difference as
$\displaystyle \frac{\mathrm{d}x}{\mathrm{d}t} \quad\mathrm{vs.}\quad\frac{dx}{dt}$
The first one makes the distinction between the operator and the variables, the second one blurs that distinction.

Integrals can be more complex to space correctly. Typing \int\!\! a\,\mathrm{d}t instead of just \int a\mathrm{d}t gives
$\displaystyle \int\!\! a\,\mathrm{d}t \quad\mathrm{vs.}\quad\int a\mathrm{d}t$
A small additional space between the variable and the differential operator makes the meaning clearer and a pair of small negative spaces between the integral sign and the variable close things up a bit. Limits on integration sometimes need a lot more negative space to close up the space, the key is to just adjust them until they look right.

# Math In Tables

Math in tables is one of the few ways to apply any layout specifications to math. The way to do it is to put the entire [[math]] ... [[math]] combination inside one of the table cells. For example, to produce
 $x^2$ $\sqrt{x}$ $\sin x$ $\sin^{-1} x$
you would need to enter
|| [[math]]
x^2
[[math]]  || [[math]]
\sqrt{x}
[[math]]  ||
|| [[math]]
\sin x
[[math]]  || [[math]]
\sin^{-1} x
[[math]]  ||
Note that the math expression itself is on its own line in between the [[math]] tags. The arrangement of line breaks is critical, if the tag and the math expression are not separated by a line break it will not work.