# How to write a LaTeX command that could discriminate if it's being called with pdfLaTeX in order to use PSTricks?

I'm writing a class for LaTeX, and I need to make it general. I want to include a simple image, a logo, within the class, which would be inserted into the document as a simple command \insertCompanyLogo. To avoid extra files, I added the PostScript definition of the logo in the .sty file.

% Include PSTricks package
\usepackage{pstricks}
% Create new command to insert logo
\newcommand{\insertCompanyLogo}{
\psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
\begin{pspicture}(180,180)
\psline(0,0)(180,180) %The actual image is far more complex
\end{pspicture}
}


This works good when I compile the document with latex <filename>. However, it fails when I try to use pdflatex.

In order to use PSTricks with pdflatex, some modifications are required. For example, I can add in the .sty file \usepackage[pdf]{pstricks}.

Then compile the document using pdflatex -shell-escape <filename>. But this won't be general, and it won't work using the regular latex command.

My question is: Is there any way to define a command that understand if the document is being compiled with pdflatex or latex? That way I can add a couple of \ifthenelse{}{}{} to the include line of PSTricks. Thus, the document that uses this .sty class and calls the \insertCompanyLogo could be compiled with both commands without any modification.

I hope I was clear enough. And any solution, tip, recommendation or workaround, as always, is more than welcome.

EDIT: Forgot to mention, I think that packages like xelatex and asymptote that could make this easier. But I would like this to work with a standard TexLive or MiKTeX installation, which is probably what 95% of the users of this class will have installed

EDIT 2: This question was marked as duplicate. The other questions address the engine issue (pdflatex vs. latex). Helpful information. But they leave out the PSTricks part, and how to make its use flexible and multi-engine, and that was the reason of my question.

EDIT 3: At the end, I opted for a completely different solution. What I wanted was to put a logo with a macro that works with both engines, latex and pdflatex. I used TiKz

\documentclass{article}
% Include package TiKz
\includepackage{tikz}
% Create new command to insert logo
\newcommand{\insertCompanyLogo}{
\begin{tikzpicture}
\draw[thick,rounded corners=8pt] (0,0) -- (0,2) -- (1,3.25)
-- (2,2) -- (2,0) -- (0,2) -- (2,2) -- (0,0) -- (2,0);
\end{tikzpicture}
}
\begin{document}
\insertCompanyLogo
\end{document}


The actual logo, and the contents of the tikzpicture environment, I got them from Inkscape, with an extension to export to TiKz format.

-

## migrated from stackoverflow.comMay 1 '14 at 3:29

This question came from our site for professional and enthusiast programmers.

I think that ifpdf should help. –  Masroor May 1 '14 at 3:34
Things are confused here. @MMA is right about \usepackage{ifpdf} for distinguishing between (say) using latex vs pdflatex. There is also \usepackage{ifplatform} for conditionals based on the OS; and \usepackage{ifxetex} and \usepackage{ifluatex} for when you want to do special things depending on which engine you wish to use (the XeTeX engine and the related xelatex command are not packages). Between ifplatform, ifpdf, ifluatex, and ifxetex, you're pretty much covered, I think.... –  jon May 1 '14 at 3:50
Thanks guys. That definitely will help. @Werner: Sorry for posting the question in the wrong forum. Won't happen again –  phollox May 1 '14 at 4:33
Possible duplicates: Detect which TeX engine is used and Conditional typesetting / build –  Werner May 1 '14 at 4:46
That is not a dublicate because it belongs to using PSTricks which is not answered. –  Herbert May 1 '14 at 6:17

That is a bit tricky because \ifpdf cannot be used with xelatex which allows PSTricks code. The following example works with latex, pdflatex, xelatex, and lualatex:

\documentclass{article}
\usepackage{ifpdf}
\providecommand\insertCompanyLogo{}
\newif\ifPSTricks \PSTrickstrue
\usepackage{ifxetex}
\ifpdf
\PSTricksfalse
\ifxetex\PSTrickstrue\fi
\fi

\ifPSTricks
% Include PSTricks package
\usepackage{pstricks}
% Create new command to insert logo
\renewcommand\insertCompanyLogo{%
\psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
\begin{pspicture}(180,180)
\psline(0,0)(180,180) %The actual image is far more complex
\end{pspicture}}
\fi

\begin{document}

PSTricks code is \ifPSTricks\else not \fi possible: \insertCompanyLogo

\end{document}

-
Thanks @Herbert for the answer. It solves the issue stated in my question. I was actually trying to make PStricks works with different engines, not run it conditionally. But I didn't say it on my question. I did a bit more of research and found TikZ. I converted my logo into this format, using an Inkscape extension, put it into my class, and now \insertCompanyLogo works like a charm in pdflatex and latex. Now, should I edit my question with this TikZ info? Or should I leave it like that? –  phollox May 2 '14 at 21:18