Process LaTeX code only if package is loaded The 2019 Stack Overflow Developer Survey Results Are InWhat do makeatletter and makeatother do?Why is the wrong version of a package being loaded?Did I install a package successfully?LaTeX Errors: “RequirePackage or LoadClass in Options Section.” AND “File 'article.cls' not found.”Unload a LaTeX packageKantlipsum installation processApplying options to already loaded packagePretending a package has been loadedPackage won't get loadedusetikzlibrarypositioning in an expl3 package but PGF Math Error: Unknown function `of'mcode package with java code

Apparent duplicates between Haynes service instructions and MOT

Is a "Democratic" Feudal System Possible?

Can you compress metal and what would be the consequences?

"as much details as you can remember"

Are there any other methods to apply to solving simultaneous equations?

Can a flute soloist sit?

Why is the maximum length of OpenWrt’s root password 8 characters?

Time travel alters history but people keep saying nothing's changed

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Right tool to dig six foot holes?

Who coined the term "madman theory"?

How to manage monthly salary

Why do UK politicians seemingly ignore opinion polls on Brexit?

Have you ever entered Singapore using a different passport or name?

Why isn't airport relocation done gradually?

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

Identify This Plant (Flower)

How to support a colleague who finds meetings extremely tiring?

Output the Arecibo Message

What is the formula behind each level spell slot progression that I can use in a spreadsheet?

Identify boardgame from Big movie

Is an up-to-date browser secure on an out-of-date OS?

Can someone be penalized for an "unlawful" act if no penalty is specified?

How technical should a Scrum Master be to effectively remove impediments?



Process LaTeX code only if package is loaded



The 2019 Stack Overflow Developer Survey Results Are InWhat do makeatletter and makeatother do?Why is the wrong version of a package being loaded?Did I install a package successfully?LaTeX Errors: “RequirePackage or LoadClass in Options Section.” AND “File 'article.cls' not found.”Unload a LaTeX packageKantlipsum installation processApplying options to already loaded packagePretending a package has been loadedPackage won't get loadedusetikzlibrarypositioning in an expl3 package but PGF Math Error: Unknown function `of'mcode package with java code










4















I would like to create a document used to test diverse packages, and I was wondering if it was possible to use a command so that part of the code is read only if the corresponding package is loaded. I've come up with this but it throws an error which I don't know how to fix.



documentclassarticle
usepackage[utf8]inputenc

makeatletter
newcommandIfPackageLoaded[3]@ifpackageloaded#1#2#3
makeatother

begindocument
IfPackageLoadednatbibnatbib loadednatbib not loaded
enddocument


I get this error:



! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.10 IfPackageLoadednatbibnatbib loaded
natbib not loaded
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.


I also know that the command ltx@ifpackageloaded exists when loading the package ltxcmds but when I try to use it in



documentclassarticle
usepackage[utf8]inputenc
usepackageltxcmds

begindocument
ltx@ifpackageloadednatbibnatbib loadednatbib not loaded
enddocument


I get this error message:



! Undefined control sequence.
l.11 ltx
@ifpackageloadednatbibnatbib loadednatbib not loaded
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.


Can someone please point out what I did wrong?



EDIT: changed documentclass from minimal to article.










share|improve this question









New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2





    You are missing the makeatletter in your second example. And don't use the minimal class, normally it is too minimal.

    – Ulrike Fischer
    12 hours ago












  • Read more: tex.stackexchange.com/q/8351/156344

    – JouleV
    12 hours ago











  • It is said in the ltxcmds documentation that ltx@ifpackageloaded can be used after begindocument though.

    – lashoun
    12 hours ago












  • But even then it can only be used if you wrap it in makeatletter...makeatother because it has an @ in its name.

    – moewe
    12 hours ago












  • Oooh, that's why! I'll try then.

    – lashoun
    12 hours ago















4















I would like to create a document used to test diverse packages, and I was wondering if it was possible to use a command so that part of the code is read only if the corresponding package is loaded. I've come up with this but it throws an error which I don't know how to fix.



documentclassarticle
usepackage[utf8]inputenc

makeatletter
newcommandIfPackageLoaded[3]@ifpackageloaded#1#2#3
makeatother

begindocument
IfPackageLoadednatbibnatbib loadednatbib not loaded
enddocument


I get this error:



! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.10 IfPackageLoadednatbibnatbib loaded
natbib not loaded
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.


I also know that the command ltx@ifpackageloaded exists when loading the package ltxcmds but when I try to use it in



documentclassarticle
usepackage[utf8]inputenc
usepackageltxcmds

begindocument
ltx@ifpackageloadednatbibnatbib loadednatbib not loaded
enddocument


I get this error message:



! Undefined control sequence.
l.11 ltx
@ifpackageloadednatbibnatbib loadednatbib not loaded
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.


Can someone please point out what I did wrong?



EDIT: changed documentclass from minimal to article.










share|improve this question









New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2





    You are missing the makeatletter in your second example. And don't use the minimal class, normally it is too minimal.

    – Ulrike Fischer
    12 hours ago












  • Read more: tex.stackexchange.com/q/8351/156344

    – JouleV
    12 hours ago











  • It is said in the ltxcmds documentation that ltx@ifpackageloaded can be used after begindocument though.

    – lashoun
    12 hours ago












  • But even then it can only be used if you wrap it in makeatletter...makeatother because it has an @ in its name.

    – moewe
    12 hours ago












  • Oooh, that's why! I'll try then.

    – lashoun
    12 hours ago













4












4








4








I would like to create a document used to test diverse packages, and I was wondering if it was possible to use a command so that part of the code is read only if the corresponding package is loaded. I've come up with this but it throws an error which I don't know how to fix.



documentclassarticle
usepackage[utf8]inputenc

makeatletter
newcommandIfPackageLoaded[3]@ifpackageloaded#1#2#3
makeatother

begindocument
IfPackageLoadednatbibnatbib loadednatbib not loaded
enddocument


I get this error:



! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.10 IfPackageLoadednatbibnatbib loaded
natbib not loaded
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.


I also know that the command ltx@ifpackageloaded exists when loading the package ltxcmds but when I try to use it in



documentclassarticle
usepackage[utf8]inputenc
usepackageltxcmds

begindocument
ltx@ifpackageloadednatbibnatbib loadednatbib not loaded
enddocument


I get this error message:



! Undefined control sequence.
l.11 ltx
@ifpackageloadednatbibnatbib loadednatbib not loaded
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.


Can someone please point out what I did wrong?



EDIT: changed documentclass from minimal to article.










share|improve this question









New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I would like to create a document used to test diverse packages, and I was wondering if it was possible to use a command so that part of the code is read only if the corresponding package is loaded. I've come up with this but it throws an error which I don't know how to fix.



documentclassarticle
usepackage[utf8]inputenc

makeatletter
newcommandIfPackageLoaded[3]@ifpackageloaded#1#2#3
makeatother

begindocument
IfPackageLoadednatbibnatbib loadednatbib not loaded
enddocument


I get this error:



! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.10 IfPackageLoadednatbibnatbib loaded
natbib not loaded
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.


I also know that the command ltx@ifpackageloaded exists when loading the package ltxcmds but when I try to use it in



documentclassarticle
usepackage[utf8]inputenc
usepackageltxcmds

begindocument
ltx@ifpackageloadednatbibnatbib loadednatbib not loaded
enddocument


I get this error message:



! Undefined control sequence.
l.11 ltx
@ifpackageloadednatbibnatbib loadednatbib not loaded
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.


Can someone please point out what I did wrong?



EDIT: changed documentclass from minimal to article.







packages






share|improve this question









New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 12 hours ago







lashoun













New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 12 hours ago









lashounlashoun

615




615




New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 2





    You are missing the makeatletter in your second example. And don't use the minimal class, normally it is too minimal.

    – Ulrike Fischer
    12 hours ago












  • Read more: tex.stackexchange.com/q/8351/156344

    – JouleV
    12 hours ago











  • It is said in the ltxcmds documentation that ltx@ifpackageloaded can be used after begindocument though.

    – lashoun
    12 hours ago












  • But even then it can only be used if you wrap it in makeatletter...makeatother because it has an @ in its name.

    – moewe
    12 hours ago












  • Oooh, that's why! I'll try then.

    – lashoun
    12 hours ago












  • 2





    You are missing the makeatletter in your second example. And don't use the minimal class, normally it is too minimal.

    – Ulrike Fischer
    12 hours ago












  • Read more: tex.stackexchange.com/q/8351/156344

    – JouleV
    12 hours ago











  • It is said in the ltxcmds documentation that ltx@ifpackageloaded can be used after begindocument though.

    – lashoun
    12 hours ago












  • But even then it can only be used if you wrap it in makeatletter...makeatother because it has an @ in its name.

    – moewe
    12 hours ago












  • Oooh, that's why! I'll try then.

    – lashoun
    12 hours ago







2




2





You are missing the makeatletter in your second example. And don't use the minimal class, normally it is too minimal.

– Ulrike Fischer
12 hours ago






You are missing the makeatletter in your second example. And don't use the minimal class, normally it is too minimal.

– Ulrike Fischer
12 hours ago














Read more: tex.stackexchange.com/q/8351/156344

– JouleV
12 hours ago





Read more: tex.stackexchange.com/q/8351/156344

– JouleV
12 hours ago













It is said in the ltxcmds documentation that ltx@ifpackageloaded can be used after begindocument though.

– lashoun
12 hours ago






It is said in the ltxcmds documentation that ltx@ifpackageloaded can be used after begindocument though.

– lashoun
12 hours ago














But even then it can only be used if you wrap it in makeatletter...makeatother because it has an @ in its name.

– moewe
12 hours ago






But even then it can only be used if you wrap it in makeatletter...makeatother because it has an @ in its name.

– moewe
12 hours ago














Oooh, that's why! I'll try then.

– lashoun
12 hours ago





Oooh, that's why! I'll try then.

– lashoun
12 hours ago










1 Answer
1






active

oldest

votes


















4














As users Ulrike Fischer and moewe pointed out, this works:



documentclassarticle
usepackage[utf8]inputenc
usepackageltxcmds

makeatletter
newcommandIfPackageLoaded[3]ltx@ifpackageloaded#1#2#3
makeatother

begindocument
IfPackageLoadednatbibnatbib loadednatbib not loaded
enddocument





share|improve this answer










New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2





    BTW: The [3] is not needed. You can simply use newcommand*IfPackageLoadedltx@ifpackageloaded.

    – Schweinebacke
    11 hours ago












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    11 hours ago











  • @egreg Yes, because ltx@ifpackageloaded is a simple macro. If it would be, e.g., robust, it could be better to use LetLtxMacro from package letltxmacro. I didn't want to explain all this, so I've only noted about using newcommand* without arguments.

    – Schweinebacke
    11 hours ago












  • Thanks for the precisions

    – lashoun
    9 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






lashoun is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f484088%2fprocess-latex-code-only-if-package-is-loaded%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














As users Ulrike Fischer and moewe pointed out, this works:



documentclassarticle
usepackage[utf8]inputenc
usepackageltxcmds

makeatletter
newcommandIfPackageLoaded[3]ltx@ifpackageloaded#1#2#3
makeatother

begindocument
IfPackageLoadednatbibnatbib loadednatbib not loaded
enddocument





share|improve this answer










New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2





    BTW: The [3] is not needed. You can simply use newcommand*IfPackageLoadedltx@ifpackageloaded.

    – Schweinebacke
    11 hours ago












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    11 hours ago











  • @egreg Yes, because ltx@ifpackageloaded is a simple macro. If it would be, e.g., robust, it could be better to use LetLtxMacro from package letltxmacro. I didn't want to explain all this, so I've only noted about using newcommand* without arguments.

    – Schweinebacke
    11 hours ago












  • Thanks for the precisions

    – lashoun
    9 hours ago















4














As users Ulrike Fischer and moewe pointed out, this works:



documentclassarticle
usepackage[utf8]inputenc
usepackageltxcmds

makeatletter
newcommandIfPackageLoaded[3]ltx@ifpackageloaded#1#2#3
makeatother

begindocument
IfPackageLoadednatbibnatbib loadednatbib not loaded
enddocument





share|improve this answer










New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2





    BTW: The [3] is not needed. You can simply use newcommand*IfPackageLoadedltx@ifpackageloaded.

    – Schweinebacke
    11 hours ago












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    11 hours ago











  • @egreg Yes, because ltx@ifpackageloaded is a simple macro. If it would be, e.g., robust, it could be better to use LetLtxMacro from package letltxmacro. I didn't want to explain all this, so I've only noted about using newcommand* without arguments.

    – Schweinebacke
    11 hours ago












  • Thanks for the precisions

    – lashoun
    9 hours ago













4












4








4







As users Ulrike Fischer and moewe pointed out, this works:



documentclassarticle
usepackage[utf8]inputenc
usepackageltxcmds

makeatletter
newcommandIfPackageLoaded[3]ltx@ifpackageloaded#1#2#3
makeatother

begindocument
IfPackageLoadednatbibnatbib loadednatbib not loaded
enddocument





share|improve this answer










New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










As users Ulrike Fischer and moewe pointed out, this works:



documentclassarticle
usepackage[utf8]inputenc
usepackageltxcmds

makeatletter
newcommandIfPackageLoaded[3]ltx@ifpackageloaded#1#2#3
makeatother

begindocument
IfPackageLoadednatbibnatbib loadednatbib not loaded
enddocument






share|improve this answer










New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer








edited 11 hours ago









Schweinebacke

22.5k4577




22.5k4577






New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered 12 hours ago









lashounlashoun

615




615




New contributor




lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






lashoun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 2





    BTW: The [3] is not needed. You can simply use newcommand*IfPackageLoadedltx@ifpackageloaded.

    – Schweinebacke
    11 hours ago












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    11 hours ago











  • @egreg Yes, because ltx@ifpackageloaded is a simple macro. If it would be, e.g., robust, it could be better to use LetLtxMacro from package letltxmacro. I didn't want to explain all this, so I've only noted about using newcommand* without arguments.

    – Schweinebacke
    11 hours ago












  • Thanks for the precisions

    – lashoun
    9 hours ago












  • 2





    BTW: The [3] is not needed. You can simply use newcommand*IfPackageLoadedltx@ifpackageloaded.

    – Schweinebacke
    11 hours ago












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    11 hours ago











  • @egreg Yes, because ltx@ifpackageloaded is a simple macro. If it would be, e.g., robust, it could be better to use LetLtxMacro from package letltxmacro. I didn't want to explain all this, so I've only noted about using newcommand* without arguments.

    – Schweinebacke
    11 hours ago












  • Thanks for the precisions

    – lashoun
    9 hours ago







2




2





BTW: The [3] is not needed. You can simply use newcommand*IfPackageLoadedltx@ifpackageloaded.

– Schweinebacke
11 hours ago






BTW: The [3] is not needed. You can simply use newcommand*IfPackageLoadedltx@ifpackageloaded.

– Schweinebacke
11 hours ago














@Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

– egreg
11 hours ago





@Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

– egreg
11 hours ago













@egreg Yes, because ltx@ifpackageloaded is a simple macro. If it would be, e.g., robust, it could be better to use LetLtxMacro from package letltxmacro. I didn't want to explain all this, so I've only noted about using newcommand* without arguments.

– Schweinebacke
11 hours ago






@egreg Yes, because ltx@ifpackageloaded is a simple macro. If it would be, e.g., robust, it could be better to use LetLtxMacro from package letltxmacro. I didn't want to explain all this, so I've only noted about using newcommand* without arguments.

– Schweinebacke
11 hours ago














Thanks for the precisions

– lashoun
9 hours ago





Thanks for the precisions

– lashoun
9 hours ago










lashoun is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















lashoun is a new contributor. Be nice, and check out our Code of Conduct.












lashoun is a new contributor. Be nice, and check out our Code of Conduct.











lashoun is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f484088%2fprocess-latex-code-only-if-package-is-loaded%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:Fedor von Bock Media in category "Fedor von Bock"Navigation menuUpload mediaISNI: 0000 0000 5511 3417VIAF ID: 24712551GND ID: 119294796Library of Congress authority ID: n96068363BnF ID: 12534305fSUDOC authorities ID: 034604189Open Library ID: OL338253ANKCR AUT ID: jn19990000869National Library of Israel ID: 000514068National Thesaurus for Author Names ID: 341574317ReasonatorScholiaStatistics

Reverse int within the 32-bit signed integer range: [−2^31, 2^31 − 1]Combining two 32-bit integers into one 64-bit integerDetermine if an int is within rangeLossy packing 32 bit integer to 16 bitComputing the square root of a 64-bit integerKeeping integer addition within boundsSafe multiplication of two 64-bit signed integersLeetcode 10: Regular Expression MatchingSigned integer-to-ascii x86_64 assembler macroReverse the digits of an Integer“Add two numbers given in reverse order from a linked list”

Kiel Indholdsfortegnelse Historie | Transport og færgeforbindelser | Sejlsport og anden sport | Kultur | Kendte personer fra Kiel | Noter | Litteratur | Eksterne henvisninger | Navigationsmenuwww.kiel.de54°19′31″N 10°8′26″Ø / 54.32528°N 10.14056°Ø / 54.32528; 10.14056Oberbürgermeister Dr. Ulf Kämpferwww.statistik-nord.deDen danske Stats StatistikKiels hjemmesiderrrWorldCat312794080n790547494030481-4