[Tex/LaTex] How to implement a command that checks for loaded packages


I use the following code to check if a package is loaded:


However, sometimes I want to check if more than one package is loaded. Therefore I would like to generalise the command, such that more than one package can be added in a list separated with commas:

\IfPackagesLoaded{xcolor, colortbl, hyperref}{

What would the typical implementation of the processing of such a list look like?

Best Answer

You can use the LaTeX kernel's \@for macro, which processes a comma-separated list, in conjunction with an if switch. The \IfPackagesLoaded macro initially sets the switch to true, then goes through the list and sets the switch to false if a package is missing.




  \ifallloaded #2\else #3\fi}



Related Question