2

I need to introduce in my preamble a conditional structure to load a package if its complete version is installed, load its light version if it exists, or load some standard package otherwise. The need to do this is that I have to forward the code to some other person and I don't know the specs of her latex installation. The package is mtpro2, that can be loaded with or without the “lite” option (“lite” is free, complete is not).

To check whether a package exists is simple (use \IfFileExists). To check whether a package is loaded with a certain property set is simple too (use ifpackagewith). But how can I check whether the package is installed in its full version or light one?

My current structure attempts a workaround, which is to check some font that is available in the full version only. But strangely enough it seems that this doesn't work properly. In any case this approach cannot be extended to other packages, therefore I think my question is valuable in more general case.

\IfFileExists{mtpro2.sty}{%this checks whether mtpro2 is installed
\IfFileExists{umt2hrb.fd}{%check whether there is this font: if the font is present, then full version is installed
    \usepackage[noamssymbols,slantedGreek,zswash,mtpscr]{mtpro2}
    }{%
    \usepackage[lite,noamssymbols,slantedGreek,zswash]{mtpro2}
    }%
}{%otherwise, load standard packages
\usepackage[cmintegrals]{newtxmath}
}%

Thanks for helping. Hope will be useful to other as well.

1

Testing for the fd-file is useless: It exists anyway, also it contains only font definitions, it is not the font itself. You need to test for a tfm and/or a pfb-font which is specific to the complete version. With pipes enabled you could do something like this (see Search for files first in the texmf trees):

\documentclass{article}
\pdfmapfile{=mtpro2.map}
\usepackage{etoolbox}
\newbool{fontexists}

\newread\mypipe
\openin\mypipe="|kpsewhich mt2syat.tfm"
\ifeof\mypipe
\else
  \begingroup
  \endlinechar=-1
  \read\mypipe to \x  
  \ifdefempty{\x}
  {\global\boolfalse{fontexists}}
  {\global\booltrue{fontexists}}
  \endgroup
\fi  
\ifbool{fontexists}
   {\usepackage[noamssymbols,slantedGreek,zswash,mtpscr]{mtpro2}}
   {\usepackage[lite,noamssymbols,slantedGreek,zswash]{mtpro2}}

\begin{document}
a $a=b$

\end{document}
  • Thanks Ulrike. This is a good solution on my computer, but what if I have to share the code with other users with very different installations? (e.g. Windows). Is there a way to program something like "load the package; if loading fails, do another thing [e.g. load another package]"? – Monte Carlo Apr 30 '16 at 10:11
  • On windows the code works too, miktex users will have to use --enable-pipes. Beside this you idea of a "package test" is too broad. mtpro2 consists of a lot of files and it is quite possible that only some are missing. – Ulrike Fischer Apr 30 '16 at 20:44
  • In the case some are missing I would regard it as failed. I am wondering how one can use the fact that there should be a warning if some option cannot be loaded. (In particular, I don't know what happens if one doesn't have the complete version of mtpro2 and tries to load it without the lite option: maybe an error?) I'll update this thread if I'll find a satisfactory way to solve the issue. Thanks for your contribution. – Monte Carlo May 2 '16 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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