Showing posts with label Latex. Show all posts
Showing posts with label Latex. Show all posts

Wednesday, February 18, 2009

Including Images in LaTeX Documents

Following are a few notes on including graphics (images) into Latex documents.

I recommend using the graphicx package. There is another one called graphcis that has the same functionality, but uses a different syntax. In my opinion, graphicx has the better syntax.
  \usepackage[options]{graphicx}
Common options are:
  • Driver name, such as dvips, dvipdf, and pdftex.
  • draft: draw an empty box in place of the image.
Examples:
  \usepackage{graphicx}
  \usepackage[dvips]{graphicx}
When compiling with latex or texify to create a DVI file (and then to PS or PDF using dvips, dvipdfm, or ps2pdf if needed) you can include EPS files using the command
  \includegraphics[key=value, ...]{fileName}
Common key/values are
  • scale= number
  • width= length
  • height= length
  • totalheight= length : height plus depth; generally used when rotating the graphic
  • keepaspectratio= boolean : true or false
  • angle= number : the angle to rotate the image counterclockwise, in degrees
  • origin= location : the anchor point for rotation; legal values include c (center), t (top), r (right), bl (bottom-left), B (baseline), and certain combinations, such as tr
  • draft= boolean : true or false; draw an empty box in place of the image.
  • bb= llx lly urx ury : creates a new bounding box using the specified coordinates; default unit is bp (points)
  • clip= boolean : true or false; don't draw parts of the graphic outside the bounding box
  • viewport= llx lly urx ury : creates a bounding box relative to origin (generally ll) of the existing one
  • trim= left bottom right top : creates a new bounding box by adding or removing the given lengths to each side of the existing bounding box
Examples:
  \includegraphics{MyFile.eps}
  \includegraphics[height=3cm,angle=45]{MyFile.eps}
  \includegraphics[scale=0.55]{MyFile.eps}
  \includegraphics[height=3cm,width=5cm,keepaspectratio=true]{MyFile.eps}
You can convert images to EPS files using the convert command in the ImageMagick tool suite. Other tools such as matlab, and PaintShop Pro (maybe Gimp?) also let you save images as EPS files.

When using pdflatex to create PDF files you can use the same commands above, but instead of including EPS files, you can include PNGs, BMPs, and GIFs directly (no need to convert to EPS files first):
  \includegraphics{MyFile.jpg}
  \includegraphics[height=3cm,width=5cm]{MyFile.png}
References
  1. CTAN, CTAN graphicx package information, 2009
  2. D.P. Carlisle, Packages in the graphics bundle, (graphics guide for Latex3, PDF), 2005
  3. Including graphics in a LaTeX document, amath.colorado.edu, 2008

Tuesday, January 6, 2009

Adding an index to your document in Latex

Source code required:

  • Include the package makeidx, e.g. \usepackage{makeidx}.
  • Call \makeindex in your preamble.
  • Add index to keywords where desired, e.g. \index{keyword}, \index{keyword!subkeyword},
  • \index{keyword!subkeyword!subsubkeyword}.
  • Call \printindex where your want the index to be generated (usually at the end of the document).

Compiling:

  • Run latex on your main latex file, e.g. latex main.tex. This will create a main.idx file.
  • Run makeindex on the index file, e.g. makeindex main.idx, to generate the index file main.ind.
  • Run latex again on your main file, e.g. latex main.tex.

or

  • Run texify on your main latex file (e.g. texify main.tex) to automatically do all the necessary steps outlined above (and more if necessary).

Example:

  \documentclass{book}
 \usepackage{index}

 \makeindex

 \begin{document}

 This is some very important text about
 Latex \index{latex}. Here is some more.

 \printindex

 \end{document}

References

  1. Leslie Lamport, MakeIndex: An Index Processor For Latex, 1987.