# Test if a package (or package option) is loaded

[french]{babel} (aka frenchb) is incompatible with some other packages, such as tikz, since it tries to insert \thinspace before semi-colons.

In order to make these two play nice, you have to call \shorthandoff{;} in the document.

Now I have a package that uses tikz and I would like to locally disable the semi-colon for babel, instead of disabling it for the whole document. I could hack the .sty of the package to do that, knowing that I'm using frenchb, but I would rather make something clean and portable.

Is there a way in my package that I can test if frenchb is loaded and disable semi-colon management with babel locally, so the package doesn't have to be hacked?

Edit:

Martin's solution gives me something like this in general:

\RequirePackage{ifthen}
}
\newcommand{\somecommandusingsemicolon}{
% code with semi-colon here
}


and in the specific case of tikz:

\AtBeginDocument{\@ifpackageloaded{babel}
{%
\shorthandoff{;}%
}
\shorthandon{;}%
}
}
{\relax}
}

-
Related (just for classes instead for packages): Which documentclass is being used?. –  Martin Scharrer Apr 19 '11 at 21:13
Instead of \ifthenelse{\@babel@loaded=1}{\shorthandoff{;}}{} just define a macro which is normally empty or \relax but defined to \shorthandoff{;} when babel is loaded. See also my tikz specific solution. –  Martin Scharrer Apr 19 '11 at 21:38
@Martin: Great, I updated my edit to reflect that. –  ℝaphink Apr 19 '11 at 21:45
make sure to mind unwanted spaces, i.e. add % at the end of the line if required. Also {\relax} doesn't really make sense, {} is just fine. –  Martin Scharrer Apr 19 '11 at 21:48
OK, thanks you. –  ℝaphink Apr 19 '11 at 21:53

You can use the internal LaTeX macro \@ifpackageloaded to test if a package was loaded:

\@ifpackageloaded{<name>}{<true>}{<false>}


There are also:

\@ifpackagewith{<name>}{<option-list>}{<true>}{<false>}
\@ifpackagelater{<name>}{<date YYYY/MM/DD>}{<true>}{<false>}


For further macro see the document linked in Documentation reference for LaTeX internal commands?.

In the case of tikz it would be best to add your code to the macros \tikz@installcommands and \tikz@uninstallcommands. The first is executed at the begin of a tikzpicture and enables all the tikz commands only defined there and the latter is executed at the begin of node content and changes the definitions back to there normal state. This way you can have French text inside the nodes.

You can add code to the macros using:

\AtBeginDocument{\@ifpackageloaded{babel}{%
\shorthandoff{;}%
}%
\shorthandon{;}%
}%
}{}


I'm just guessing here that \shorthandon is the opposite of \shorthandoff.

-
@Martin: \@ifclassloaded seems to be only usable in preamble. Is that right? –  ℝaphink Apr 19 '11 at 21:20
@Raphink: Yes, they are marked as \@onlypreamble. You would need to test for the package in question at the end of the preamble, e.g. using \AtBeginDocument{...}, and set a global flag for your document macros. –  Martin Scharrer Apr 19 '11 at 21:24
@Martin: Right. I would like to disable semi-colon management very locally, in a given macro. If I do a \AtBeginDocument, it will still affect the whole scope. –  ℝaphink Apr 19 '11 at 21:25
@Raphink: Right, that's why I wrote "set a global flag for your document macros" not "change your settings". You then use that flag locally. –  Martin Scharrer Apr 19 '11 at 21:30
@Martin: I edited the question to make an example with your proposal. Is that correct? –  ℝaphink Apr 19 '11 at 21:33