12.04.2015 Views

Using Imported Graphics in LaTeX and pdfLaTeX - Mirror

Using Imported Graphics in LaTeX and pdfLaTeX - Mirror

Using Imported Graphics in LaTeX and pdfLaTeX - Mirror

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7.4.1 Conditional Code with the ifpdf Package<br />

The ifpdf package’s \ifpdf comm<strong>and</strong> detects 13 whether the document is be<strong>in</strong>g<br />

processed by latex or pdflatex, allow<strong>in</strong>g the document to have conditional code.<br />

For example, s<strong>in</strong>ce it may be advisable to m<strong>in</strong>imize the length of the extension list<br />

(as described <strong>in</strong> Section 9.1) the \ifpdf comm<strong>and</strong> can be used to customize the<br />

extension list<br />

\usepackage{ifpdf}<br />

...<br />

\ifpdf<br />

\Declare<strong>Graphics</strong>Extensions{.pdf,.png,.jpg,.mps}<br />

\else<br />

\Declare<strong>Graphics</strong>Extensions{.eps}<br />

\fi<br />

If the user wants the conditional code to use different \documentclass options, the<br />

follow code allows the \ifpdf comm<strong>and</strong> to be def<strong>in</strong>ed before the \documentclass<br />

comm<strong>and</strong><br />

\RequirePackage{ifpdf}<br />

\ifpdf<br />

\documentclass[pdftex]{article}<br />

\else<br />

\documentclass[dvips]{article}<br />

\fi<br />

This code passes the [pdftex] option if the document is be<strong>in</strong>g processed by pdflatex<br />

<strong>and</strong> passes the [dvips] option if the document is be<strong>in</strong>g processed by latex. As<br />

described <strong>in</strong> Section 7.1 on Page 22, this code is generally not needed s<strong>in</strong>ce most<br />

distributions automatically do this <strong>in</strong> their graphics.cfg file.<br />

Specify<strong>in</strong>g<br />

Width<br />

Specify<strong>in</strong>g<br />

Height<br />

7.5 Specify<strong>in</strong>g Width, Height, or Angle<br />

The comm<strong>and</strong><br />

\<strong>in</strong>cludegraphics[width=3<strong>in</strong>]{file}<br />

<strong>in</strong>cludes the graphics from the specified file such that its width is 3 <strong>in</strong>ches. Instead of<br />

specify<strong>in</strong>g a fixed width (such as 3 <strong>in</strong>ches) specify<strong>in</strong>g the width <strong>in</strong> terms of scalable<br />

lengths 14 makes the graphic layout more robust. For example, the comm<strong>and</strong><br />

\<strong>in</strong>cludegraphics[width=\l<strong>in</strong>ewidth]{graphic}<br />

scales the <strong>in</strong>cluded graphic to be as wide as the current text. The comm<strong>and</strong><br />

\<strong>in</strong>cludegraphics[width=0.80\l<strong>in</strong>ewidth]{graphic}<br />

makes the <strong>in</strong>cluded graphic 80% as wide as the current text. When the calc package<br />

is used, the follow<strong>in</strong>g comm<strong>and</strong> causes the graphics to be 2 <strong>in</strong>ches more narrow than<br />

the current text<br />

\<strong>in</strong>cludegraphics[width=\l<strong>in</strong>ewidth-2.0<strong>in</strong>]{graphic}<br />

Similarly, the comm<strong>and</strong><br />

13 Historically, one method for do<strong>in</strong>g this detection was to use the fact that \pdfoutput was<br />

def<strong>in</strong>ed only if pdfL A TEX was process<strong>in</strong>g the document. However, many TEX distributions now have<br />

their latex comm<strong>and</strong> actually execute pdfL A TEX <strong>in</strong> dvi mode, caus<strong>in</strong>g \pdfoutput to be def<strong>in</strong>ed<br />

when both latex <strong>and</strong> pdflatex are executed. The ifpdf package solves this problem by provid<strong>in</strong>g<br />

a conditional comm<strong>and</strong> that robustly determ<strong>in</strong>es whether the document is be<strong>in</strong>g processed directly<br />

<strong>in</strong>to a pdf file.<br />

14 The predef<strong>in</strong>ed scalable lengths are:<br />

\textwidth is the width of the document’s normal text.<br />

\l<strong>in</strong>ewidth is the width of l<strong>in</strong>es for the current environment.<br />

em is the width of a capital M for the current font.<br />

ex is the height of a lowercase x for the current font.<br />

24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!