Tuesday, December 11, 2012

How to use reference (cross-links) by their names

There are many ways to do this, see e.g. here:
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=nameref

The way that works for me is the nameref command from within hyperref package. One possible usage is:
\section*{foo}
\label{sec:foo}
...
\nameref{sec:foo}

Monday, December 10, 2012

How to create an empty page in your document

Sometimes we need empty pages in our document, the easiest way to do this is:
\newpage
\mbox{}
\newpage

Also if different style to the empty page is needed the following code is working:
\newpage
\thispagestyle{empty}
\mbox{}
\newpage

 Source: http://nw360.blogspot.pt/2007/10/creat-empty-page-in-latex.html

Monday, October 22, 2012

Wednesday, October 10, 2012

How to put two figures next to each other

Use the minipage command, and the epsfig package e.g.

\begin{figure}[h]
  \hfill
  \begin{minipage}[t]{.45\textwidth}
    \begin{center}  
      \epsfig{file=figure1.eps, scale=0.5}
      \caption{figure 1}
      \label{fig-tc}
    \end{center}
  \end{minipage}
  \hfill
  \begin{minipage}[t]{.45\textwidth}
    \begin{center}  
      \epsfig{file=figure2.eps, scale=0.5}
      \caption{figure 2}
      \label{fig-tc}
    \end{center}
  \end{minipage}
  \hfill
\end{figure}

This, and other possible ways to put figures next to each other can be found here:
http://www.cse.iitd.ernet.in/~bagchi/latex-tips.html

Tuesday, October 2, 2012

How to write new line in LaTeX

Many LaTeX user (as myself in the past) think that the form of new line is to write
\\
Well, it works, bit it is actually not new line, but starting a new paragraph
The correct notation for new line (but not new paragraph) is
\\*

A more detailed description with many other possibilities to write new line new paragraph, new page is available at
http://www.personal.ceu.hu/tex/breaking.htm#newline

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.

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$

Wednesday, May 16, 2012

How to write fraction

I usually use the \frac command as

$x = \frac{numerator}{denominator}$

This will render numerator over the denominator, alternatively in inline codes \dfrac can be used instead from the amsmath package with the same syntax.

How to write mathematical symbols

A fairly good description about the topic can be found here:
http://amath.colorado.edu/documentation/LaTeX/Symbols.pdf

Write normal (gaussian) distribution in LaTeX

To imply that a random variable v is distributed according to the normal distribution with mean m and covariance sigma^2 write

\usepackage{amssymb}

$v \sim \mathcal{N} (m,\sigma^2)$

note that the package amssymb is needed in order to use \mathcal

Friday, May 4, 2012

Collaborative editing

My first guess for collaborative editing was googledocs with latexlab as described here.
But this in my opinion has serious privacy issues.

Some other ideas are text tracking systems, like svn or git as back-end. A collection of possible methods can be found here.

However this topic is still unresolved.

Update: there are two main alternatives for online collaborative editing:
  • Sharelatex
  •  Overleaf

Thursday, April 12, 2012

How to place figures / images inside a table

Figures and images can be placed within tables, but even into other environments, or without environment. A good description is available here:

http://texblog.org/2008/02/04/placing-graphicsimages-inside-a-table/

Thank you J. !

Tuesday, April 10, 2012

How to use subtitle in an article

Make use of the \subtitle command, to do this use scrartcl document class,
and if you want the same fonts as at the article class,
also set them accordingly with \setkomafont
 
\documentclass{scrartcl}
\setkomafont{disposition}{\normalfont\bfseries}

\begin{document}

\title{(Title)}
\subtitle{(Subtitle)}
\author{(Author)}
\maketitle
\end{document}

Friday, March 30, 2012

How to embed fonts in your document

Sometimes you need font types embedded into your document, here is a good solution:

http://mohamednabeel.blogspot.pt/2009/10/fixing-font-not-embedded-issue-to-pass.html

Since I personally use kile to edit LaTeX documents, I process normally to create the .dvi, and then I use the commands

> dvips -Ppdf -G0 -tA4 file.dvi

> ps2pdf -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress file.ps file.pdf

Monday, March 26, 2012

How to link webpages from latex

Use the hyperref package as:
 
\documentclass{article}
\usepackage{hyperref}
\begin{document}

Here's a link to \href{http://webpage.com}{text}.

\end{document}
 
See at http://www.johndcook.com/blog/2008/11/24/link-to-web-pages-from-latex-pdf/
 or
 http://en.wikibooks.org/wiki/LaTeX/Hyperlinks

How to create matrices

Generally the easiest way is:
$
  L = \left[
    \begin{array}{cc}
       x & y \\
       z & w
    \end{array} \right]
$
A good reference about the topic can be found here:

http://www.rizauddin.com/2009/05/how-to-create-a-matrix-in-latex/

An even easier way to do this is to use pmatrix as
$
  \begin{pmatrix}
     x & y \\
     z &  w
  \end{pmatrix}
$
 However this latter will always put the matrix inside round  parenthesis.

Tuesday, March 20, 2012

write 1st, 2nd, ... nth correctly

Using the nth package as

\usepackage[super]{nth}

 ...

 \nth{<number>}

super is only needed if you want the "th" in superscript, this is the English preferred format, so I usually use as this

or alternatively

 k$^{\textnormal{th}}