0

I suppose there is some reason why the command \@ifpackageloaded is not just called \ifpackageloaded

But with the @ one has some additional work:

\makeatletter
\@ifpackageloaded{geometry}
 {                               % i the package was loaded 
    \newcommand*{\qw}{\itshape}  % this is enabled, else is not enabled.                                                                                               
 }{}
\makeatother

Is it a security feature?

16
  • 3
    Not an answer, but you can use \IfPackageLoadedTF{<package>}{<true code>}{<false code>} without \makeatletter (it is equivalent to \@ifpackageloaded)
    – mbert
    Oct 23, 2023 at 1:14
  • 1
    why would you ever need this command with \makeatletter ???? Oct 23, 2023 at 7:43
  • 1
    you don't need to test for a package in the document preamble as it is explicitly there or not. you do need to test in a package code to see if another package has been loaded, but there you don't need \makeatletter as @ is allowed automatically. Oct 23, 2023 at 7:51
  • 3
    I can not think of any possible use of \@ifpackageloaded in a document preamble, the document is a single entity the package is used or not, no need to test for it. this is not like package A which might need to test for package B being loaded. But your comment about @ only applies to the first case that should never happen. Oct 24, 2023 at 12:59
  • 1
    @user2609605 this is a package level command so has a name matching these guidelines: tex.stackexchange.com/questions/48195/… Oct 24, 2023 at 13:04

1 Answer 1

4

LaTeX2e defines functions such as \@ifpackageloaded as "non-user-facing": they are only intended for use inside packages or classes, and users writing documents should not rely on them. It also makes it very difficult to redefine such commands, particularly without knowing one is doing so.

Basically, if the macro has "@" in it, only people who really know what they are doing should be using it, much less redefining it. In particular, a user writing a document unwittingly redefining something used internally by the LaTeX kernel or a package would be a bad idea, and the @ convention precludes that possibility.

Another reason for the "@" convention is to avoid name conflicts, particularly with other commands the user might want to use.

4
  • 2
    If users should not rely on them, how can class and package authors? Usually 'cannot rely on' means the internal implementation may change, so relying on it risks depending on something which vanishes in a later version. But, if that's so, nobody should rely on them and the only classes/packages which should use them would be those which are part of LaTeX itself.
    – cfr
    Oct 23, 2023 at 3:33
  • 2
    You might want to point out that the picture you're painting is not one anybody familiar with the current landscape would recognise. This may have been the intention, but it didn't work. Almost everyone uses @ because almost everyone needs something they can't access any other way. And name conflicts are rife. Suggesting only people who really know what they are doing should use any macro with @ simply ignores reality.
    – cfr
    Oct 23, 2023 at 3:36
  • 1
    @cfr Feel free to give a better answer.
    – karlh
    Oct 23, 2023 at 4:32
  • 1
    although this is the accepted answer, davids reference to the naming convention is more general. Oct 24, 2023 at 13:17

Not the answer you're looking for? Browse other questions tagged .