The post has moved here:
Wednesday, January 19, 2011
Sunday, January 2, 2011
Installing Latex on Windows and Linux and Latex Document Compilation Instructions
In this article, I’ll present some tips and tricks on how to do certain things on latex such as adding sections, subsections, inserting images and writing equations etc. Then I’ll provide a sample tex file and instructions for compiling the file using latex along with installation instructions of latex software on various operating systems.
Adding sections and subsections in latex documents
To add a section, use section tag. Here’s an example,
Adding sections and subsections in latex documents
To add a section, use section tag. Here’s an example,
\section{Overview} |
If this section is in a chapter it is preceded by a numbering. For example, if it is chapter 1 numbering is 1.1, 1.2 etc.
If you want to add a subsection under a section use use subsection tag. Here's an example,
It will have numbering like 1.1.1, 1.1.2 etc. If you need subsections under subsection, use subsubsection tag.
No more nesting (after 3 levels) is supported.
How to insert images on latex documents
The first thing you need to do is to convert your image (jpg, png, gif etc) to eps (a postscript format) which is easy to convert to pdf. To convert an image to eps format you need ImageMagick. In fedora installation command of ImageMagick is
In Windows you can install ImageMagick after downloading from http://www.imagemagick.org/download/binaries/
Current latest release direct link for Windows:
http://www.imagemagick.org/download/binaries/ImageMagick-6.6.6-7-Q16-windows-dll.exe
Now use the convert command to convert the image.
In widows you have to put the installation path as well with the command. For example, if it installed in C:\Program Files\ImageMagick directory.
To view eps files you need ghostscript. In Windows, you can install ghostscript from here:
http://ghostscript.com/releases/gs900w32.exe
In Fedora, you have to apply following command as root to install ghostscript,
Now it’s time to include the eps file on tex. Use figure tag to make caption, includegraphics command to include the image. You need to specify the correct path of your image in \includegraphics command. Here’s an example,
Set the caption text and label text same. Label text is used on List of figures. In a template they are automatically numbered according to chapter. If you need to scale up image to half of its size use scalebox tag along with includegraphics.
Writing scientific/math equations in latex
If your equations require numbering on right side use this tag,
For example,
But if your equation doesn’t require numbering use tag like this,
For example,
Integration symbol: \int
To show only root sign not n-th root use tag: \sqrt{x}, replace x with your expression or symbol
To show nth root use tag: \sqrt[n]{x}
To show fractions like ½ use \frac tag. Example,
For summation sign use \sum tag,
\limits is used to set limits on summation sign. Here, i=1 goes down and n goes up. You write texts preceding _ to put them down (subscript) and use ^ to superscript.
For using only one math symbol you can use \ensuremath{} tag. For example,
Here are latex tags for some of the math symbols:
You can find a detailed list of latex symbols here:
http://web.ift.uib.no/Teori/KURS/WRK/TeX/symALL.html
Installation Instructions of Latex for Fedora Core
Apply following commands after opening a terminal and logging into root. Alternatively you can apply su command and provide root password for instant switching.
Installation Instructions of Latex for Ubuntu
Apply following commands if you are using Ubuntu
Installation Instructions for Windows (XP, Vista, Seven)
Download basic-miktex from here: http://miktex.org/2.9/setup and run the installer.
Compiling Tex Documents
Now let’s learn how to compile latex document file. Here’s a sample tex file,
Open a text editor. Create a new file and paste the code given above. Save the file with name test.tex.
Now let’s compile the tex file. In Linux, apply following commands on terminal
A pdf file will be generated with same filename. In Linux if you need to view dvi files you can use either evince or xdvi
In Windows, you might skip generating dvi files. You can use pdflatex.
To compile tex files in Windows you need to apply following command,
assuming "C:\Program Files\TeX” is your installation directory for basic-miktex.
If there is no error on the tex file it will generate a pdf document which you can open using a pdf reader like Adobe pdf reader or Foxit Reader.
More tips and tricks
Here’s an example of using bullets for following texts:
Using tables
Follow this link: http://en.wikibooks.org/wiki/LaTeX/Tables It explains tables well.
Adding newlines: use \\ to add a newline
Using Bold styles: Use \textbf{text here} tag to bold your text.
Italicizing texts: You can use \emph tag or \textit tag to italicize your text. Example,
Subscripting: Write texts preceding _ to make them subscripted. To write xi type x_i
Superscript: use ^ to superscript. To write x^2 use x^2 exactly.
Troubleshooting
If you get errors like this frequently,
Latex expects including math tag during usage of math notations like superscript, subscript and symbols. Here’s an example,
When this syntax is ensured latex will not display those error messages anymore.
If you want to add a subsection under a section use use subsection tag. Here's an example,
\subsection{Formulation} |
It will have numbering like 1.1.1, 1.1.2 etc. If you need subsections under subsection, use subsubsection tag.
No more nesting (after 3 levels) is supported.
How to insert images on latex documents
The first thing you need to do is to convert your image (jpg, png, gif etc) to eps (a postscript format) which is easy to convert to pdf. To convert an image to eps format you need ImageMagick. In fedora installation command of ImageMagick is
# yum install ImageMagick |
In Windows you can install ImageMagick after downloading from http://www.imagemagick.org/download/binaries/
Current latest release direct link for Windows:
http://www.imagemagick.org/download/binaries/ImageMagick-6.6.6-7-Q16-windows-dll.exe
Now use the convert command to convert the image.
$ convert filename.jpg filename.eps |
In widows you have to put the installation path as well with the command. For example, if it installed in C:\Program Files\ImageMagick directory.
C:> “C:\Program Files\ImageMagick\convert.exe” filename.jpg filename.eps |
To view eps files you need ghostscript. In Windows, you can install ghostscript from here:
http://ghostscript.com/releases/gs900w32.exe
In Fedora, you have to apply following command as root to install ghostscript,
# yum install ghostscipt |
Now it’s time to include the eps file on tex. Use figure tag to make caption, includegraphics command to include the image. You need to specify the correct path of your image in \includegraphics command. Here’s an example,
1 \begin{figure}[htbp] 2 \centering 3 \includegraphics{./Figures/SA_Spheric.eps} 4 \caption{Latitude and Longitude \label{ Latitude and Longitude }} 5 \end{figure} |
Set the caption text and label text same. Label text is used on List of figures. In a template they are automatically numbered according to chapter. If you need to scale up image to half of its size use scalebox tag along with includegraphics.
\scalebox{0.5}{ \includegraphics{./Figures/SA_Spheric.eps}} |
Writing scientific/math equations in latex
If your equations require numbering on right side use this tag,
\begin{equation} Your math exp \end{equation} |
For example,
\begin{equation}\int r = \sqrt[2]{x^2 + y^2 + z^2}\end{equation} |
But if your equation doesn’t require numbering use tag like this,
\begin{math} Your math exp \end{math} |
For example,
Our equation is, \begin{math}\int r = \sqrt[2]{x^2 + y^2 + z^2}\end{math}. Proof ... |
Integration symbol: \int
To show only root sign not n-th root use tag: \sqrt{x}, replace x with your expression or symbol
To show nth root use tag: \sqrt[n]{x}
To show fractions like ½ use \frac tag. Example,
thd = \frac{1}{n} |
For summation sign use \sum tag,
\sum\limits_{i = 1}^n Abs (t_i - t_{i-1})\end{equation} |
\limits is used to set limits on summation sign. Here, i=1 goes down and n goes up. You write texts preceding _ to put them down (subscript) and use ^ to superscript.
For using only one math symbol you can use \ensuremath{} tag. For example,
If angle in degree is \ensuremath{\theta} then the slope is .. |
Here are latex tags for some of the math symbols:
\Phi \lambda \Pi \epsilon |
You can find a detailed list of latex symbols here:
http://web.ift.uib.no/Teori/KURS/WRK/TeX/symALL.html
Installation Instructions of Latex for Fedora Core
Apply following commands after opening a terminal and logging into root. Alternatively you can apply su command and provide root password for instant switching.
$ su Password: # yum install tetex-latex evince-dvi xdvik |
Installation Instructions of Latex for Ubuntu
Apply following commands if you are using Ubuntu
# sudo apt-get install tetex-base tetex-bin |
Installation Instructions for Windows (XP, Vista, Seven)
Download basic-miktex from here: http://miktex.org/2.9/setup and run the installer.
Compiling Tex Documents
Now let’s learn how to compile latex document file. Here’s a sample tex file,
\documentclass[12pt]{article} \usepackage{amsmath} \title{\LaTeX} \date{} \begin{document} \maketitle \LaTeX{} is a document preparation system for the \TeX{} typesetting program. It offers programmable desktop publishing features and extensive facilities for automating most aspects of typesetting and desktop publishing, including numbering and cross-referencing, tables and figures, page layout, bibliographies, and much more. \LaTeX{} was originally written in 1984 by Leslie Lamport and has become the dominant method for using \TeX; few people write in plain \TeX{} anymore. The current version is \LaTeXe. % This is a comment; it is not shown in the final output. % The following shows a little of the typesetting power of LaTeX: \begin{align} E &= mc^2 \\ m &= \frac{m_0}{\sqrt{1-\frac{v^2}{c^2}}} \end{align} \end{document} |
Open a text editor. Create a new file and paste the code given above. Save the file with name test.tex.
Now let’s compile the tex file. In Linux, apply following commands on terminal
$ latex test.tex $ dvipdf test.dvi |
A pdf file will be generated with same filename. In Linux if you need to view dvi files you can use either evince or xdvi
$ evince test.dvi & $ xdvi test.dvi & |
In Windows, you might skip generating dvi files. You can use pdflatex.
To compile tex files in Windows you need to apply following command,
D:> "C:\Program Files\TeX\miktex\bin\pdflatex.exe" test.tex |
assuming "C:\Program Files\TeX” is your installation directory for basic-miktex.
If there is no error on the tex file it will generate a pdf document which you can open using a pdf reader like Adobe pdf reader or Foxit Reader.
More tips and tricks
Here’s an example of using bullets for following texts:
- Dining and canteen system
- Library, reading room system
- Debate,language club system
- Games and sports system
- Washing and cleaning system and Utensil management
\begin{itemize} \item {Dining and canteen system} \item {Library, reading room system} \item {Debate,language club system} \item {Games and sports system } \item {Washing and cleaning system and Utensil management } \end{itemize} |
Using tables
Follow this link: http://en.wikibooks.org/wiki/LaTeX/Tables It explains tables well.
Adding newlines: use \\ to add a newline
Using Bold styles: Use \textbf{text here} tag to bold your text.
Italicizing texts: You can use \emph tag or \textit tag to italicize your text. Example,
\emph{set your text here} \textit{set your text here } |
Subscripting: Write texts preceding _ to make them subscripted. To write xi type x_i
Superscript: use ^ to superscript. To write x^2 use x^2 exactly.
Troubleshooting
If you get errors like this frequently,
! Missing $ inserted. |
Latex expects including math tag during usage of math notations like superscript, subscript and symbols. Here’s an example,
\begin{math} Your expression for example C_i end{math} |
When this syntax is ensured latex will not display those error messages anymore.
Subscribe to:
Posts (Atom)