How can I check if the current code is inside a certain environment?How can I check if the current code is inside a tikzpicture?Detecting if inside a tikzpictureHow to test if I'm currently in a footnote or notHow can I center arbitrary content between two horizontal lines?Checking environment in order to end itHow to access name of environment in its own definitionpassing options to the newenvironmentUse column-separator & (ampersand) inside newenvironmentHow can I create a customized environment?Environments with matched parens in begin and endAllow only certain commands in own environmentCompiler Error when Creating a Macro/EnvironmentHow can I know if I am inside an equation environment if it's nested with others?Symbol at the end of an environmentHow to delete the contents of the current paragraph and “re-start” from the beginning?Using a split environment inside every equation environment
Identify a stage play about a VR experience in which participants are encouraged to simulate performing horrific activities
Invariance of results when scaling explanatory variables in logistic regression, is there a proof?
How to prevent YouTube from showing already watched videos?
Can a malicious addon access internet history and such in chrome/firefox?
Calculating the number of days between 2 dates in Excel
Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)
Why does this part of the Space Shuttle launch pad seem to be floating in air?
Is it possible to have a strip of cold climate in the middle of a planet?
Teaching indefinite integrals that require special-casing
Modern Day Chaucer
Can the electrostatic force be infinite in magnitude?
Is there any significance to the Valyrian Stone vault door of Qarth?
How to be able to process a large JSON response?
How do I repair my stair bannister?
The most efficient algorithm to find all possible integer pairs which sum to a given integer
Freedom of speech and where it applies
Giant Toughroad SLR 2 for 200 miles in two days, will it make it?
Why is delta-v is the most useful quantity for planning space travel?
A known event to a history junkie
Can a Gentile theist be saved?
What if somebody invests in my application?
Why isn't KTEX's runway designation 10/28 instead of 9/27?
Java - What do constructor type arguments mean when placed *before* the type?
Resetting two CD4017 counters simultaneously, only one resets
How can I check if the current code is inside a certain environment?
How can I check if the current code is inside a tikzpicture?Detecting if inside a tikzpictureHow to test if I'm currently in a footnote or notHow can I center arbitrary content between two horizontal lines?Checking environment in order to end itHow to access name of environment in its own definitionpassing options to the newenvironmentUse column-separator & (ampersand) inside newenvironmentHow can I create a customized environment?Environments with matched parens in begin and endAllow only certain commands in own environmentCompiler Error when Creating a Macro/EnvironmentHow can I know if I am inside an equation environment if it's nested with others?Symbol at the end of an environmentHow to delete the contents of the current paragraph and “re-start” from the beginning?Using a split environment inside every equation environment
I would like to define a command which checks if it is executed inside a certain environment. Like this:
documentclassarticle
newenvironmentmyenv[0]at start at end
newcommandinner[0]%
% if iside a myenv
(inner)
% else
beginmyenv
(inner)%
endmyenv
% end
begindocument
beginmyenv
inner
endmyenv
inner
enddocument
See the definition of inner
. Is an if-condition of this form possible?
environments conditionals
add a comment |
I would like to define a command which checks if it is executed inside a certain environment. Like this:
documentclassarticle
newenvironmentmyenv[0]at start at end
newcommandinner[0]%
% if iside a myenv
(inner)
% else
beginmyenv
(inner)%
endmyenv
% end
begindocument
beginmyenv
inner
endmyenv
inner
enddocument
See the definition of inner
. Is an if-condition of this form possible?
environments conditionals
Related Question: Detecting if inside a tikzpicture
– Peter Grill
Nov 7 '18 at 23:30
add a comment |
I would like to define a command which checks if it is executed inside a certain environment. Like this:
documentclassarticle
newenvironmentmyenv[0]at start at end
newcommandinner[0]%
% if iside a myenv
(inner)
% else
beginmyenv
(inner)%
endmyenv
% end
begindocument
beginmyenv
inner
endmyenv
inner
enddocument
See the definition of inner
. Is an if-condition of this form possible?
environments conditionals
I would like to define a command which checks if it is executed inside a certain environment. Like this:
documentclassarticle
newenvironmentmyenv[0]at start at end
newcommandinner[0]%
% if iside a myenv
(inner)
% else
beginmyenv
(inner)%
endmyenv
% end
begindocument
beginmyenv
inner
endmyenv
inner
enddocument
See the definition of inner
. Is an if-condition of this form possible?
environments conditionals
environments conditionals
edited May 20 '11 at 14:15
lockstep
192k53593723
192k53593723
asked May 20 '11 at 8:17
Nickolay KolevNickolay Kolev
1,70641731
1,70641731
Related Question: Detecting if inside a tikzpicture
– Peter Grill
Nov 7 '18 at 23:30
add a comment |
Related Question: Detecting if inside a tikzpicture
– Peter Grill
Nov 7 '18 at 23:30
Related Question: Detecting if inside a tikzpicture
– Peter Grill
Nov 7 '18 at 23:30
Related Question: Detecting if inside a tikzpicture
– Peter Grill
Nov 7 '18 at 23:30
add a comment |
2 Answers
2
active
oldest
votes
LaTeX keeps the current environment in the macro @currenvir
makeatletter
newcommandinner%
ifx@currenvir@myenvname
(inner)
else
beginmyenv(inner)endmyenv
fi
newcommand*@myenvnamemyenv
makeatother
Another approach would be to define a global conditional that's set to true by myenv
start code and to false by myenv
end code. It depends mostly on what you are expecting from the myenv
environment: can it appear nested inside itself?
2
@Nickoley: Note that this doesn't work any longer wheninner
is used inside another environment inside themyenv
environment, e.g. beginmyenvbegincenterinnerendcenterendmyenv. Then
@currenvir` will becenter
wheninner
is expanded.
– Martin Scharrer♦
May 20 '11 at 10:28
This does not seem to work on my end. It produces the "else" output both inside and outside amyenv
environment. However, both@currenvir
and@myenvname
display the correct (and the same) output when placed inside the environment.
– Danny Hansen
29 mins ago
@DannyHansen Right: in some update during the last eight years, the LaTeX kernel changed@currenvir
to not belong
as it used to be. Fixed by adding a*
.
– egreg
20 mins ago
add a comment |
If you use pdftex
, etex
or xetex
(I mean engine), you can define a fully expandable test:
makeatletter defIfEnvir #1%
% implicit #2 "what if true"
% implicit #3 "what if false"
%
ifnum strcmp@currenvir#1=0
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
Such a conditional is defined in the gmutils
package: @ifenvir
, but there it's protected
for some reason.
If you prefer the if… … else … fi form, just replace expandafter@first/secondoftwo with your stuff, but i'd suggest the arguments-form because it's robust to unbalanced if's.
– Natror
May 20 '11 at 9:06
Please indent your code with four spaces (or use the '101010' button to do this) so that it is properly highlighted. Please don't use HTML for code formatting. Thanks.
– Martin Scharrer♦
May 20 '11 at 9:39
the command isstrcmp
in XeTeX andpdfstrcmp
in pdfTeX. One can loadpdftexcmds
and usepdf@strcmp
in all engines (including LuaTeX).
– egreg
May 20 '11 at 10:04
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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%2f18652%2fhow-can-i-check-if-the-current-code-is-inside-a-certain-environment%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
LaTeX keeps the current environment in the macro @currenvir
makeatletter
newcommandinner%
ifx@currenvir@myenvname
(inner)
else
beginmyenv(inner)endmyenv
fi
newcommand*@myenvnamemyenv
makeatother
Another approach would be to define a global conditional that's set to true by myenv
start code and to false by myenv
end code. It depends mostly on what you are expecting from the myenv
environment: can it appear nested inside itself?
2
@Nickoley: Note that this doesn't work any longer wheninner
is used inside another environment inside themyenv
environment, e.g. beginmyenvbegincenterinnerendcenterendmyenv. Then
@currenvir` will becenter
wheninner
is expanded.
– Martin Scharrer♦
May 20 '11 at 10:28
This does not seem to work on my end. It produces the "else" output both inside and outside amyenv
environment. However, both@currenvir
and@myenvname
display the correct (and the same) output when placed inside the environment.
– Danny Hansen
29 mins ago
@DannyHansen Right: in some update during the last eight years, the LaTeX kernel changed@currenvir
to not belong
as it used to be. Fixed by adding a*
.
– egreg
20 mins ago
add a comment |
LaTeX keeps the current environment in the macro @currenvir
makeatletter
newcommandinner%
ifx@currenvir@myenvname
(inner)
else
beginmyenv(inner)endmyenv
fi
newcommand*@myenvnamemyenv
makeatother
Another approach would be to define a global conditional that's set to true by myenv
start code and to false by myenv
end code. It depends mostly on what you are expecting from the myenv
environment: can it appear nested inside itself?
2
@Nickoley: Note that this doesn't work any longer wheninner
is used inside another environment inside themyenv
environment, e.g. beginmyenvbegincenterinnerendcenterendmyenv. Then
@currenvir` will becenter
wheninner
is expanded.
– Martin Scharrer♦
May 20 '11 at 10:28
This does not seem to work on my end. It produces the "else" output both inside and outside amyenv
environment. However, both@currenvir
and@myenvname
display the correct (and the same) output when placed inside the environment.
– Danny Hansen
29 mins ago
@DannyHansen Right: in some update during the last eight years, the LaTeX kernel changed@currenvir
to not belong
as it used to be. Fixed by adding a*
.
– egreg
20 mins ago
add a comment |
LaTeX keeps the current environment in the macro @currenvir
makeatletter
newcommandinner%
ifx@currenvir@myenvname
(inner)
else
beginmyenv(inner)endmyenv
fi
newcommand*@myenvnamemyenv
makeatother
Another approach would be to define a global conditional that's set to true by myenv
start code and to false by myenv
end code. It depends mostly on what you are expecting from the myenv
environment: can it appear nested inside itself?
LaTeX keeps the current environment in the macro @currenvir
makeatletter
newcommandinner%
ifx@currenvir@myenvname
(inner)
else
beginmyenv(inner)endmyenv
fi
newcommand*@myenvnamemyenv
makeatother
Another approach would be to define a global conditional that's set to true by myenv
start code and to false by myenv
end code. It depends mostly on what you are expecting from the myenv
environment: can it appear nested inside itself?
edited 20 mins ago
answered May 20 '11 at 8:32
egregegreg
729k8819263235
729k8819263235
2
@Nickoley: Note that this doesn't work any longer wheninner
is used inside another environment inside themyenv
environment, e.g. beginmyenvbegincenterinnerendcenterendmyenv. Then
@currenvir` will becenter
wheninner
is expanded.
– Martin Scharrer♦
May 20 '11 at 10:28
This does not seem to work on my end. It produces the "else" output both inside and outside amyenv
environment. However, both@currenvir
and@myenvname
display the correct (and the same) output when placed inside the environment.
– Danny Hansen
29 mins ago
@DannyHansen Right: in some update during the last eight years, the LaTeX kernel changed@currenvir
to not belong
as it used to be. Fixed by adding a*
.
– egreg
20 mins ago
add a comment |
2
@Nickoley: Note that this doesn't work any longer wheninner
is used inside another environment inside themyenv
environment, e.g. beginmyenvbegincenterinnerendcenterendmyenv. Then
@currenvir` will becenter
wheninner
is expanded.
– Martin Scharrer♦
May 20 '11 at 10:28
This does not seem to work on my end. It produces the "else" output both inside and outside amyenv
environment. However, both@currenvir
and@myenvname
display the correct (and the same) output when placed inside the environment.
– Danny Hansen
29 mins ago
@DannyHansen Right: in some update during the last eight years, the LaTeX kernel changed@currenvir
to not belong
as it used to be. Fixed by adding a*
.
– egreg
20 mins ago
2
2
@Nickoley: Note that this doesn't work any longer when
inner
is used inside another environment inside the myenv
environment, e.g. beginmyenvbegincenterinnerendcenterendmyenv. Then
@currenvir` will be center
when inner
is expanded.– Martin Scharrer♦
May 20 '11 at 10:28
@Nickoley: Note that this doesn't work any longer when
inner
is used inside another environment inside the myenv
environment, e.g. beginmyenvbegincenterinnerendcenterendmyenv. Then
@currenvir` will be center
when inner
is expanded.– Martin Scharrer♦
May 20 '11 at 10:28
This does not seem to work on my end. It produces the "else" output both inside and outside a
myenv
environment. However, both @currenvir
and @myenvname
display the correct (and the same) output when placed inside the environment.– Danny Hansen
29 mins ago
This does not seem to work on my end. It produces the "else" output both inside and outside a
myenv
environment. However, both @currenvir
and @myenvname
display the correct (and the same) output when placed inside the environment.– Danny Hansen
29 mins ago
@DannyHansen Right: in some update during the last eight years, the LaTeX kernel changed
@currenvir
to not be long
as it used to be. Fixed by adding a *
.– egreg
20 mins ago
@DannyHansen Right: in some update during the last eight years, the LaTeX kernel changed
@currenvir
to not be long
as it used to be. Fixed by adding a *
.– egreg
20 mins ago
add a comment |
If you use pdftex
, etex
or xetex
(I mean engine), you can define a fully expandable test:
makeatletter defIfEnvir #1%
% implicit #2 "what if true"
% implicit #3 "what if false"
%
ifnum strcmp@currenvir#1=0
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
Such a conditional is defined in the gmutils
package: @ifenvir
, but there it's protected
for some reason.
If you prefer the if… … else … fi form, just replace expandafter@first/secondoftwo with your stuff, but i'd suggest the arguments-form because it's robust to unbalanced if's.
– Natror
May 20 '11 at 9:06
Please indent your code with four spaces (or use the '101010' button to do this) so that it is properly highlighted. Please don't use HTML for code formatting. Thanks.
– Martin Scharrer♦
May 20 '11 at 9:39
the command isstrcmp
in XeTeX andpdfstrcmp
in pdfTeX. One can loadpdftexcmds
and usepdf@strcmp
in all engines (including LuaTeX).
– egreg
May 20 '11 at 10:04
add a comment |
If you use pdftex
, etex
or xetex
(I mean engine), you can define a fully expandable test:
makeatletter defIfEnvir #1%
% implicit #2 "what if true"
% implicit #3 "what if false"
%
ifnum strcmp@currenvir#1=0
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
Such a conditional is defined in the gmutils
package: @ifenvir
, but there it's protected
for some reason.
If you prefer the if… … else … fi form, just replace expandafter@first/secondoftwo with your stuff, but i'd suggest the arguments-form because it's robust to unbalanced if's.
– Natror
May 20 '11 at 9:06
Please indent your code with four spaces (or use the '101010' button to do this) so that it is properly highlighted. Please don't use HTML for code formatting. Thanks.
– Martin Scharrer♦
May 20 '11 at 9:39
the command isstrcmp
in XeTeX andpdfstrcmp
in pdfTeX. One can loadpdftexcmds
and usepdf@strcmp
in all engines (including LuaTeX).
– egreg
May 20 '11 at 10:04
add a comment |
If you use pdftex
, etex
or xetex
(I mean engine), you can define a fully expandable test:
makeatletter defIfEnvir #1%
% implicit #2 "what if true"
% implicit #3 "what if false"
%
ifnum strcmp@currenvir#1=0
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
Such a conditional is defined in the gmutils
package: @ifenvir
, but there it's protected
for some reason.
If you use pdftex
, etex
or xetex
(I mean engine), you can define a fully expandable test:
makeatletter defIfEnvir #1%
% implicit #2 "what if true"
% implicit #3 "what if false"
%
ifnum strcmp@currenvir#1=0
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
Such a conditional is defined in the gmutils
package: @ifenvir
, but there it's protected
for some reason.
edited May 20 '11 at 9:40
Martin Scharrer♦
203k47651825
203k47651825
answered May 20 '11 at 9:01
NatrorNatror
612
612
If you prefer the if… … else … fi form, just replace expandafter@first/secondoftwo with your stuff, but i'd suggest the arguments-form because it's robust to unbalanced if's.
– Natror
May 20 '11 at 9:06
Please indent your code with four spaces (or use the '101010' button to do this) so that it is properly highlighted. Please don't use HTML for code formatting. Thanks.
– Martin Scharrer♦
May 20 '11 at 9:39
the command isstrcmp
in XeTeX andpdfstrcmp
in pdfTeX. One can loadpdftexcmds
and usepdf@strcmp
in all engines (including LuaTeX).
– egreg
May 20 '11 at 10:04
add a comment |
If you prefer the if… … else … fi form, just replace expandafter@first/secondoftwo with your stuff, but i'd suggest the arguments-form because it's robust to unbalanced if's.
– Natror
May 20 '11 at 9:06
Please indent your code with four spaces (or use the '101010' button to do this) so that it is properly highlighted. Please don't use HTML for code formatting. Thanks.
– Martin Scharrer♦
May 20 '11 at 9:39
the command isstrcmp
in XeTeX andpdfstrcmp
in pdfTeX. One can loadpdftexcmds
and usepdf@strcmp
in all engines (including LuaTeX).
– egreg
May 20 '11 at 10:04
If you prefer the if… … else … fi form, just replace expandafter@first/secondoftwo with your stuff, but i'd suggest the arguments-form because it's robust to unbalanced if's.
– Natror
May 20 '11 at 9:06
If you prefer the if… … else … fi form, just replace expandafter@first/secondoftwo with your stuff, but i'd suggest the arguments-form because it's robust to unbalanced if's.
– Natror
May 20 '11 at 9:06
Please indent your code with four spaces (or use the '101010' button to do this) so that it is properly highlighted. Please don't use HTML for code formatting. Thanks.
– Martin Scharrer♦
May 20 '11 at 9:39
Please indent your code with four spaces (or use the '101010' button to do this) so that it is properly highlighted. Please don't use HTML for code formatting. Thanks.
– Martin Scharrer♦
May 20 '11 at 9:39
the command is
strcmp
in XeTeX and pdfstrcmp
in pdfTeX. One can load pdftexcmds
and use pdf@strcmp
in all engines (including LuaTeX).– egreg
May 20 '11 at 10:04
the command is
strcmp
in XeTeX and pdfstrcmp
in pdfTeX. One can load pdftexcmds
and use pdf@strcmp
in all engines (including LuaTeX).– egreg
May 20 '11 at 10:04
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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%2f18652%2fhow-can-i-check-if-the-current-code-is-inside-a-certain-environment%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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
Related Question: Detecting if inside a tikzpicture
– Peter Grill
Nov 7 '18 at 23:30