Checking if certain package option is declared inside .sty











up vote
0
down vote

favorite












I'm writting a package in which the user may choose between three types of documents through declared options when issuing the usepackage command: undergraduatethesis, technicalreport and academicpaper. For this I'm using xkeyval so people use the command like usepackage[documenttype=academicpaper]{mypackage}.



I'm organizing the package in different sections, each with a type of configuration (spacing, figure configuration, titles, etc.) and I would like to put my document-type-specific commands in these separate sections, for example:



if{documenttype}{undergraduatethesis}
% do something
fi

if{documenttype}{academicpaper OR technicalreport}
% do some other thing
fi


I've tried a couple things, but I failed. The method I tried were not exactly like my situation, though.



Is this possible?



Thanks!










share|improve this question
















bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Sure. Why not? I would use boolean flags from package etoolbox.
    – Johannes_B
    Mar 25 at 1:42










  • @Johannes_B Thanks! I'm reading the etoolbox documentation right now, but how could I expain to LaTeX that the argument is the option I declared? defdocumenttype{}? I'll try this.
    – Johann Hemmer
    Mar 25 at 2:04

















up vote
0
down vote

favorite












I'm writting a package in which the user may choose between three types of documents through declared options when issuing the usepackage command: undergraduatethesis, technicalreport and academicpaper. For this I'm using xkeyval so people use the command like usepackage[documenttype=academicpaper]{mypackage}.



I'm organizing the package in different sections, each with a type of configuration (spacing, figure configuration, titles, etc.) and I would like to put my document-type-specific commands in these separate sections, for example:



if{documenttype}{undergraduatethesis}
% do something
fi

if{documenttype}{academicpaper OR technicalreport}
% do some other thing
fi


I've tried a couple things, but I failed. The method I tried were not exactly like my situation, though.



Is this possible?



Thanks!










share|improve this question
















bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Sure. Why not? I would use boolean flags from package etoolbox.
    – Johannes_B
    Mar 25 at 1:42










  • @Johannes_B Thanks! I'm reading the etoolbox documentation right now, but how could I expain to LaTeX that the argument is the option I declared? defdocumenttype{}? I'll try this.
    – Johann Hemmer
    Mar 25 at 2:04















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm writting a package in which the user may choose between three types of documents through declared options when issuing the usepackage command: undergraduatethesis, technicalreport and academicpaper. For this I'm using xkeyval so people use the command like usepackage[documenttype=academicpaper]{mypackage}.



I'm organizing the package in different sections, each with a type of configuration (spacing, figure configuration, titles, etc.) and I would like to put my document-type-specific commands in these separate sections, for example:



if{documenttype}{undergraduatethesis}
% do something
fi

if{documenttype}{academicpaper OR technicalreport}
% do some other thing
fi


I've tried a couple things, but I failed. The method I tried were not exactly like my situation, though.



Is this possible?



Thanks!










share|improve this question















I'm writting a package in which the user may choose between three types of documents through declared options when issuing the usepackage command: undergraduatethesis, technicalreport and academicpaper. For this I'm using xkeyval so people use the command like usepackage[documenttype=academicpaper]{mypackage}.



I'm organizing the package in different sections, each with a type of configuration (spacing, figure configuration, titles, etc.) and I would like to put my document-type-specific commands in these separate sections, for example:



if{documenttype}{undergraduatethesis}
% do something
fi

if{documenttype}{academicpaper OR technicalreport}
% do some other thing
fi


I've tried a couple things, but I failed. The method I tried were not exactly like my situation, though.



Is this possible?



Thanks!







conditionals package-writing package-options xkeyval






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 2:51

























asked Mar 25 at 1:00









Johann Hemmer

12




12





bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Sure. Why not? I would use boolean flags from package etoolbox.
    – Johannes_B
    Mar 25 at 1:42










  • @Johannes_B Thanks! I'm reading the etoolbox documentation right now, but how could I expain to LaTeX that the argument is the option I declared? defdocumenttype{}? I'll try this.
    – Johann Hemmer
    Mar 25 at 2:04




















  • Sure. Why not? I would use boolean flags from package etoolbox.
    – Johannes_B
    Mar 25 at 1:42










  • @Johannes_B Thanks! I'm reading the etoolbox documentation right now, but how could I expain to LaTeX that the argument is the option I declared? defdocumenttype{}? I'll try this.
    – Johann Hemmer
    Mar 25 at 2:04


















Sure. Why not? I would use boolean flags from package etoolbox.
– Johannes_B
Mar 25 at 1:42




Sure. Why not? I would use boolean flags from package etoolbox.
– Johannes_B
Mar 25 at 1:42












@Johannes_B Thanks! I'm reading the etoolbox documentation right now, but how could I expain to LaTeX that the argument is the option I declared? defdocumenttype{}? I'll try this.
– Johann Hemmer
Mar 25 at 2:04






@Johannes_B Thanks! I'm reading the etoolbox documentation right now, but how could I expain to LaTeX that the argument is the option I declared? defdocumenttype{}? I'll try this.
– Johann Hemmer
Mar 25 at 2:04












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Found an answer myself after realizing I made the mistake everyone warned me about: the placement of ProcessOptions, or, in my case ProcessOptionsX, since I'm using the xkeyval package.



I used the following bit if code to assign values to some variables in order to distinguish the three document types (for simplicity I'll call them A, B and C):



defA{A} % creates macro named A (not sure if this value matters)
defB{B} % creates macro named B
defC{C} % creates macro named C


I did that in order to later use the ifx command and compare two macros. Now, using the xkeyval package's syntax to create package options:



makeatletter
define@key{fam}{documenttype}{%
ifthenelse{equal{#1}{A}}{% if user types: documenttype=A
defdocumenttype{A}}{% assigns value "A" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{B}}{% if user types: documenttype=B
defdocumenttype{B}}{% assigns value "B" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{C}}{% if user types: documenttype=C
defdocumenttype{C}}{% assigns value "C" to documenttype macro
relax % not sure if needed
}
}
makeatother
ProcessOptionsX<fam>relax


Great, now the macro documenttype has a value defined by the user. Now, we can write codes that will be compiled only when the user has specified a certain value to documenttype, using ifx.



ifx documenttype A % check if documenttype is equal to A
% insert commands for when user chooses A
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype B % check if documenttype is equal to B
% insert commands for when user chooses B
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype C % check if documenttype is equal to C
% insert commands for when user chooses C
else % not sure if needed
relax % not sure if needed
fi

% exactly HERE is where I was placing ProcessOptionsX, shame on me!!


That's it! Now I can use any booleans!!






share|improve this answer

















  • 2




    Sorry, but just snippets aren't very helpful in a question, nor in most answers.
    – Johannes_B
    Mar 25 at 5:33










  • no, the relax should not be needed.
    – jakun
    Jun 23 at 6:31










  • What are those ifthenelse statements in the key definition good for? Why not simply defdocumenttype{#1} (or even better edefdocumenttype{#1}) instead?
    – jakun
    Jun 23 at 6:42










  • I would recommend to add a check for invalid user input to the key definition: ifxdocumenttypeA elseifxdocumenttypeB elseifxdocumenttypeC else PackageError{mypackage}{invalid value for key documenttype: documenttype}{Should be one of A, Bspace or C.}fififi
    – jakun
    Jun 23 at 6:49











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',
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%2f423024%2fchecking-if-certain-package-option-is-declared-inside-sty%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








up vote
0
down vote













Found an answer myself after realizing I made the mistake everyone warned me about: the placement of ProcessOptions, or, in my case ProcessOptionsX, since I'm using the xkeyval package.



I used the following bit if code to assign values to some variables in order to distinguish the three document types (for simplicity I'll call them A, B and C):



defA{A} % creates macro named A (not sure if this value matters)
defB{B} % creates macro named B
defC{C} % creates macro named C


I did that in order to later use the ifx command and compare two macros. Now, using the xkeyval package's syntax to create package options:



makeatletter
define@key{fam}{documenttype}{%
ifthenelse{equal{#1}{A}}{% if user types: documenttype=A
defdocumenttype{A}}{% assigns value "A" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{B}}{% if user types: documenttype=B
defdocumenttype{B}}{% assigns value "B" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{C}}{% if user types: documenttype=C
defdocumenttype{C}}{% assigns value "C" to documenttype macro
relax % not sure if needed
}
}
makeatother
ProcessOptionsX<fam>relax


Great, now the macro documenttype has a value defined by the user. Now, we can write codes that will be compiled only when the user has specified a certain value to documenttype, using ifx.



ifx documenttype A % check if documenttype is equal to A
% insert commands for when user chooses A
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype B % check if documenttype is equal to B
% insert commands for when user chooses B
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype C % check if documenttype is equal to C
% insert commands for when user chooses C
else % not sure if needed
relax % not sure if needed
fi

% exactly HERE is where I was placing ProcessOptionsX, shame on me!!


That's it! Now I can use any booleans!!






share|improve this answer

















  • 2




    Sorry, but just snippets aren't very helpful in a question, nor in most answers.
    – Johannes_B
    Mar 25 at 5:33










  • no, the relax should not be needed.
    – jakun
    Jun 23 at 6:31










  • What are those ifthenelse statements in the key definition good for? Why not simply defdocumenttype{#1} (or even better edefdocumenttype{#1}) instead?
    – jakun
    Jun 23 at 6:42










  • I would recommend to add a check for invalid user input to the key definition: ifxdocumenttypeA elseifxdocumenttypeB elseifxdocumenttypeC else PackageError{mypackage}{invalid value for key documenttype: documenttype}{Should be one of A, Bspace or C.}fififi
    – jakun
    Jun 23 at 6:49















up vote
0
down vote













Found an answer myself after realizing I made the mistake everyone warned me about: the placement of ProcessOptions, or, in my case ProcessOptionsX, since I'm using the xkeyval package.



I used the following bit if code to assign values to some variables in order to distinguish the three document types (for simplicity I'll call them A, B and C):



defA{A} % creates macro named A (not sure if this value matters)
defB{B} % creates macro named B
defC{C} % creates macro named C


I did that in order to later use the ifx command and compare two macros. Now, using the xkeyval package's syntax to create package options:



makeatletter
define@key{fam}{documenttype}{%
ifthenelse{equal{#1}{A}}{% if user types: documenttype=A
defdocumenttype{A}}{% assigns value "A" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{B}}{% if user types: documenttype=B
defdocumenttype{B}}{% assigns value "B" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{C}}{% if user types: documenttype=C
defdocumenttype{C}}{% assigns value "C" to documenttype macro
relax % not sure if needed
}
}
makeatother
ProcessOptionsX<fam>relax


Great, now the macro documenttype has a value defined by the user. Now, we can write codes that will be compiled only when the user has specified a certain value to documenttype, using ifx.



ifx documenttype A % check if documenttype is equal to A
% insert commands for when user chooses A
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype B % check if documenttype is equal to B
% insert commands for when user chooses B
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype C % check if documenttype is equal to C
% insert commands for when user chooses C
else % not sure if needed
relax % not sure if needed
fi

% exactly HERE is where I was placing ProcessOptionsX, shame on me!!


That's it! Now I can use any booleans!!






share|improve this answer

















  • 2




    Sorry, but just snippets aren't very helpful in a question, nor in most answers.
    – Johannes_B
    Mar 25 at 5:33










  • no, the relax should not be needed.
    – jakun
    Jun 23 at 6:31










  • What are those ifthenelse statements in the key definition good for? Why not simply defdocumenttype{#1} (or even better edefdocumenttype{#1}) instead?
    – jakun
    Jun 23 at 6:42










  • I would recommend to add a check for invalid user input to the key definition: ifxdocumenttypeA elseifxdocumenttypeB elseifxdocumenttypeC else PackageError{mypackage}{invalid value for key documenttype: documenttype}{Should be one of A, Bspace or C.}fififi
    – jakun
    Jun 23 at 6:49













up vote
0
down vote










up vote
0
down vote









Found an answer myself after realizing I made the mistake everyone warned me about: the placement of ProcessOptions, or, in my case ProcessOptionsX, since I'm using the xkeyval package.



I used the following bit if code to assign values to some variables in order to distinguish the three document types (for simplicity I'll call them A, B and C):



defA{A} % creates macro named A (not sure if this value matters)
defB{B} % creates macro named B
defC{C} % creates macro named C


I did that in order to later use the ifx command and compare two macros. Now, using the xkeyval package's syntax to create package options:



makeatletter
define@key{fam}{documenttype}{%
ifthenelse{equal{#1}{A}}{% if user types: documenttype=A
defdocumenttype{A}}{% assigns value "A" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{B}}{% if user types: documenttype=B
defdocumenttype{B}}{% assigns value "B" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{C}}{% if user types: documenttype=C
defdocumenttype{C}}{% assigns value "C" to documenttype macro
relax % not sure if needed
}
}
makeatother
ProcessOptionsX<fam>relax


Great, now the macro documenttype has a value defined by the user. Now, we can write codes that will be compiled only when the user has specified a certain value to documenttype, using ifx.



ifx documenttype A % check if documenttype is equal to A
% insert commands for when user chooses A
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype B % check if documenttype is equal to B
% insert commands for when user chooses B
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype C % check if documenttype is equal to C
% insert commands for when user chooses C
else % not sure if needed
relax % not sure if needed
fi

% exactly HERE is where I was placing ProcessOptionsX, shame on me!!


That's it! Now I can use any booleans!!






share|improve this answer












Found an answer myself after realizing I made the mistake everyone warned me about: the placement of ProcessOptions, or, in my case ProcessOptionsX, since I'm using the xkeyval package.



I used the following bit if code to assign values to some variables in order to distinguish the three document types (for simplicity I'll call them A, B and C):



defA{A} % creates macro named A (not sure if this value matters)
defB{B} % creates macro named B
defC{C} % creates macro named C


I did that in order to later use the ifx command and compare two macros. Now, using the xkeyval package's syntax to create package options:



makeatletter
define@key{fam}{documenttype}{%
ifthenelse{equal{#1}{A}}{% if user types: documenttype=A
defdocumenttype{A}}{% assigns value "A" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{B}}{% if user types: documenttype=B
defdocumenttype{B}}{% assigns value "B" to documenttype macro
relax % not sure if needed
}

ifthenelse{equal{#1}{C}}{% if user types: documenttype=C
defdocumenttype{C}}{% assigns value "C" to documenttype macro
relax % not sure if needed
}
}
makeatother
ProcessOptionsX<fam>relax


Great, now the macro documenttype has a value defined by the user. Now, we can write codes that will be compiled only when the user has specified a certain value to documenttype, using ifx.



ifx documenttype A % check if documenttype is equal to A
% insert commands for when user chooses A
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype B % check if documenttype is equal to B
% insert commands for when user chooses B
else % not sure if needed
relax % not sure if needed
fi

ifx documenttype C % check if documenttype is equal to C
% insert commands for when user chooses C
else % not sure if needed
relax % not sure if needed
fi

% exactly HERE is where I was placing ProcessOptionsX, shame on me!!


That's it! Now I can use any booleans!!







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 2:49









Johann Hemmer

12




12








  • 2




    Sorry, but just snippets aren't very helpful in a question, nor in most answers.
    – Johannes_B
    Mar 25 at 5:33










  • no, the relax should not be needed.
    – jakun
    Jun 23 at 6:31










  • What are those ifthenelse statements in the key definition good for? Why not simply defdocumenttype{#1} (or even better edefdocumenttype{#1}) instead?
    – jakun
    Jun 23 at 6:42










  • I would recommend to add a check for invalid user input to the key definition: ifxdocumenttypeA elseifxdocumenttypeB elseifxdocumenttypeC else PackageError{mypackage}{invalid value for key documenttype: documenttype}{Should be one of A, Bspace or C.}fififi
    – jakun
    Jun 23 at 6:49














  • 2




    Sorry, but just snippets aren't very helpful in a question, nor in most answers.
    – Johannes_B
    Mar 25 at 5:33










  • no, the relax should not be needed.
    – jakun
    Jun 23 at 6:31










  • What are those ifthenelse statements in the key definition good for? Why not simply defdocumenttype{#1} (or even better edefdocumenttype{#1}) instead?
    – jakun
    Jun 23 at 6:42










  • I would recommend to add a check for invalid user input to the key definition: ifxdocumenttypeA elseifxdocumenttypeB elseifxdocumenttypeC else PackageError{mypackage}{invalid value for key documenttype: documenttype}{Should be one of A, Bspace or C.}fififi
    – jakun
    Jun 23 at 6:49








2




2




Sorry, but just snippets aren't very helpful in a question, nor in most answers.
– Johannes_B
Mar 25 at 5:33




Sorry, but just snippets aren't very helpful in a question, nor in most answers.
– Johannes_B
Mar 25 at 5:33












no, the relax should not be needed.
– jakun
Jun 23 at 6:31




no, the relax should not be needed.
– jakun
Jun 23 at 6:31












What are those ifthenelse statements in the key definition good for? Why not simply defdocumenttype{#1} (or even better edefdocumenttype{#1}) instead?
– jakun
Jun 23 at 6:42




What are those ifthenelse statements in the key definition good for? Why not simply defdocumenttype{#1} (or even better edefdocumenttype{#1}) instead?
– jakun
Jun 23 at 6:42












I would recommend to add a check for invalid user input to the key definition: ifxdocumenttypeA elseifxdocumenttypeB elseifxdocumenttypeC else PackageError{mypackage}{invalid value for key documenttype: documenttype}{Should be one of A, Bspace or C.}fififi
– jakun
Jun 23 at 6:49




I would recommend to add a check for invalid user input to the key definition: ifxdocumenttypeA elseifxdocumenttypeB elseifxdocumenttypeC else PackageError{mypackage}{invalid value for key documenttype: documenttype}{Should be one of A, Bspace or C.}fififi
– jakun
Jun 23 at 6:49


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f423024%2fchecking-if-certain-package-option-is-declared-inside-sty%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

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt