18:07 - Thursday, 24 April 2014

Conditional “if A Package Is Available”

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

ifpackageavailable{packagefoo}usefooelseusefooreplacementfi

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}...elseusepackage{framed}newenvironment{framedbox}... fi

Is there anything that provides that kind of functionality?

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, thereforeMessageBreak      substituting command raggedright for RaggedRightMessageBreak    }%    renewcommand*{ila@RaggedRight}{raggedright}%  }%}
documentclass{article}IfFileExists{mdframed.sty}  {usepackage{mdframed}   %newenvironment{framedbox}   letframedmdframed   letendframedendmdframed  }  {usepackage{framed}   %newenvironment{framedbox}...   }begin{document}begin{framed}fooend{framed}end{document}

Share

Advertisement

Comment