LaTeX 2e environment that “knows” the name of surrounding environment
I'd like to have a LaTeX 2e-environment which when occurring inside another environment "knows" the name of the surrounding environment.
Is this possible?
I know that @currenvir
provides the name of the current environment.
I seek some sort of @surroundenvir
which provides the name of the surrounding environment.
E.g.
documentclass{article}
makeatletter
newenvironment{FOO}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{BAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{FOOBAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
shall deliver console output:
FOO-begin: Surrounding environment's name is document
FOO-end: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is document
BAR-end: Surrounding environment's name is document
FOOBAR-begin: Surrounding environment's name is document
FOOBAR-end: Surrounding environment's name is document
FOO-begin: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is FOO
FOOBAR-begin: Surrounding environment's name is BAR
FOOBAR-end: Surrounding environment's name is BAR
BAR-end: Surrounding environment's name is FOO
FOO-end: Surrounding environment's name is document
macros environments nesting
New contributor
add a comment |
I'd like to have a LaTeX 2e-environment which when occurring inside another environment "knows" the name of the surrounding environment.
Is this possible?
I know that @currenvir
provides the name of the current environment.
I seek some sort of @surroundenvir
which provides the name of the surrounding environment.
E.g.
documentclass{article}
makeatletter
newenvironment{FOO}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{BAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{FOOBAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
shall deliver console output:
FOO-begin: Surrounding environment's name is document
FOO-end: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is document
BAR-end: Surrounding environment's name is document
FOOBAR-begin: Surrounding environment's name is document
FOOBAR-end: Surrounding environment's name is document
FOO-begin: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is FOO
FOOBAR-begin: Surrounding environment's name is BAR
FOOBAR-end: Surrounding environment's name is BAR
BAR-end: Surrounding environment's name is FOO
FOO-end: Surrounding environment's name is document
macros environments nesting
New contributor
add a comment |
I'd like to have a LaTeX 2e-environment which when occurring inside another environment "knows" the name of the surrounding environment.
Is this possible?
I know that @currenvir
provides the name of the current environment.
I seek some sort of @surroundenvir
which provides the name of the surrounding environment.
E.g.
documentclass{article}
makeatletter
newenvironment{FOO}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{BAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{FOOBAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
shall deliver console output:
FOO-begin: Surrounding environment's name is document
FOO-end: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is document
BAR-end: Surrounding environment's name is document
FOOBAR-begin: Surrounding environment's name is document
FOOBAR-end: Surrounding environment's name is document
FOO-begin: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is FOO
FOOBAR-begin: Surrounding environment's name is BAR
FOOBAR-end: Surrounding environment's name is BAR
BAR-end: Surrounding environment's name is FOO
FOO-end: Surrounding environment's name is document
macros environments nesting
New contributor
I'd like to have a LaTeX 2e-environment which when occurring inside another environment "knows" the name of the surrounding environment.
Is this possible?
I know that @currenvir
provides the name of the current environment.
I seek some sort of @surroundenvir
which provides the name of the surrounding environment.
E.g.
documentclass{article}
makeatletter
newenvironment{FOO}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{BAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{FOOBAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
shall deliver console output:
FOO-begin: Surrounding environment's name is document
FOO-end: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is document
BAR-end: Surrounding environment's name is document
FOOBAR-begin: Surrounding environment's name is document
FOOBAR-end: Surrounding environment's name is document
FOO-begin: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is FOO
FOOBAR-begin: Surrounding environment's name is BAR
FOOBAR-end: Surrounding environment's name is BAR
BAR-end: Surrounding environment's name is FOO
FOO-end: Surrounding environment's name is document
macros environments nesting
macros environments nesting
New contributor
New contributor
New contributor
asked Dec 24 at 17:33
James Gambolputty
261
261
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Environments are usually called using a begin
-end
clause. You can patch begin
(using etoolbox
) to store the value of @currenvir
before it is updated:
documentclass{article}
usepackage{etoolbox}
makeatletter
% patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
patchcmd{begin}{begingroup}{begingrouplet@surroundenvir@currenvir}{}{}
newenvironment{FOO}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{BAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{FOOBAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
This yields in the .log
:
FOO-begin: Surrounding environment's name is document
FOO-end: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is document
BAR-end: Surrounding environment's name is document
FOOBAR-begin: Surrounding environment's name is document
FOOBAR-end: Surrounding environment's name is document
FOO-begin: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is FOO
FOOBAR-begin: Surrounding environment's name is BAR
FOOBAR-end: Surrounding environment's name is BAR
BAR-end: Surrounding environment's name is FOO
FOO-end: Surrounding environment's name is document
Note that @currenvir
defaults to document
, set inside the LaTeX2e kernel.
add a comment |
Example "test.tex":
documentclass{article}
usepackage{etoolbox}
makeatletter
newcommand*@surroundenvir{}
newcommand*@surroundenvirtemp{}
BeforeBeginEnvironment{FOO}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOO}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{BAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{BAR}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{FOOBAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOOBAR}{let@surroundenvir=@surroundenvirtemp}
newenvironment{FOO}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{BAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{FOOBAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
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
});
}
});
James Gambolputty is a new contributor. Be nice, and check out our Code of Conduct.
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%2f467211%2flatex-2e-environment-that-knows-the-name-of-surrounding-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
Environments are usually called using a begin
-end
clause. You can patch begin
(using etoolbox
) to store the value of @currenvir
before it is updated:
documentclass{article}
usepackage{etoolbox}
makeatletter
% patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
patchcmd{begin}{begingroup}{begingrouplet@surroundenvir@currenvir}{}{}
newenvironment{FOO}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{BAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{FOOBAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
This yields in the .log
:
FOO-begin: Surrounding environment's name is document
FOO-end: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is document
BAR-end: Surrounding environment's name is document
FOOBAR-begin: Surrounding environment's name is document
FOOBAR-end: Surrounding environment's name is document
FOO-begin: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is FOO
FOOBAR-begin: Surrounding environment's name is BAR
FOOBAR-end: Surrounding environment's name is BAR
BAR-end: Surrounding environment's name is FOO
FOO-end: Surrounding environment's name is document
Note that @currenvir
defaults to document
, set inside the LaTeX2e kernel.
add a comment |
Environments are usually called using a begin
-end
clause. You can patch begin
(using etoolbox
) to store the value of @currenvir
before it is updated:
documentclass{article}
usepackage{etoolbox}
makeatletter
% patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
patchcmd{begin}{begingroup}{begingrouplet@surroundenvir@currenvir}{}{}
newenvironment{FOO}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{BAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{FOOBAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
This yields in the .log
:
FOO-begin: Surrounding environment's name is document
FOO-end: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is document
BAR-end: Surrounding environment's name is document
FOOBAR-begin: Surrounding environment's name is document
FOOBAR-end: Surrounding environment's name is document
FOO-begin: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is FOO
FOOBAR-begin: Surrounding environment's name is BAR
FOOBAR-end: Surrounding environment's name is BAR
BAR-end: Surrounding environment's name is FOO
FOO-end: Surrounding environment's name is document
Note that @currenvir
defaults to document
, set inside the LaTeX2e kernel.
add a comment |
Environments are usually called using a begin
-end
clause. You can patch begin
(using etoolbox
) to store the value of @currenvir
before it is updated:
documentclass{article}
usepackage{etoolbox}
makeatletter
% patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
patchcmd{begin}{begingroup}{begingrouplet@surroundenvir@currenvir}{}{}
newenvironment{FOO}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{BAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{FOOBAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
This yields in the .log
:
FOO-begin: Surrounding environment's name is document
FOO-end: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is document
BAR-end: Surrounding environment's name is document
FOOBAR-begin: Surrounding environment's name is document
FOOBAR-end: Surrounding environment's name is document
FOO-begin: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is FOO
FOOBAR-begin: Surrounding environment's name is BAR
FOOBAR-end: Surrounding environment's name is BAR
BAR-end: Surrounding environment's name is FOO
FOO-end: Surrounding environment's name is document
Note that @currenvir
defaults to document
, set inside the LaTeX2e kernel.
Environments are usually called using a begin
-end
clause. You can patch begin
(using etoolbox
) to store the value of @currenvir
before it is updated:
documentclass{article}
usepackage{etoolbox}
makeatletter
% patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
patchcmd{begin}{begingroup}{begingrouplet@surroundenvir@currenvir}{}{}
newenvironment{FOO}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{BAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
newenvironment{FOOBAR}{message{@currenvir-begin: Surrounding environment's name is @surroundenvir}}%
{message{@currenvir-end: Surrounding environment's name is @surroundenvir}}
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
This yields in the .log
:
FOO-begin: Surrounding environment's name is document
FOO-end: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is document
BAR-end: Surrounding environment's name is document
FOOBAR-begin: Surrounding environment's name is document
FOOBAR-end: Surrounding environment's name is document
FOO-begin: Surrounding environment's name is document
BAR-begin: Surrounding environment's name is FOO
FOOBAR-begin: Surrounding environment's name is BAR
FOOBAR-end: Surrounding environment's name is BAR
BAR-end: Surrounding environment's name is FOO
FOO-end: Surrounding environment's name is document
Note that @currenvir
defaults to document
, set inside the LaTeX2e kernel.
answered Dec 24 at 17:46
Werner
437k649581648
437k649581648
add a comment |
add a comment |
Example "test.tex":
documentclass{article}
usepackage{etoolbox}
makeatletter
newcommand*@surroundenvir{}
newcommand*@surroundenvirtemp{}
BeforeBeginEnvironment{FOO}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOO}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{BAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{BAR}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{FOOBAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOOBAR}{let@surroundenvir=@surroundenvirtemp}
newenvironment{FOO}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{BAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{FOOBAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
add a comment |
Example "test.tex":
documentclass{article}
usepackage{etoolbox}
makeatletter
newcommand*@surroundenvir{}
newcommand*@surroundenvirtemp{}
BeforeBeginEnvironment{FOO}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOO}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{BAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{BAR}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{FOOBAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOOBAR}{let@surroundenvir=@surroundenvirtemp}
newenvironment{FOO}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{BAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{FOOBAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
add a comment |
Example "test.tex":
documentclass{article}
usepackage{etoolbox}
makeatletter
newcommand*@surroundenvir{}
newcommand*@surroundenvirtemp{}
BeforeBeginEnvironment{FOO}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOO}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{BAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{BAR}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{FOOBAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOOBAR}{let@surroundenvir=@surroundenvirtemp}
newenvironment{FOO}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{BAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{FOOBAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
Example "test.tex":
documentclass{article}
usepackage{etoolbox}
makeatletter
newcommand*@surroundenvir{}
newcommand*@surroundenvirtemp{}
BeforeBeginEnvironment{FOO}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOO}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{BAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{BAR}{let@surroundenvir=@surroundenvirtemp}
BeforeBeginEnvironment{FOOBAR}{let@surroundenvirtemp=@currenvir}
AtBeginEnvironment{FOOBAR}{let@surroundenvir=@surroundenvirtemp}
newenvironment{FOO}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{BAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
newenvironment{FOOBAR}{message{Begin @currenvir: Surrounding env is: @surroundenvir^^J}}%
{message{End @currenvir: Surrounding env is: @surroundenvir^^J}}%%
makeatother
begin{document}
begin{FOO}
end{FOO}
begin{BAR}
end{BAR}
begin{FOOBAR}
end{FOOBAR}
begin{FOO}
begin{BAR}
begin{FOOBAR}
end{FOOBAR}
end{BAR}
end{FOO}
end{document}
edited Dec 24 at 20:34
answered Dec 24 at 18:15
Ulrich Diez
4,135615
4,135615
add a comment |
add a comment |
James Gambolputty is a new contributor. Be nice, and check out our Code of Conduct.
James Gambolputty is a new contributor. Be nice, and check out our Code of Conduct.
James Gambolputty is a new contributor. Be nice, and check out our Code of Conduct.
James Gambolputty is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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');
});
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%2f467211%2flatex-2e-environment-that-knows-the-name-of-surrounding-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');
});
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