I'm creating my personal package. I'd like to use an option to turn on/off the line numbering provided by the package lineno.
So, my sty file contains
\RequirePackage{lineno}
\linenumbers
But if one does not have the lineno package installed it will produce an error. It one does have the package installed it will enumerate the lines.
I'd like to check if one does have lineno first and in affirmative case I'd like to be able to use my package as
\usepackage[lineno]{mysty} % to turn on the numbering
or
\usepackage{mysty} % default with no numbering if `lineno` does not exists
I tried this
\RequirePackage{lineno}
\@ifpackageloaded{lineno}{%
\DeclareOption{lineno}{\linenumbers}%
\ProcessOptions%
}{}
and it works if lineno is installed. But what about if it is not?
egreg's solution only tests for the file, if needed -- in my case the warning is given earlier. (I would have deleted my solution, but my answer has more remarks/hints.) – Heiko Oberdiek Apr 26 '13 at 00:14\IfFileExists{color.sty}{\RequirePackage{color}\def\alerta#1{\textcolor{red}{#1}}}{}producing the error Illegal parameter number in definition of \reserved@a {}? – Sigur Apr 26 '13 at 00:48\IfFileExistsin the LaTeX kernel. Instead of\IfFileExists{file}{yes}{no}the workaround\IfFileExists{file}\@firstoftwo\@secondoftwo{yes}{no}can be used. Here\IfFileExists{color.sty}\@firstofone\@gobble{\RequirePackage{color}\newcommand*{\alerta}[1]{\textcolor{red}{#1}}}can be used. – Heiko Oberdiek Apr 26 '13 at 01:07