How to robustly store bits of text for later useHow to use def or similar command to store an arbitrary number of variables for later processing?How to collect text for later usage in appendix?How to store and append text for later use (inside enumerate environment)Save original variable/command for invocation laterWrap text to quote it later in the same documentCollecting contents of environment and store them for later retrievalHow reuse latex code for later expansion?How to store to-be-credited contributors for acknowledgment later in the appendixStore values, text, commands in variablesHow to store multiple fragile definitions for re-importing later
Output visual diagram of picture
Do native speakers use "ultima" and "proxima" frequently in spoken English?
Pre-Employment Background Check With Consent For Future Checks
What's the meaning of "what it means for something to be something"?
Writing in a Christian voice
Why is indicated airspeed rather than ground speed used during the takeoff roll?
How are passwords stolen from companies if they only store hashes?
Mortal danger in mid-grade literature
Is there any common country to visit for persons holding UK and Schengen visas?
Magnifying glass in hyperbolic space
Why do Radio Buttons not fill the entire outer circle?
Did I make a mistake by ccing email to boss to others?
Is there a distance limit for minecart tracks?
I keep switching characters, how do I stop?
Connection Between Knot Theory and Number Theory
categorizing a variable turns it from insignificant to significant
Asserting that Atheism and Theism are both faith based positions
Not hide and seek
Offset in split text content
How would a solely written language work mechanically
Air travel with refrigerated insulin
Strange behavior in TikZ draw command
If the Dominion rule using their Jem'Hadar troops, why is their life expectancy so low?
Make a Bowl of Alphabet Soup
How to robustly store bits of text for later use
How to use def or similar command to store an arbitrary number of variables for later processing?How to collect text for later usage in appendix?How to store and append text for later use (inside enumerate environment)Save original variable/command for invocation laterWrap text to quote it later in the same documentCollecting contents of environment and store them for later retrievalHow reuse latex code for later expansion?How to store to-be-credited contributors for acknowledgment later in the appendixStore values, text, commands in variablesHow to store multiple fragile definitions for re-importing later
I'm trying to write myself a package, similar to the exercise package, so I can prepare problem sets for my students. I wish to delay the output of problems and/or solutions until a suitable place in the document has been reached. I have something that sort of works but it's kind of clunky. For example, this works pretty well:
usepackageenviron
NewEnvirontestbglobalexpandafterletcsname barendcsnameBODY
I use csname because the names are dynamically generated. This doesn't work so well if the command is anything other than BODY. For example, if I do letbarBODY, latex has an aneurysm (it binds bar to just {).
There is an alternate way of doing this, which is:
NewEnvirontestcglobalexpandafteredefcsname fooendcsnameBODY
This sort of works. The following thing works:begintestchiendtestc, but this gives LaTeX an aneurysm: begintestcbf hiendtestc. (The error message is incomplete). I tried to debug it myself but I get hopelessly tangled up in packages that I don't understand. If you do it with tiny instead of bf you get the wildly different LaTeX error message: ! TeX capacity exceeded, sorry [input stack size=5000].
How can I squirrel away for later, not just BODY, but some sophisticated combination of BODY and other stuff, while having it robust to what's between the begin and end?
Edit: ok multiple solutions below
macros environments
New contributor
Sébastien Loisel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 1 more comment
I'm trying to write myself a package, similar to the exercise package, so I can prepare problem sets for my students. I wish to delay the output of problems and/or solutions until a suitable place in the document has been reached. I have something that sort of works but it's kind of clunky. For example, this works pretty well:
usepackageenviron
NewEnvirontestbglobalexpandafterletcsname barendcsnameBODY
I use csname because the names are dynamically generated. This doesn't work so well if the command is anything other than BODY. For example, if I do letbarBODY, latex has an aneurysm (it binds bar to just {).
There is an alternate way of doing this, which is:
NewEnvirontestcglobalexpandafteredefcsname fooendcsnameBODY
This sort of works. The following thing works:begintestchiendtestc, but this gives LaTeX an aneurysm: begintestcbf hiendtestc. (The error message is incomplete). I tried to debug it myself but I get hopelessly tangled up in packages that I don't understand. If you do it with tiny instead of bf you get the wildly different LaTeX error message: ! TeX capacity exceeded, sorry [input stack size=5000].
How can I squirrel away for later, not just BODY, but some sophisticated combination of BODY and other stuff, while having it robust to what's between the begin and end?
Edit: ok multiple solutions below
macros environments
New contributor
Sébastien Loisel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Why not usedef?letdoes what it should do: use the the next token.
– TeXnician
10 hours ago
If you mean this:NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY, I get:! Undefined control sequence. foo ->BODY
– Sébastien Loisel
9 hours ago
1
I'm not sure why you don't likeglobalexpandafterletcsname barendcsnameBODY: it's entirely normal TeX.
– Joseph Wright♦
9 hours ago
I started writing a class file to prepare conference programmes using the same sort of "save text for later" features. github.com/scmbradley/schedule I have just realised that this was six years ago. My god. Six years!?
– Seamus
9 hours ago
You should definitely use let with BODY, def with anything whose definition doesn't change, and edef with things that do change (and you don't mind expanding them).
– John Kormylo
7 hours ago
|
show 1 more comment
I'm trying to write myself a package, similar to the exercise package, so I can prepare problem sets for my students. I wish to delay the output of problems and/or solutions until a suitable place in the document has been reached. I have something that sort of works but it's kind of clunky. For example, this works pretty well:
usepackageenviron
NewEnvirontestbglobalexpandafterletcsname barendcsnameBODY
I use csname because the names are dynamically generated. This doesn't work so well if the command is anything other than BODY. For example, if I do letbarBODY, latex has an aneurysm (it binds bar to just {).
There is an alternate way of doing this, which is:
NewEnvirontestcglobalexpandafteredefcsname fooendcsnameBODY
This sort of works. The following thing works:begintestchiendtestc, but this gives LaTeX an aneurysm: begintestcbf hiendtestc. (The error message is incomplete). I tried to debug it myself but I get hopelessly tangled up in packages that I don't understand. If you do it with tiny instead of bf you get the wildly different LaTeX error message: ! TeX capacity exceeded, sorry [input stack size=5000].
How can I squirrel away for later, not just BODY, but some sophisticated combination of BODY and other stuff, while having it robust to what's between the begin and end?
Edit: ok multiple solutions below
macros environments
New contributor
Sébastien Loisel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm trying to write myself a package, similar to the exercise package, so I can prepare problem sets for my students. I wish to delay the output of problems and/or solutions until a suitable place in the document has been reached. I have something that sort of works but it's kind of clunky. For example, this works pretty well:
usepackageenviron
NewEnvirontestbglobalexpandafterletcsname barendcsnameBODY
I use csname because the names are dynamically generated. This doesn't work so well if the command is anything other than BODY. For example, if I do letbarBODY, latex has an aneurysm (it binds bar to just {).
There is an alternate way of doing this, which is:
NewEnvirontestcglobalexpandafteredefcsname fooendcsnameBODY
This sort of works. The following thing works:begintestchiendtestc, but this gives LaTeX an aneurysm: begintestcbf hiendtestc. (The error message is incomplete). I tried to debug it myself but I get hopelessly tangled up in packages that I don't understand. If you do it with tiny instead of bf you get the wildly different LaTeX error message: ! TeX capacity exceeded, sorry [input stack size=5000].
How can I squirrel away for later, not just BODY, but some sophisticated combination of BODY and other stuff, while having it robust to what's between the begin and end?
Edit: ok multiple solutions below
macros environments
macros environments
New contributor
Sébastien Loisel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Sébastien Loisel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 7 hours ago
Sébastien Loisel
New contributor
Sébastien Loisel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 10 hours ago
Sébastien LoiselSébastien Loisel
1284
1284
New contributor
Sébastien Loisel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Sébastien Loisel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Sébastien Loisel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Why not usedef?letdoes what it should do: use the the next token.
– TeXnician
10 hours ago
If you mean this:NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY, I get:! Undefined control sequence. foo ->BODY
– Sébastien Loisel
9 hours ago
1
I'm not sure why you don't likeglobalexpandafterletcsname barendcsnameBODY: it's entirely normal TeX.
– Joseph Wright♦
9 hours ago
I started writing a class file to prepare conference programmes using the same sort of "save text for later" features. github.com/scmbradley/schedule I have just realised that this was six years ago. My god. Six years!?
– Seamus
9 hours ago
You should definitely use let with BODY, def with anything whose definition doesn't change, and edef with things that do change (and you don't mind expanding them).
– John Kormylo
7 hours ago
|
show 1 more comment
1
Why not usedef?letdoes what it should do: use the the next token.
– TeXnician
10 hours ago
If you mean this:NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY, I get:! Undefined control sequence. foo ->BODY
– Sébastien Loisel
9 hours ago
1
I'm not sure why you don't likeglobalexpandafterletcsname barendcsnameBODY: it's entirely normal TeX.
– Joseph Wright♦
9 hours ago
I started writing a class file to prepare conference programmes using the same sort of "save text for later" features. github.com/scmbradley/schedule I have just realised that this was six years ago. My god. Six years!?
– Seamus
9 hours ago
You should definitely use let with BODY, def with anything whose definition doesn't change, and edef with things that do change (and you don't mind expanding them).
– John Kormylo
7 hours ago
1
1
Why not use
def? let does what it should do: use the the next token.– TeXnician
10 hours ago
Why not use
def? let does what it should do: use the the next token.– TeXnician
10 hours ago
If you mean this:
NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY, I get: ! Undefined control sequence. foo ->BODY– Sébastien Loisel
9 hours ago
If you mean this:
NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY, I get: ! Undefined control sequence. foo ->BODY– Sébastien Loisel
9 hours ago
1
1
I'm not sure why you don't like
globalexpandafterletcsname barendcsnameBODY: it's entirely normal TeX.– Joseph Wright♦
9 hours ago
I'm not sure why you don't like
globalexpandafterletcsname barendcsnameBODY: it's entirely normal TeX.– Joseph Wright♦
9 hours ago
I started writing a class file to prepare conference programmes using the same sort of "save text for later" features. github.com/scmbradley/schedule I have just realised that this was six years ago. My god. Six years!?
– Seamus
9 hours ago
I started writing a class file to prepare conference programmes using the same sort of "save text for later" features. github.com/scmbradley/schedule I have just realised that this was six years ago. My god. Six years!?
– Seamus
9 hours ago
You should definitely use let with BODY, def with anything whose definition doesn't change, and edef with things that do change (and you don't mind expanding them).
– John Kormylo
7 hours ago
You should definitely use let with BODY, def with anything whose definition doesn't change, and edef with things that do change (and you don't mind expanding them).
– John Kormylo
7 hours ago
|
show 1 more comment
3 Answers
3
active
oldest
votes
With unexpanded you can avoid worrying about protected@xdef.
documentclassarticle
usepackageenviron
NewEnvironexercise%
xdefsavedexercises%
unexpandedexpandaftersavedexercises%
noexpandbeginprintedexercise%
unexpandedexpandafterBODY%
noexpandendprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
I used newtheorem just for the example.

With xparse released 2019-03-05 or later:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentEnvironmentexercise+b
tl_gput_right:Nn g_loisel_exercises_tl
beginprintedexercise
#1
endprintedexercise
NewDocumentCommandprintexercises
tl_use:N g_loisel_exercises_tl
tl_gclear:N g_loisel_exercises_tl
tl_new:N g_loisel_exercises_tl
ExplSyntaxOff
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
Oh this is good
– Sébastien Loisel
7 hours ago
add a comment |
If you want BODY to be saved then add stuff dynamically, you are likely best using two macros:
documentclassarticle
usepackageenviron
NewEnvirontestb%
globalexpandafterletcsname barendcsnameBODY
expandafterxdefcsname barplusendcsname%
expandafternoexpandcsname barendcsname
noexpandbf Hi
%
begindocument
begintestb
bfseries
Hi
endtestb
showbarplus
enddocument
If you want to avoid using BODY you could use xparse
documentclassarticle
usepackagexparse
NewDocumentEnvironmenttestb+bexpandaftergdefcsname barendcsname#1
begindocument
begintestb
bfseries
Hi
endtestb
showbar
enddocument
This needs TL'19 or up-to-date MiKTeX: this is a new feature inxparse.
– Joseph Wright♦
9 hours ago
Ah, thanks for this. By the way, I just tried this:NewEnvirontestcexpandafterprotected@xdefcsname fooendcsnameBODY, and it seems to work. Is there any situation where this would break again?
– Sébastien Loisel
8 hours ago
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
8 hours ago
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
8 hours ago
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
7 hours ago
|
show 2 more comments
A trick for triggering expansion is using romannumeral:
When due to romannumeral (La)TeX does gather together a sequence of digits trailed by a space as the number which it has to convert, expandable tokens get expanded.
When in the end a number is gathered together which is not positive, as the result of the conversion (La)TeX will not deliver any token at all.
Thus one can nicely (ab?)use romannumeral for triggering a lot of expansion-work and flipping-arguments-around-work as long as one ensures that in the end romannumeral will not find a positive number.
Here is a variant of egreg's answer which does with romannumeral and exchange instead of xdef and unexpanded.
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefexpandaftersavedexercisesexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandaftersavedexercises
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

If you wish to wrap the name of the macro that is to be defined into csname..endcsname, i.e., if you wish to use csname savedexercisesendcsname rather than savedexercises, you can take advantage of the fact that (La)TeX does expand expandable tokens while due to csname gathering the name of a control sequence token and hereby searching for the matching endcsname:
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefcsname savedexercisesexpandafterendcsnameexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandafterexpandafterexpandaftercsname savedexercisesendcsname
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
csname savedexercisesendcsname
expandaftergdefcsname savedexercisesendcsname%
expandafternewcommandexpandaftercsname savedexercisesendcsname
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

Be aware that with the approaches presented by now you cannot use printexercises for having exercises occur in arbitrary places. You can have exercises occur only in places of the document which in the source correspond to places behind the exercise-environments.
Perhaps an environment which does read its content under verbatim-catcode-régime for unexpanded-writing it to .aux-file in a way where from the .aux-file it gets read back under verbatim-catcode-régime also for defining a macro where scantokens will be applied to, and thus some sort of re-implementation of the label-ref-mechanism or of the tableofcontents-mechanism for verbatimized stuff might make it possible to make exercises printable throughout the entire document.
Implementing such a mechanism might be a nice challenge. But before taking that into consideration at all, exact information is needed on the intended usage and the desired "user-interface", i.e., what additional things you wish to be able to specify in which ways, etc, ...
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
);
);
Sébastien Loisel 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%2f480267%2fhow-to-robustly-store-bits-of-text-for-later-use%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
With unexpanded you can avoid worrying about protected@xdef.
documentclassarticle
usepackageenviron
NewEnvironexercise%
xdefsavedexercises%
unexpandedexpandaftersavedexercises%
noexpandbeginprintedexercise%
unexpandedexpandafterBODY%
noexpandendprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
I used newtheorem just for the example.

With xparse released 2019-03-05 or later:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentEnvironmentexercise+b
tl_gput_right:Nn g_loisel_exercises_tl
beginprintedexercise
#1
endprintedexercise
NewDocumentCommandprintexercises
tl_use:N g_loisel_exercises_tl
tl_gclear:N g_loisel_exercises_tl
tl_new:N g_loisel_exercises_tl
ExplSyntaxOff
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
Oh this is good
– Sébastien Loisel
7 hours ago
add a comment |
With unexpanded you can avoid worrying about protected@xdef.
documentclassarticle
usepackageenviron
NewEnvironexercise%
xdefsavedexercises%
unexpandedexpandaftersavedexercises%
noexpandbeginprintedexercise%
unexpandedexpandafterBODY%
noexpandendprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
I used newtheorem just for the example.

With xparse released 2019-03-05 or later:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentEnvironmentexercise+b
tl_gput_right:Nn g_loisel_exercises_tl
beginprintedexercise
#1
endprintedexercise
NewDocumentCommandprintexercises
tl_use:N g_loisel_exercises_tl
tl_gclear:N g_loisel_exercises_tl
tl_new:N g_loisel_exercises_tl
ExplSyntaxOff
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
Oh this is good
– Sébastien Loisel
7 hours ago
add a comment |
With unexpanded you can avoid worrying about protected@xdef.
documentclassarticle
usepackageenviron
NewEnvironexercise%
xdefsavedexercises%
unexpandedexpandaftersavedexercises%
noexpandbeginprintedexercise%
unexpandedexpandafterBODY%
noexpandendprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
I used newtheorem just for the example.

With xparse released 2019-03-05 or later:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentEnvironmentexercise+b
tl_gput_right:Nn g_loisel_exercises_tl
beginprintedexercise
#1
endprintedexercise
NewDocumentCommandprintexercises
tl_use:N g_loisel_exercises_tl
tl_gclear:N g_loisel_exercises_tl
tl_new:N g_loisel_exercises_tl
ExplSyntaxOff
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
With unexpanded you can avoid worrying about protected@xdef.
documentclassarticle
usepackageenviron
NewEnvironexercise%
xdefsavedexercises%
unexpandedexpandaftersavedexercises%
noexpandbeginprintedexercise%
unexpandedexpandafterBODY%
noexpandendprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
I used newtheorem just for the example.

With xparse released 2019-03-05 or later:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentEnvironmentexercise+b
tl_gput_right:Nn g_loisel_exercises_tl
beginprintedexercise
#1
endprintedexercise
NewDocumentCommandprintexercises
tl_use:N g_loisel_exercises_tl
tl_gclear:N g_loisel_exercises_tl
tl_new:N g_loisel_exercises_tl
ExplSyntaxOff
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument
answered 7 hours ago
egregegreg
727k8819233233
727k8819233233
Oh this is good
– Sébastien Loisel
7 hours ago
add a comment |
Oh this is good
– Sébastien Loisel
7 hours ago
Oh this is good
– Sébastien Loisel
7 hours ago
Oh this is good
– Sébastien Loisel
7 hours ago
add a comment |
If you want BODY to be saved then add stuff dynamically, you are likely best using two macros:
documentclassarticle
usepackageenviron
NewEnvirontestb%
globalexpandafterletcsname barendcsnameBODY
expandafterxdefcsname barplusendcsname%
expandafternoexpandcsname barendcsname
noexpandbf Hi
%
begindocument
begintestb
bfseries
Hi
endtestb
showbarplus
enddocument
If you want to avoid using BODY you could use xparse
documentclassarticle
usepackagexparse
NewDocumentEnvironmenttestb+bexpandaftergdefcsname barendcsname#1
begindocument
begintestb
bfseries
Hi
endtestb
showbar
enddocument
This needs TL'19 or up-to-date MiKTeX: this is a new feature inxparse.
– Joseph Wright♦
9 hours ago
Ah, thanks for this. By the way, I just tried this:NewEnvirontestcexpandafterprotected@xdefcsname fooendcsnameBODY, and it seems to work. Is there any situation where this would break again?
– Sébastien Loisel
8 hours ago
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
8 hours ago
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
8 hours ago
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
7 hours ago
|
show 2 more comments
If you want BODY to be saved then add stuff dynamically, you are likely best using two macros:
documentclassarticle
usepackageenviron
NewEnvirontestb%
globalexpandafterletcsname barendcsnameBODY
expandafterxdefcsname barplusendcsname%
expandafternoexpandcsname barendcsname
noexpandbf Hi
%
begindocument
begintestb
bfseries
Hi
endtestb
showbarplus
enddocument
If you want to avoid using BODY you could use xparse
documentclassarticle
usepackagexparse
NewDocumentEnvironmenttestb+bexpandaftergdefcsname barendcsname#1
begindocument
begintestb
bfseries
Hi
endtestb
showbar
enddocument
This needs TL'19 or up-to-date MiKTeX: this is a new feature inxparse.
– Joseph Wright♦
9 hours ago
Ah, thanks for this. By the way, I just tried this:NewEnvirontestcexpandafterprotected@xdefcsname fooendcsnameBODY, and it seems to work. Is there any situation where this would break again?
– Sébastien Loisel
8 hours ago
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
8 hours ago
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
8 hours ago
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
7 hours ago
|
show 2 more comments
If you want BODY to be saved then add stuff dynamically, you are likely best using two macros:
documentclassarticle
usepackageenviron
NewEnvirontestb%
globalexpandafterletcsname barendcsnameBODY
expandafterxdefcsname barplusendcsname%
expandafternoexpandcsname barendcsname
noexpandbf Hi
%
begindocument
begintestb
bfseries
Hi
endtestb
showbarplus
enddocument
If you want to avoid using BODY you could use xparse
documentclassarticle
usepackagexparse
NewDocumentEnvironmenttestb+bexpandaftergdefcsname barendcsname#1
begindocument
begintestb
bfseries
Hi
endtestb
showbar
enddocument
If you want BODY to be saved then add stuff dynamically, you are likely best using two macros:
documentclassarticle
usepackageenviron
NewEnvirontestb%
globalexpandafterletcsname barendcsnameBODY
expandafterxdefcsname barplusendcsname%
expandafternoexpandcsname barendcsname
noexpandbf Hi
%
begindocument
begintestb
bfseries
Hi
endtestb
showbarplus
enddocument
If you want to avoid using BODY you could use xparse
documentclassarticle
usepackagexparse
NewDocumentEnvironmenttestb+bexpandaftergdefcsname barendcsname#1
begindocument
begintestb
bfseries
Hi
endtestb
showbar
enddocument
edited 9 hours ago
answered 9 hours ago
Joseph Wright♦Joseph Wright
205k23561890
205k23561890
This needs TL'19 or up-to-date MiKTeX: this is a new feature inxparse.
– Joseph Wright♦
9 hours ago
Ah, thanks for this. By the way, I just tried this:NewEnvirontestcexpandafterprotected@xdefcsname fooendcsnameBODY, and it seems to work. Is there any situation where this would break again?
– Sébastien Loisel
8 hours ago
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
8 hours ago
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
8 hours ago
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
7 hours ago
|
show 2 more comments
This needs TL'19 or up-to-date MiKTeX: this is a new feature inxparse.
– Joseph Wright♦
9 hours ago
Ah, thanks for this. By the way, I just tried this:NewEnvirontestcexpandafterprotected@xdefcsname fooendcsnameBODY, and it seems to work. Is there any situation where this would break again?
– Sébastien Loisel
8 hours ago
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
8 hours ago
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
8 hours ago
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
7 hours ago
This needs TL'19 or up-to-date MiKTeX: this is a new feature in
xparse.– Joseph Wright♦
9 hours ago
This needs TL'19 or up-to-date MiKTeX: this is a new feature in
xparse.– Joseph Wright♦
9 hours ago
Ah, thanks for this. By the way, I just tried this:
NewEnvirontestcexpandafterprotected@xdefcsname fooendcsnameBODY , and it seems to work. Is there any situation where this would break again?– Sébastien Loisel
8 hours ago
Ah, thanks for this. By the way, I just tried this:
NewEnvirontestcexpandafterprotected@xdefcsname fooendcsnameBODY , and it seems to work. Is there any situation where this would break again?– Sébastien Loisel
8 hours ago
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
8 hours ago
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
8 hours ago
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
8 hours ago
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
8 hours ago
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
7 hours ago
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
7 hours ago
|
show 2 more comments
A trick for triggering expansion is using romannumeral:
When due to romannumeral (La)TeX does gather together a sequence of digits trailed by a space as the number which it has to convert, expandable tokens get expanded.
When in the end a number is gathered together which is not positive, as the result of the conversion (La)TeX will not deliver any token at all.
Thus one can nicely (ab?)use romannumeral for triggering a lot of expansion-work and flipping-arguments-around-work as long as one ensures that in the end romannumeral will not find a positive number.
Here is a variant of egreg's answer which does with romannumeral and exchange instead of xdef and unexpanded.
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefexpandaftersavedexercisesexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandaftersavedexercises
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

If you wish to wrap the name of the macro that is to be defined into csname..endcsname, i.e., if you wish to use csname savedexercisesendcsname rather than savedexercises, you can take advantage of the fact that (La)TeX does expand expandable tokens while due to csname gathering the name of a control sequence token and hereby searching for the matching endcsname:
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefcsname savedexercisesexpandafterendcsnameexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandafterexpandafterexpandaftercsname savedexercisesendcsname
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
csname savedexercisesendcsname
expandaftergdefcsname savedexercisesendcsname%
expandafternewcommandexpandaftercsname savedexercisesendcsname
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

Be aware that with the approaches presented by now you cannot use printexercises for having exercises occur in arbitrary places. You can have exercises occur only in places of the document which in the source correspond to places behind the exercise-environments.
Perhaps an environment which does read its content under verbatim-catcode-régime for unexpanded-writing it to .aux-file in a way where from the .aux-file it gets read back under verbatim-catcode-régime also for defining a macro where scantokens will be applied to, and thus some sort of re-implementation of the label-ref-mechanism or of the tableofcontents-mechanism for verbatimized stuff might make it possible to make exercises printable throughout the entire document.
Implementing such a mechanism might be a nice challenge. But before taking that into consideration at all, exact information is needed on the intended usage and the desired "user-interface", i.e., what additional things you wish to be able to specify in which ways, etc, ...
add a comment |
A trick for triggering expansion is using romannumeral:
When due to romannumeral (La)TeX does gather together a sequence of digits trailed by a space as the number which it has to convert, expandable tokens get expanded.
When in the end a number is gathered together which is not positive, as the result of the conversion (La)TeX will not deliver any token at all.
Thus one can nicely (ab?)use romannumeral for triggering a lot of expansion-work and flipping-arguments-around-work as long as one ensures that in the end romannumeral will not find a positive number.
Here is a variant of egreg's answer which does with romannumeral and exchange instead of xdef and unexpanded.
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefexpandaftersavedexercisesexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandaftersavedexercises
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

If you wish to wrap the name of the macro that is to be defined into csname..endcsname, i.e., if you wish to use csname savedexercisesendcsname rather than savedexercises, you can take advantage of the fact that (La)TeX does expand expandable tokens while due to csname gathering the name of a control sequence token and hereby searching for the matching endcsname:
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefcsname savedexercisesexpandafterendcsnameexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandafterexpandafterexpandaftercsname savedexercisesendcsname
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
csname savedexercisesendcsname
expandaftergdefcsname savedexercisesendcsname%
expandafternewcommandexpandaftercsname savedexercisesendcsname
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

Be aware that with the approaches presented by now you cannot use printexercises for having exercises occur in arbitrary places. You can have exercises occur only in places of the document which in the source correspond to places behind the exercise-environments.
Perhaps an environment which does read its content under verbatim-catcode-régime for unexpanded-writing it to .aux-file in a way where from the .aux-file it gets read back under verbatim-catcode-régime also for defining a macro where scantokens will be applied to, and thus some sort of re-implementation of the label-ref-mechanism or of the tableofcontents-mechanism for verbatimized stuff might make it possible to make exercises printable throughout the entire document.
Implementing such a mechanism might be a nice challenge. But before taking that into consideration at all, exact information is needed on the intended usage and the desired "user-interface", i.e., what additional things you wish to be able to specify in which ways, etc, ...
add a comment |
A trick for triggering expansion is using romannumeral:
When due to romannumeral (La)TeX does gather together a sequence of digits trailed by a space as the number which it has to convert, expandable tokens get expanded.
When in the end a number is gathered together which is not positive, as the result of the conversion (La)TeX will not deliver any token at all.
Thus one can nicely (ab?)use romannumeral for triggering a lot of expansion-work and flipping-arguments-around-work as long as one ensures that in the end romannumeral will not find a positive number.
Here is a variant of egreg's answer which does with romannumeral and exchange instead of xdef and unexpanded.
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefexpandaftersavedexercisesexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandaftersavedexercises
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

If you wish to wrap the name of the macro that is to be defined into csname..endcsname, i.e., if you wish to use csname savedexercisesendcsname rather than savedexercises, you can take advantage of the fact that (La)TeX does expand expandable tokens while due to csname gathering the name of a control sequence token and hereby searching for the matching endcsname:
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefcsname savedexercisesexpandafterendcsnameexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandafterexpandafterexpandaftercsname savedexercisesendcsname
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
csname savedexercisesendcsname
expandaftergdefcsname savedexercisesendcsname%
expandafternewcommandexpandaftercsname savedexercisesendcsname
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

Be aware that with the approaches presented by now you cannot use printexercises for having exercises occur in arbitrary places. You can have exercises occur only in places of the document which in the source correspond to places behind the exercise-environments.
Perhaps an environment which does read its content under verbatim-catcode-régime for unexpanded-writing it to .aux-file in a way where from the .aux-file it gets read back under verbatim-catcode-régime also for defining a macro where scantokens will be applied to, and thus some sort of re-implementation of the label-ref-mechanism or of the tableofcontents-mechanism for verbatimized stuff might make it possible to make exercises printable throughout the entire document.
Implementing such a mechanism might be a nice challenge. But before taking that into consideration at all, exact information is needed on the intended usage and the desired "user-interface", i.e., what additional things you wish to be able to specify in which ways, etc, ...
A trick for triggering expansion is using romannumeral:
When due to romannumeral (La)TeX does gather together a sequence of digits trailed by a space as the number which it has to convert, expandable tokens get expanded.
When in the end a number is gathered together which is not positive, as the result of the conversion (La)TeX will not deliver any token at all.
Thus one can nicely (ab?)use romannumeral for triggering a lot of expansion-work and flipping-arguments-around-work as long as one ensures that in the end romannumeral will not find a positive number.
Here is a variant of egreg's answer which does with romannumeral and exchange instead of xdef and unexpanded.
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefexpandaftersavedexercisesexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandaftersavedexercises
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
savedexercises
gdefsavedexercises%
newcommandsavedexercises
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

If you wish to wrap the name of the macro that is to be defined into csname..endcsname, i.e., if you wish to use csname savedexercisesendcsname rather than savedexercises, you can take advantage of the fact that (La)TeX does expand expandable tokens while due to csname gathering the name of a control sequence token and hereby searching for the matching endcsname:
documentclassarticle
usepackageenviron
newcommandexchange[2]#2#1
NewEnvironexercise%
expandaftergdefcsname savedexercisesexpandafterendcsnameexpandafter%
romannumeral0expandafterexchangeexpandafterBODY%
exchange expandafterexpandafterexpandaftercsname savedexercisesendcsname
beginprintedexercise%
%
endprintedexercise%
%
newcommandprintexercises%
csname savedexercisesendcsname
expandaftergdefcsname savedexercisesendcsname%
expandafternewcommandexpandaftercsname savedexercisesendcsname
newtheoremprintedexerciseExercise
begindocument
Here we talk about addition and show that $1+1=2$.
beginexercise
Compute $1+2$
endexercise
Here we talk about integrals.
beginexercise
Compute the following integrals:
beginitemize
item $displaystyleint_0^x e^-t^2,dt$
item $displaystyleint_1^x frace^tt,dt$, for $t>0$.
enditemize
endexercise
Now we can print the exercises.
printexercises
enddocument

Be aware that with the approaches presented by now you cannot use printexercises for having exercises occur in arbitrary places. You can have exercises occur only in places of the document which in the source correspond to places behind the exercise-environments.
Perhaps an environment which does read its content under verbatim-catcode-régime for unexpanded-writing it to .aux-file in a way where from the .aux-file it gets read back under verbatim-catcode-régime also for defining a macro where scantokens will be applied to, and thus some sort of re-implementation of the label-ref-mechanism or of the tableofcontents-mechanism for verbatimized stuff might make it possible to make exercises printable throughout the entire document.
Implementing such a mechanism might be a nice challenge. But before taking that into consideration at all, exact information is needed on the intended usage and the desired "user-interface", i.e., what additional things you wish to be able to specify in which ways, etc, ...
answered 6 hours ago
Ulrich DiezUlrich Diez
5,460619
5,460619
add a comment |
add a comment |
Sébastien Loisel is a new contributor. Be nice, and check out our Code of Conduct.
Sébastien Loisel is a new contributor. Be nice, and check out our Code of Conduct.
Sébastien Loisel is a new contributor. Be nice, and check out our Code of Conduct.
Sébastien Loisel 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.
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%2f480267%2fhow-to-robustly-store-bits-of-text-for-later-use%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
1
Why not use
def?letdoes what it should do: use the the next token.– TeXnician
10 hours ago
If you mean this:
NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY, I get:! Undefined control sequence. foo ->BODY– Sébastien Loisel
9 hours ago
1
I'm not sure why you don't like
globalexpandafterletcsname barendcsnameBODY: it's entirely normal TeX.– Joseph Wright♦
9 hours ago
I started writing a class file to prepare conference programmes using the same sort of "save text for later" features. github.com/scmbradley/schedule I have just realised that this was six years ago. My god. Six years!?
– Seamus
9 hours ago
You should definitely use let with BODY, def with anything whose definition doesn't change, and edef with things that do change (and you don't mind expanding them).
– John Kormylo
7 hours ago