Monday, August 6, 2012

Avoid eqnarray

Some say, you should avoid eqnarray in multiline equations. There are several reasons why and how to do that, see here:
http://tug.org/pracjourn/2006-4/madsen/madsen.pdf

I personally used eqnarray a lot, and never had problems with that till now, when it just generated too much empty space before and after the equations, so I simply switched to array.

Monday, July 30, 2012

Thursday, July 19, 2012

How to force no indentation at the beginning of a new section

Use the \noindent command at the beginning of the section. This will force the first line to have no indentation at all.

Tuesday, July 3, 2012

Include figures from a separate directory

It is often a good idea to have the figures separated into a folder. This can be done using the \graphicspath command as


\graphicspath{{./mypics/}}
after the includes.
This will tell the compiler to look up the figures from the mypics directory in the document root. Don't forget to include the graphicx (or similar) package.

Thursday, June 28, 2012

Write comments in LaTeX

Normally comment is written in LaTeX with '%'. This rather suggested for short, one line comments, because the effect is only valid till the end of the line. If you would like to comment an entire block, it's more convenient to use the verbatim package as

\usepackage{verbatim}
 ...

\begin{comment}
  ...
  commented text
  ...
\end{comment}

Friday, June 22, 2012

How to refer to sections

Use \label to add label to a section and \ref to refer to it.

\section{Greetings}
\label{sec:greetings}
 
Hello!
 
\section{Referencing}
 
I greeted in section~\ref{sec:greetings}.
 see http://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing for more detils

Thursday, June 21, 2012

How to make references to equations

To have correct references of the same form to the equations use the \autoref{} command from within the hyperref package. This will also creat hyperlinks within the document into the referred equations.

Tuesday, June 19, 2012

How to leave open parenthesis in equations

If you use \left( and \right) the syntax checker will not allow you not to close (or not to open) the parenthesis. To get your LaTeX code correct you have to use \left. or \right. to have it closed.

This is useful for instance when you want to add new lines with parenthesis open or write cases like 
$\left\{
   \begin{array}{l c l}
      x &\rightarrow& y \\
      z &\rightarrow& w
    \end{array}

\right.$

Monday, June 18, 2012

Sunday, June 17, 2012

Vertical spaces in equations

This might not be the most sophisticated way to do this, but it works:
simply escape the spaces using \ (backslash)
$x_{k+1}\ =\ x_k+w_k$

Thursday, May 31, 2012

How to write integral from minus infinity to plus infinity in LaTeX

Lower and higher limits to integrals can be set as
$ \int^{+\infty}_{-\infty} x \, dx $

How to write argmax and argmin

$ \operatorname{arg\,max}_a f(a) \operatorname*{arg\,max}_b f(b)$

Note that the first version is more for inline code, while the second is rather for equation. Naturally, arg min is written analogously. Don't forget to use the amsmath package

For more info see
http://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics

Wednesday, May 23, 2012

How to use multiple .bib files

Bibtex files are countaining references. In some cases we would like to use multiple .bib files, these we can simple enumerate in the  \bibliography command
as

\bibliography{file1,file2}
where file1.bib and file2.bib contain the references

Monday, May 21, 2012

How to write different cases in equations

Many times we need to write different cases like      
a= {0.6 if t <= 100
      {0.9 it t > 100
The easiest, and most elegant way to do this is to use \case command, as
 $a = \begin{cases}
     0.6, & \textnormal{if } t\le100 \\
     0.9 & \textnormal{if } t>100
\end{cases}$

Thursday, May 17, 2012

How to write sum in the equations

The easiest way to write a sum of an expression (i=[1 .. n]) in equations is
$\sum_{i=1}^n expression$
Note that in inline code this will put lower and upper bound next to the sum sign, not over and under. To  display lower and upper bound under and over the sum sign use the \displaystyle command before the sum.

To specify directly that the upper and lower bound are over and under the sum symbol, simply write
$\sum\limits_{i=1}^n expression$