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?

David Carlisle
  • 757,742
  • Related (duplicate?): https://tex.stackexchange.com/q/8351/107497 – Teepeemm Oct 23 '23 at 01:08
  • 3
    Not an answer, but you can use \IfPackageLoadedTF{<package>}{<true code>}{<false code>} without \makeatletter (it is equivalent to \@ifpackageloaded) – mbert Oct 23 '23 at 01:14
  • 1
    why would you ever need this command with \makeatletter ???? – David Carlisle Oct 23 '23 at 07: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. – David Carlisle Oct 23 '23 at 07:51
  • @teepmeemm: I dont think it is a duplicate. The other thread is about catcode. – user2609605 Oct 24 '23 at 12:56
  • @david: Hm.. i am confused. – user2609605 Oct 24 '23 at 12:57
  • 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. – David Carlisle Oct 24 '23 at 12:59
  • 1
    @user2609605 this is a package level command so has a name matching these guidelines: https://tex.stackexchange.com/questions/48195/macro-naming-best-practice/48207#48207 – David Carlisle Oct 24 '23 at 13:04
  • @david: Hm.. i am confused. Just a.\@ifpackageloaded{beamer}{a}{b} interprets \@ as one command, which is sth about spacing. Only if @ is a letter, the whole @ifpackageloaded is a single command. – user2609605 Oct 24 '23 at 13:13
  • @david: the possible use is a bit special: I want to unify the loaded packages. Thus I provide a header file performing the generic loading. Now I have the choice to write a separate header file for each situation, I may also create this or, and thats what I do, I make variants based on the packages and classes loaded. – user2609605 Oct 24 '23 at 13:15
  • @david: thank you for pointing to the naming convention. This clarifies all. – user2609605 Oct 24 '23 at 13:16
  • yes but (apart from the fact that beamer is a class not a package) why would you ever need to do that in a document. If the document starts beamer it's true if it doesn't it's false, the test itself is not useful. – David Carlisle Oct 24 '23 at 13:18
  • 1
    Your generaic loader should be a package and so you don't need \makeatletter and using commands with @ is as easy as using ones without. – David Carlisle Oct 24 '23 at 13:19
  • @user2609605 BTW, the username has to match exactly in order to have @ notifying work. It's easiest to type the @ and then the first few letters and then tab complete the username. Just @david won't work, and you misspelled mine up above. – Teepeemm Oct 24 '23 at 13:42
  • @tee You're sure? https://meta.stackexchange.com/a/43020/237989 – samcarter_is_at_topanswers.xyz Oct 24 '23 at 16:04
  • @mbert: your hint with \IfPackageLoadedTF is useful. avoids catcode fiddling. Also I can use \IfClassLoadedTF analogously. – user2609605 Oct 27 '23 at 12:28

1 Answers1

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.

karlh
  • 640
  • 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 '23 at 03: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 '23 at 03:36
  • 1
    @cfr Feel free to give a better answer. – karlh Oct 23 '23 at 04:32
  • 1
    although this is the accepted answer, davids reference to the naming convention is more general. – user2609605 Oct 24 '23 at 13:17