3

(1) What argument <arg> do I supply to \ltx@ifpackageloaded{<arg>} to specifically catch french babel?
(2) Would you mind compiling the MWE with \usepackage{siunitx} commented out. If it produces compiler error ! Undefined control sequence.<argument> \text{loaded} ...eLoaded[babel]+: \myIsPackageLoaded[babel] as it does for me, I would like to know why?!

\documentclass{minimal}
%RN. 10Aug16. MWE_17_04
\usepackage{ltxcmds}
\usepackage[frenchb,english]{babel}
%\usepackage{siunitx}
\usepackage{MyUtilities}
\begin{document}
\verb+\myIsPackageLoaded[babel]+: \myIsPackageLoaded[babel]

\verb+\myIsPackageLoaded[frenchb]+: \myIsPackageLoaded[frenchb]

\verb+\myIsPackageLoaded[french-babel]+: \myIsPackageLoaded[french-babel]     
\end{document}

\ProvidesPackage{MyUtilities}
%\usepackage{expl3}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand\myIsPackageLoaded{O{}}{\myIsPackageLoaded_Main:nn {#1}} 
\cs_new:Npn \myIsPackageLoaded_Main:nn #1
  {
    \ltx@ifpackageloaded{#1}{\text{loaded}}{\text{not~loaded}}
  }
\ExplSyntaxOff
  • 1
    Are you missing a \makeatletter...\makeatother pair needed for \ltx@ifpackageloaded? –  Aug 09 '16 at 15:50
  • A post Ryan Reich July 8/12 states that \makeatletter ...\makeatother is not required in .sty files. – Reinhard Neuwirth Aug 09 '16 at 23:20
  • asfaf `\ltx@ifpackageloaded{}{}{}' – Reinhard Neuwirth Aug 10 '16 at 04:07
  • 2
    The answer is not trivial. For the reasons explained in the babel docs, language names may refer to different things. Checking if frenchb is used as an option is not the right answer, because you can load the french language with french or francais, too. A better test is if l<@lang> and \date<lang> exist. – Javier Bezos Aug 10 '16 at 06:45
  • @ReinhardNeuwirth: True, I didn't notice the \ProvidesPackage command -- which is difficult to see, since example code and .sty are merged in your post –  Aug 10 '16 at 07:37
  • 2
    Daniel Flipo, maintainer of the A Babel language definition file for French has supplied me with following 2-liner which solves my problem perfectly and without fuss: \ifdefined\frenchbsetup \shorthandoff{;} % \shorthandon{;} \fi – Reinhard Neuwirth Aug 11 '16 at 04:54
  • @ChristianHupfer I am struggling with the editing features of TeX-Exchange and would be happy to adopt your advise on how, in future, to separate .tex and .sty components. – Reinhard Neuwirth Aug 11 '16 at 07:14
  • @ReinhardNeuwirth: Just write some line in real text, without indentation between the code parts, e.g. ... and here is the package code –  Aug 11 '16 at 07:48

1 Answers1

2

LaTeX has built-in support for this. See for example this post of which is what you're looking for: Test if a package (or package option) is loaded