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!
conditionals package-writing package-options xkeyval
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.
add a comment |
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!
conditionals package-writing package-options xkeyval
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
add a comment |
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!
conditionals package-writing package-options xkeyval
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
conditionals package-writing package-options xkeyval
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
add a comment |
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
add a comment |
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!!
2
Sorry, but just snippets aren't very helpful in a question, nor in most answers.
– Johannes_B
Mar 25 at 5:33
no, therelax
should not be needed.
– jakun
Jun 23 at 6:31
What are thoseifthenelse
statements in the key definition good for? Why not simplydefdocumenttype{#1}
(or even betteredefdocumenttype{#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
add a comment |
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!!
2
Sorry, but just snippets aren't very helpful in a question, nor in most answers.
– Johannes_B
Mar 25 at 5:33
no, therelax
should not be needed.
– jakun
Jun 23 at 6:31
What are thoseifthenelse
statements in the key definition good for? Why not simplydefdocumenttype{#1}
(or even betteredefdocumenttype{#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
add a comment |
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!!
2
Sorry, but just snippets aren't very helpful in a question, nor in most answers.
– Johannes_B
Mar 25 at 5:33
no, therelax
should not be needed.
– jakun
Jun 23 at 6:31
What are thoseifthenelse
statements in the key definition good for? Why not simplydefdocumenttype{#1}
(or even betteredefdocumenttype{#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
add a comment |
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!!
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!!
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, therelax
should not be needed.
– jakun
Jun 23 at 6:31
What are thoseifthenelse
statements in the key definition good for? Why not simplydefdocumenttype{#1}
(or even betteredefdocumenttype{#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
add a comment |
2
Sorry, but just snippets aren't very helpful in a question, nor in most answers.
– Johannes_B
Mar 25 at 5:33
no, therelax
should not be needed.
– jakun
Jun 23 at 6:31
What are thoseifthenelse
statements in the key definition good for? Why not simplydefdocumenttype{#1}
(or even betteredefdocumenttype{#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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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