TeX - LaTeX Asked on December 31, 2021
I have created an environment with NewEnviron
that processes some input. For the sake of the discussion, it is something like
NewEnviron{myworkingenvironment}[1]
{
BODY % BODY is expected to define A, B and C
numericResult{A + B + C}
textResult{A + B + C}
}
The functions typeset the output I want them to and I use the environment extensively (the parameter #1
, thus far unused, should serve as an ID).
Now I want to use the variables of this environment in another one, like:
NewEnviron{mynewenvironment}[1]
{
BODY
The input was get{#1:A}, get{#1:B} and get{#1:C}
The result was get{id:numericResult}.
}
How can I implement this get
macro? The options I’ve found so far (e.g. change @currentlabelname
and defining a label afterwards) do not seem to work (I always get the name of the section where the reference is, instead of the value I expected).
I think this does what you require.
documentclass{article}
usepackage{environ}
NewEnviron{myworkingenvironment}[1]{BODY%
globalexpandafterletcsname#1AendcsnameA
globalexpandafterletcsname#1BendcsnameB}
NewEnviron{mynewenvironment}[1]{BODY%
defgetrelay##1:##2{csname##1##2endcsname}
defget##1{getrelay##1}
get{#1:A} is a friendly clown.
get{ABC:B} is a dangerous doll.
}
begin{document}
%
begin{myworkingenvironment}{ABC}
newcommandA{Pennywise}
newcommandB{Chucky}
end{myworkingenvironment}
begin{mynewenvironment}{ABC}
end{mynewenvironment}
end{document}
The idea is that when you create a myworkingenvironment
called ABC
, global macros called ABCA
and ABCB
are generated automatically. The get
command implemented here just allows you to say something like get{#1:A}
(where #1
is ABC
) rather than typing ABCA
directly. Let me know if this works for you, and I will add a more detailed explanation.
Answered by Ian Thompson on December 31, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP