Equations in Latex

On of the main purpose of using Latex is to write the math symbols and equations. There are lot of ways to write a given math in Latex, but it is better to follow some conventions . Here I describes how to put simple math equations and those spanning multiple line which needs special alignments, in Latex.


To put a math equation inline(ie in the current line), we just have to enclose the equation with a pair of dollar signs( eg: $x = y$). If it is to be put in center of a new line, we can use a pair of square brackets ( eg: \[ x = y \] ).

There are many Latex environments which allow to write equations spanning multiple lines. Often it is confusing which environment to use. Almost all multi line equations can be written using the align environment provided by the amsmath package(usage of environments such as equation, displaymath,eqnarray.. is not encouraged). An important concern about multiline equations is vertical alignment of various symbols in it. Following examples illustrate usage of the align environment for common scenarios.


note: To use the 'align' environment, \usepackage{amsmath} should be added to the preamble.

  • A multiple line math derivation which needs all the lines to be vertically aligned on a symbol (say '=' symbol):
     \begin{align*}
    E[|X|] &= \int_{x} |x| f_X(x) dx \\
    &= \int_{|x| \ge a} \! |x| f_X(x) dx + \int_{|x| < a} \! |x| f_X(x) dx \\
    &\ge \int_{|x| \ge a} |x| f_X(x) dx \\
    &\ge a \int_{|x| \ge a} f_X(x) dx \\
    &= a E[|X| \ge a]\\
    \therefore \qquad E[|X| \ge a] &\le \frac{E[|X|]}{a}
    \end{align*}


    Here the ampersand('&') symbol in the first line sets an indentation point. In all lines, the symbol following the '&' symbol would be vertically aligned to the corresponding positions of the first(previous) line. More than one indentation point can be set using more number of '&' symbol. The 'align*' environment is used to prevent numbering of each line. If numbering is needed for each line, then 'align' should be used as the environment. The \qquad command in the last line leaves a horizontal space.

  • Add details to each step of the derivation:
    \begin{align*}
    E[|X|] &= \int_{x} |x| f_X(x) dx \\
    &= \int_{|x| \ge a} \! |x| f_X(x) dx + \int_{|x| < a} \! |x| f_X(x) dx \\
    &\ge \int_{|x| \ge a} |x| f_X(x) dx &&(\because \text{the removed term is non negative})\\
    &\ge a \int_{|x| \ge a} f_X(x) dx &&(\because a \le |x| \text{and it is taken outside})\\
    &= a E[|X| \ge a]\\
    \therefore \qquad E[|X| \ge a] &\le \frac{E[|X|]}{a}
    \end{align*}
    This is an example of using columns in align environment. The double ampersand('&&') symbol is the column separator. The description of a step is written in the same line separated by the column separator.



  • Leave horizontal space between different parts of the equation: You would have already seen \! and \qquad in earlier steps. These are used for adding horizontal space in equations. The available commands for adding space are: \!(adds a negative space), \,(adds a small space), \:, \;, \quad, \qquad in the increasing order

Plotting data points

At the end of all your work, you have some data to show as your result. If you had worked on Scilab you just have to use plot2d() or plot3d() for plotting the data. For 2d data, plot2d() can be used. For 3d data, plot3d() can be used provided you know the third component for each combination of first two components ( ie you have z=f(x,y) for all x and y , then you can plot points(x,y,z) ).

I had a situation in which I want to plot 3d data, but the third component of which is not a function of others. I could not figure out how to do it in Scilab. Then I came to know gnuplot, which is really powerful in plotting. The following lines shows how I plotted the set of 3d points which is pretty easy.

Case: There is a list of 3d data, one in each row (it may have other irrelevant columns which need not be plotted) . Suppose you have data as shown below in a file "points.dat". A line preceded by # is considered as a comment.

#Id x y z
1 -4 -4 -4
2 -4 -4 -2
124 4 4 2
125 4 4 4

Start gnuplot(just type gnuplot in terminal) and give the command
gnuplot> splot "data.csv" using 2:3:4
This command plots the x,y,z values ignoring the first column. You can view the plot obtained in 3d which can be rotated to change the perspective angle, and can be exported as image.

Rainlendar : Calendar for desktop


Have you thought of keeping a calendar on your desktop so that you can see it without clicking anywhere. Then try the calendar Rainlendar . It is very easy to use and can be integrated to your desktop. It has a lot of options that can be configured. A lot of markers are available for highlighting an event. Still it has a simple interface and easy to use.