Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to do something like the following (in pseudo-TeX)

\ifpackageavailable{packagefoo}
\usefoo
\else
\usefooreplacement
\fi

For example, I know that a template file I wrote is used by people who don't have the mdframed package. So I want to write:

\ifpackageavailable{mdframed}
\usepackage{mdframed}
\newenvironment{framedbox}...
\else
\usepackage{framed}
\newenvironment{framedbox}... 
\fi

Is there anything that provides that kind of functionality?

share|improve this question
add comment

2 Answers

up vote 11 down vote accepted

Use \IfFileExists. Here's a code snippet from my idxlayout package that tests for the availability of ragged2e.

\AtBeginDocument{%
  \IfFileExists{ragged2e.sty}{%
    \RequirePackage{ragged2e}%
    \renewcommand*{\ila@RaggedRight}{\RaggedRight}%
  }{%
    \PackageWarning{idxlayout}{%
      Package ragged2e not available, therefore\MessageBreak
      substituting command raggedright for RaggedRight\MessageBreak
    }%
    \renewcommand*{\ila@RaggedRight}{\raggedright}%
  }%
}
share|improve this answer
    
I added code like this to enable optional features in my packages which depend on other packages. However I got the impression that \IfFileExists already triggers MikTeX auto-install feature (I didn't do deeper tests). –  Martin Scharrer Jan 22 '13 at 22:03
add comment
\documentclass{article}

\IfFileExists{mdframed.sty}
  {\usepackage{mdframed}
   %\newenvironment{framedbox}
   \let\framed\mdframed
   \let\endframed\endmdframed
  }
  {\usepackage{framed}
   %\newenvironment{framedbox}... 
  }

\begin{document}

\begin{framed}
foo
\end{framed}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.