Showing posts with label LaTeX. Show all posts
Showing posts with label LaTeX. Show all posts

Saturday, June 21, 2008

LaTeX: Frequent Use Packages

This is a list of frequently use packages:
(Usage: Insert \usepackage{package} before \begin{document})

anysize: Set margins
\marginsize{l}{r}{t}{b}


\multicol: Use n columns

\begin{multicols}{n}


graphicx: For displaying images

\includegraphics[width=3cm]{filename}
\includegraphics[width=0.50textwidth]{filename}


url: To insert URL

\url{http://rizauddin.com}

Friday, June 20, 2008

The General Syntax of a LaTeX File

This is a general syntax of a LaTeX file:
\documentclass[options]{class}
% Further global commands and specifications goes here
\begin{document}
% Text mixed with additional commands of local effect goes here
\end{document}

class:

book, report, article, letter, slides

options:

10pt/11pt/12pt, letterpaper/a4paper, twocolumn, twoside, landscape, draft

Tuesday, June 17, 2008

LaTeX: Change the chapter name

How to change the chapter name to something else? For example to have it in other language, such as Malay. In order to do it, put the code below in the preamble of your LaTeX document.

\documentclass{report}
\renewcommand{chaptername}{Bab}
\begin{document}
\chapter{Introduction}
Testing
\end{document}

Tuesday, June 10, 2008

Export EndNote to BibTeX

EndNote is a great software managing references. EndNote works fine with Microsoft Words. But, what about LaTeX? Do you know that LaTeX users could also use EndNote to manage their references, and export the EndNote database to the BibTeX format as needed. This tutorial will show how to export the EndNote database to BibTeX format.

Step 1: Click on Edit > Output Styles > Open Style Manager


Step 2: Select "BibTeX Export"
(Hint: click on any Name, and type bib very fast. It will go straight to the "BibTeX Export" listing)



Step 3: Click Edit > Output Styles > BibTeX Export


Step 4: Open the database that you want to convert to the BibTeX format. Make sure that all entries has been given a label (you must do it manually).




Step 5: Click File > Export. Give the filename a .bib extension. Click on Save.



Now you will have a BibTeX file.

Note: Please don't forget to give all the EndNote database entries a label.

Tuesday, May 20, 2008

Display Maths with Wordpress

Displaying Mathematics notation in a browser is not an easy task. One option is by using a plugin such as Design Science MathPlayer™, which enables Microsoft Internet Explorer to display mathematical notation in Web pages. However, the plugin is not so popular, and it does not comes with the browser by default.

Another way to do it is by using a public LaTeX server, using standard LaTeX code. An example of a public LaTeX server is http://l.wordpress.com/latex.php?latex=. As an example, http://l.wordpress.com/latex.php?latex=int_{-infty }^{infty }e^{-x^{2}};dx=sqrt{pi }&bg=fff&s=2.

One way to use it is by using the img tag of HTML.

For example,
<img src="http://l.wordpress.com/latex.php?latex= int_{-infty}^{infty}e^{-x^{2}};dx=sqrt{pi }&bg=fff&s=2" alt="" />
will produce this image.

Please note that adding bg=fff would produce an image with white background (default is black). As an addition, s=2 is for the size.

However, it is a messy and error prone job to do it this way.

Fortunately, there is an alternative, for Wordpress user. A PhD student at Center for Advanced Study and Institute for Theoretical Computer Science, Tsinghua University, Zhiqiang Zhang had created a plugin for Wordpress, called Latex for Wordpress. This plugin uses LaTeX code to generate images. Although the plugin uses the Wordpress public LaTeX server, a local LaTeX service such as MimeTex is preferable, in case the public server is down. Some Web hosting support MimeTeX by default.

With this plugin, adding Maths notation is as easy as adding the LaTeX code. For example, for displaying an inline math equation, use
$$int_{-infty }^{infty }e^{-x^{2}};dx=sqrt{pi }!$$
and, for the math mode, use
$$!int_{-infty }^{infty }e^{-x^{2}};dx=sqrt{pi }!$$
Notice that there is an exclamation mark "!", just after the second dollar sign.

Download Link: http://wordpress.org/extend/plugins/latex/

Update: You can also try the new Easy LaTeX plugin by Manoj.

Note: If you have trouble in writing the LaTeX code, use TeXaide.

Tuesday, May 6, 2008

Create LaTeX table easily

LaTeX is a great typesetting system that produces publication quality mathematics, and it is free. However, creating table in LaTeX is not an easy task.

Fortunately, there are some table generator exists for creating LaTeX table. One example is Excel2LaTeX. Excel2LaTeX is a free Microsoft Excel addin that allows you to transform the Microsoft Excel current selection into LaTeX code. Most of the formatting such as bold, italic, border lines, and multi column cells, will be preserved.


The usage is very simple. First, create the table using Microsoft Excel. Second, highlight the table. Finally, click on the Excel2LaTeX addin button on the toolbar. The LaTeX code can then be copied to the clipboard, or saved as a LaTeX file.

As a conclusion, creating table in LaTeX is not an easy task. However, the existence of LaTeX table generator such as Excel2LaTeX, will ease the problem.

Download link: Excel2LaTeX

Tuesday, April 22, 2008

Insert figures to LaTeX

LaTeX is a good tool for creating articles or books. However, when it comes to inserting figures, it is a very cumbersome process. This tutorial will show the steps for producing LaTeX documents with figures. For the purpose of this tutorial, we will use a graph from an excel document.


Step 1: Highlight (left click) the graph in the excel file.


Step 2: Copy the graph into memory. Right click and select Copy. (or just press and hold Ctrl, and then press c)



Step 3: Open Paint application. Click on the Start button, choose All Programs > Accessories > Paint.



Step 4: Paste the graph that we have just copied into Paint. Click on Edit > Paste. (or just press and hold Ctrl, and then press v)




Step 5: Now we are going to save our graph in JPEG format. Click File > Save As. A "Save As" dialog box will opened. Type the file name - graph. For the "Save as type" choose JPEG. For simplicity, make sure that the graph is saved in the save folder as the LaTeX document. Then, click on the save button.




Step 6: Open the LaTeX document, and type the following LaTeX code:
\begin{figure}[htp]
\centering
\includegraphics{graph}
\caption{Some graph}
\label{fig:graph}
\end{figure}
Don't forget to import the graphicx package, by inserting
\usepackage{graphicx}
at the top of the LaTeX document.


Step 7: Now we can produce the pdf document, using the pdflatex command.


note: This tutorial assumed that we are going to produce a pdf file, since pdflatex only accept PDF, PNG, JPEG and GIF format. For producing a postscript or dvi file, we need to convert the JPEG file (graph.jpg) to eps format. It could be done using tools such as jpeg2ps. However, it is beyond this tutorial.

Wednesday, April 16, 2008

LaTeX example - creating a lecture note

This LaTeX example will create an automatic exercises numbering as well as the problems in each exercise. It is useful for creating lecture notes.

Example

\documentclass[a4paper,12pt]{book}

\newcounter{exercisenum}[section]
\renewcommand{theexercisenum}{\arabic{exercisenum}}
\newenvironment{exercise}
\stepcounter{exercisenum}

\vspace{1pc}\par\noindent\textbf{Exercise thesection.theexercisenum}\par

\newcounter{problemnum}[exercisenum]
\renewcommand{theproblemnum}{\arabic{problemnum}}
\newcommand{problem}
{
\stepcounter{problemnum}
\theproblemnum.
}

\newcounter{secondproblemnum}[problemnum]
\renewcommand{thesecondproblemnum}{\alph{secondproblemnum}}
\newcommand{secondproblem}
{
\stepcounter{secondproblemnum}
\thesecondproblemnum)
}

\begin{document}

\chapter{Introduction}

\section{Function}

\begin{exercise}

\begin{tabular}{lll}
\multicolumn{3}{l}{Solve for $x$.}
\problem $x + 3 = 4$ &amp; \problem $x + 3 = 4$ &amp; \problem $x + 3 = 4$
\multicolumn{3}{l}{
\problem \secondproblem $x + 11 = 0$
\secondproblem $x + 11 = 0$
\secondproblem $x + 11 = 0$
}
\problem $x + 3 = 4$ &amp; \problem $x + 3 = 4$ &amp; \problem $x + 3 = 4$
\problem $x + 3 = 4$ &amp; \problem $x + 3 = 4$ &amp; \problem $x + 3 = 4$
\end{tabular}

\end{exercise}

\begin{exercise}

\problem
Cras egestas rhoncus mi. Donec sed orci rhoncus risus consequat
posuere. Maecenas ut lorem at neque imperdiet varius. Mauris imperdiet
arcu a eros. Proin elementum elementum nibh.

\problem Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In eget magna.

\end{exercise}

\end{document}

BibTeX Entry Types

This is a list of possible BibTeX entry. The "required fields" part is mandotary, while "optional fields" is optional. However, if we missed some of the "required fields" item, LaTeX can still compile successfully.
@article
required fields: author, title, journal, year.
optional fields: volume, number, page, month, note.

@book
required fields: author or editor, title, publisher, year.
optional fields: volume or number, series, address, edition, month, note.

@booklet
required fields: title.
optional fields: author, howpublished, address, month, year, note.

@inbook
required fields: author or editor, title, chapter and/or pages, publisher, year.
optional fields: volume or number, series, type, address, edition, month, note.

@incollection
required fields: author, title, booktitle, publisher, year.
optional fields: editor, volume or number, series, type, chapter, pages,
address, edition, month, note.

@conference
@inproceedings
required fields: author, title, booktitle, year.
optional fields: editor, volume or number, series, pages, address, month,
organization, publisher, note.

@manual
required fields: title.
optional fields: author, organization, address, edition, month, year, note.

@masterthesis
required fields: author, title, school, year.
optional fields: type, address, month, note.

@misc
required fields: none.
optional fields: author, title, howpublished, month, year, note.

@phdthesis
required fields: author, title, school, year.
optional fields: type, address, month, note.

@proceedings
required fields: title, year.
optional fields: editor, volume or number, series, address, month,
organization, publisher, note.

@techreport
required fields: author, title, institution, year.
optional fields: type, number, address, month, note.

@unpublished
required fields: author, title, note.
optional fields: month, year.

Compiling LaTeX on Windows: An alternative method

The usual method to compile latex is by using "latex" command, and if the latex file contains bibliography, it will be a very tedious and repetitive job.

To produce a dvi file:
latex yourfile.tex
bibtex yourfile.tex
latex yourfile.tex
latex yourfile.tex

To produce a pdf file:
pdflatex yourfile.tex
bibtex yourfile.tex
pdflatex yourfile.tex
pdflatex yourfile.tex

However, for the windows user, with Miktex, there is an alternative that could simplify all those tasks - the texify.

To produce a dvi file"
texify yourfile.tex

To produce a dvi file and clean all the auxilary files:
texify -c yourfile.tex

To produce a pdf file (to clean all the auxilary files, just add -c as above):
texify -p yourfile.tex

To produce a dvi file and run the default viewer (add -p for pdf)
texify yourfile.tex --run-viewer