General"If" statements in LaTeX... Possible?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
FrankZA
Posts: 14
Joined: Wed Oct 17, 2007 1:02 pm

"If" statements in LaTeX... Possible?

Post by FrankZA »

I have a tricky question. I am busy working on a document that I would like to compile directly to PS and PDF for various reasons.

Is it possible to include if-statements in my code to do something like the following:

Code: Select all

IF compiling to PDF THEN
    \usepackage{PDFstyle}
    \usepackage{hyperref}
ELSE IF compiling to PS THEN
    \usepackage{PSstyle}
    \usepackage{psfrag}
END IF

IF compiling to PDF THEN
    Go to \url{www.latex-community.org}
ELSE IF compiling to PS THEN
    Go to {\tt www.latex-community.org}
END IF
TeXnicCenter 1RC, LEd 0.53, MikTeX 2.8, Windows XP (SP3)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

"If" statements in LaTeX... Possible?

Post by localghost »

Take a look at the ifthen, the xifthen or the ifpdf package.


Best regards
Thorsten¹
User avatar
FrankZA
Posts: 14
Joined: Wed Oct 17, 2007 1:02 pm

Re: "If" statements in LaTeX... Possible?

Post by FrankZA »

Thanks Thorsten

I appreciate the help.
TeXnicCenter 1RC, LEd 0.53, MikTeX 2.8, Windows XP (SP3)
User avatar
FrankZA
Posts: 14
Joined: Wed Oct 17, 2007 1:02 pm

"If" statements in LaTeX... Possible?

Post by FrankZA »

The ifpdf package works very well for this problem and I see Heiko Oberdiek has allowed for integration with the ifthen package.

I currently have the following code working:

Code: Select all

\usepackage{ifpdf}
\ifpdf
	\usepackage{Style-PDF}
	\usepackage{hyperref}
	\usepackage[all]{hypcap}
\else
	\usepackage{Style-PS}
	\usepackage{pstricks}
\fi
then further down...

Code: Select all

\ifpdf
	\DeclareGraphicsExtensions{.pdf}
\else
	\DeclareGraphicsExtensions{.ps}
\fi
It also works nicely in my references when I either use \url (PDF) or \textt (PS) for webpages.
TeXnicCenter 1RC, LEd 0.53, MikTeX 2.8, Windows XP (SP3)
Post Reply