7

Is there a LaTeX3 equivalent for \@ifpackageloaded?

3
  • Won't the LaTeX2 version work? May 30 '18 at 19:53
  • It works, but I thought I could have my whole file in the new syntax, at one point. Maybe that is not possible, yet.
    – mhchem
    May 30 '18 at 20:02
  • 6
    I could answer \let\ltx_if_pkg_loaded:nTF\@ifpackageloaded yes, there is now? May 30 '18 at 20:12
13

No, there isn't. But you can easily build it.

\prg_new_conditional:Nnn \mhchem_package_if_loaded:n { p, T, F , TF }
 {
  \use:c { @ifpackageloaded } { #1 } { \prg_return_true: } { \prg_return_false: }
 }

This will define the conditionals

\mhchem_package_if_loaded:nTF
\mhchem_package_if_loaded:nT
\mhchem_package_if_loaded:nF

and the predicate form

\mhchem_package_if_loaded_p:n

to be used in boolean expressions.

A test:

\documentclass{article}
\usepackage{expl3}

\ExplSyntaxOn

\prg_new_conditional:Nnn \mhchem_package_if_loaded:n { p, T, F , TF }
 {
  \use:c { @ifpackageloaded } { #1 } { \prg_return_true: } { \prg_return_false: }
 }

% now let's test it

\mhchem_package_if_loaded:nTF { expl3 }
 { \typeout{Yes~expl3} }
 { \typeout{No~expl3} }

\mhchem_package_if_loaded:nT { expl3 }
 { \typeout{Yes~expl3} }

\mhchem_package_if_loaded:nTF { kantlipsum }
 { \typeout{Yes~kantlipsum} }
 { \typeout{No~kantlipsum} }

\mhchem_package_if_loaded:nF { kantlipsum }
 { \typeout{No~kantlipsum} }

\bool_if:nTF
 {
  \mhchem_package_if_loaded_p:n {expl3}
  ||
  \mhchem_package_if_loaded_p:n {kantlipsum}
 }
 { \typeout{Yes~expl3~or~kantlipsum} }
 { \typeout{No~expl3~or~kantlipsum} }

\bool_if:nTF
 {
  \mhchem_package_if_loaded_p:n {expl3}
  &&
  \mhchem_package_if_loaded_p:n {kantlipsum}
 }
 { \typeout{Yes~expl3~and~kantlipsum} }
 { \typeout{No~expl3~and~kantlipsum} }

\stop

The relevant console output:

Yes expl3
Yes expl3
No kantlipsum
No kantlipsum
Yes expl3 or kantlipsum
No expl3 and kantlipsum

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.