Process LaTeX code only if package is loaded Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)What 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

Is it cost-effective to upgrade an old-ish Giant Escape R3 commuter bike with entry-level branded parts (wheels, drivetrain)?

How could we fake a moon landing now?

What do you call a floor made of glass so you can see through the floor?

Is there any way for the UK Prime Minister to make a motion directly dependent on Government confidence?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

Does classifying an integer as a discrete log require it be part of a multiplicative group?

また usage in a dictionary

Is it a good idea to use CNN to classify 1D signal?

If my PI received research grants from a company to be able to pay my postdoc salary, did I have a potential conflict interest too?

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

How to tell that you are a giant?

Delete nth line from bottom

Did MS DOS itself ever use blinking text?

Fantasy story; one type of magic grows in power with use, but the more powerful they are, they more they are drawn to travel to their source

Do I really need recursive chmod to restrict access to a folder?

Why aren't air breathing engines used as small first stages

When the Haste spell ends on a creature, do attackers have advantage against that creature?

Why are there no cargo aircraft with "flying wing" design?

Can a new player join a group only when a new campaign starts?

Why do we bend a book to keep it straight?

Significance of Cersei's obsession with elephants?

Why does the resolve message appear first?

2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?

Integration Help



Process LaTeX code only if package is loaded



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)What 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










5















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



















  • 3





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

    – Ulrike Fischer
    Apr 10 at 9:52












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

    – JouleV
    Apr 10 at 9:53











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

    – lashoun
    Apr 10 at 9:58












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

    – moewe
    Apr 10 at 9:59












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

    – lashoun
    Apr 10 at 10:00















5















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



















  • 3





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

    – Ulrike Fischer
    Apr 10 at 9:52












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

    – JouleV
    Apr 10 at 9:53











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

    – lashoun
    Apr 10 at 9:58












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

    – moewe
    Apr 10 at 9:59












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

    – lashoun
    Apr 10 at 10:00













5












5








5








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
















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















share|improve this question













share|improve this question




share|improve this question








edited Apr 10 at 10:03







lashoun

















asked Apr 10 at 9:46









lashounlashoun

665




665







  • 3





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

    – Ulrike Fischer
    Apr 10 at 9:52












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

    – JouleV
    Apr 10 at 9:53











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

    – lashoun
    Apr 10 at 9:58












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

    – moewe
    Apr 10 at 9:59












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

    – lashoun
    Apr 10 at 10:00












  • 3





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

    – Ulrike Fischer
    Apr 10 at 9:52












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

    – JouleV
    Apr 10 at 9:53











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

    – lashoun
    Apr 10 at 9:58












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

    – moewe
    Apr 10 at 9:59












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

    – lashoun
    Apr 10 at 10:00







3




3





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

– Ulrike Fischer
Apr 10 at 9:52






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

– Ulrike Fischer
Apr 10 at 9:52














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

– JouleV
Apr 10 at 9:53





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

– JouleV
Apr 10 at 9:53













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

– lashoun
Apr 10 at 9:58






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

– lashoun
Apr 10 at 9:58














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

– moewe
Apr 10 at 9:59






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

– moewe
Apr 10 at 9:59














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

– lashoun
Apr 10 at 10:00





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

– lashoun
Apr 10 at 10:00










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




















  • 3





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

    – Schweinebacke
    Apr 10 at 10:08












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    Apr 10 at 10:43






  • 1





    @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
    Apr 10 at 10:47












  • Thanks for the precisions

    – lashoun
    Apr 10 at 12:10











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
);



);













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




















  • 3





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

    – Schweinebacke
    Apr 10 at 10:08












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    Apr 10 at 10:43






  • 1





    @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
    Apr 10 at 10:47












  • Thanks for the precisions

    – lashoun
    Apr 10 at 12:10















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




















  • 3





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

    – Schweinebacke
    Apr 10 at 10:08












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    Apr 10 at 10:43






  • 1





    @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
    Apr 10 at 10:47












  • Thanks for the precisions

    – lashoun
    Apr 10 at 12:10













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















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














share|improve this answer



share|improve this answer








edited Apr 10 at 10:06









Schweinebacke

22.8k4578




22.8k4578










answered Apr 10 at 10:02









lashounlashoun

665




665







  • 3





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

    – Schweinebacke
    Apr 10 at 10:08












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    Apr 10 at 10:43






  • 1





    @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
    Apr 10 at 10:47












  • Thanks for the precisions

    – lashoun
    Apr 10 at 12:10












  • 3





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

    – Schweinebacke
    Apr 10 at 10:08












  • @Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

    – egreg
    Apr 10 at 10:43






  • 1





    @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
    Apr 10 at 10:47












  • Thanks for the precisions

    – lashoun
    Apr 10 at 12:10







3




3





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

– Schweinebacke
Apr 10 at 10:08






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

– Schweinebacke
Apr 10 at 10:08














@Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

– egreg
Apr 10 at 10:43





@Schweinebacke RIght; also letIfPackageLoadedltx@ifpackageloaded

– egreg
Apr 10 at 10:43




1




1





@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
Apr 10 at 10:47






@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
Apr 10 at 10:47














Thanks for the precisions

– lashoun
Apr 10 at 12:10





Thanks for the precisions

– lashoun
Apr 10 at 12:10

















draft saved

draft discarded
















































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

រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output

PDF-ში გადმოწერა სანავიგაციო მენიუproject page