How to robustly store bits of text for later use Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)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
What does it mean that physics no longer uses mechanical models to describe phenomena?
What does 丫 mean? 丫是什么意思?
macOS: Name for app shortcut screen found by pinching with thumb and three fingers
Girl Hackers - Logic Puzzle
What order were files/directories output in dir?
How much damage would a cupful of neutron star matter do to the Earth?
Does the Mueller report show a conspiracy between Russia and the Trump Campaign?
Most bit efficient text communication method?
Do I really need to have a message in a novel to appeal to readers?
Semigroups with no morphisms between them
How does the math work when buying airline miles?
How do living politicians protect their readily obtainable signatures from misuse?
Is there public access to the Meteor Crater in Arizona?
What does Turing mean by this statement?
AppleTVs create a chatty alternate WiFi network
What do you call the main part of a joke?
What is the difference between a "ranged attack" and a "ranged weapon attack"?
How many time has Arya actually used Needle?
Do wooden building fires get hotter than 600°C?
Why can't I install Tomboy in Ubuntu Mate 19.04?
Misunderstanding of Sylow theory
Time evolution of a Gaussian wave packet, why convert to k-space?
Why weren't discrete x86 CPUs ever used in game hardware?
The test team as an enemy of development? And how can this be avoided?
How to robustly store bits of text for later use
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)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
|
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
1
Why not usedef
?let
does what it should do: use the the next token.
– TeXnician
Mar 19 at 13:02
If you mean this:NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY
, I get:! Undefined control sequence. foo ->BODY
– Sébastien Loisel
Mar 19 at 13:09
1
I'm not sure why you don't likeglobalexpandafterletcsname barendcsnameBODY
: it's entirely normal TeX.
– Joseph Wright♦
Mar 19 at 13:31
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
Mar 19 at 13:47
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
Mar 19 at 16:05
|
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
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
edited Mar 19 at 15:40
Sébastien Loisel
asked Mar 19 at 12:59
Sébastien LoiselSébastien Loisel
1284
1284
1
Why not usedef
?let
does what it should do: use the the next token.
– TeXnician
Mar 19 at 13:02
If you mean this:NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY
, I get:! Undefined control sequence. foo ->BODY
– Sébastien Loisel
Mar 19 at 13:09
1
I'm not sure why you don't likeglobalexpandafterletcsname barendcsnameBODY
: it's entirely normal TeX.
– Joseph Wright♦
Mar 19 at 13:31
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
Mar 19 at 13:47
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
Mar 19 at 16:05
|
show 1 more comment
1
Why not usedef
?let
does what it should do: use the the next token.
– TeXnician
Mar 19 at 13:02
If you mean this:NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY
, I get:! Undefined control sequence. foo ->BODY
– Sébastien Loisel
Mar 19 at 13:09
1
I'm not sure why you don't likeglobalexpandafterletcsname barendcsnameBODY
: it's entirely normal TeX.
– Joseph Wright♦
Mar 19 at 13:31
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
Mar 19 at 13:47
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
Mar 19 at 16:05
1
1
Why not use
def
? let
does what it should do: use the the next token.– TeXnician
Mar 19 at 13:02
Why not use
def
? let
does what it should do: use the the next token.– TeXnician
Mar 19 at 13:02
If you mean this:
NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY
, I get: ! Undefined control sequence. foo ->BODY
– Sébastien Loisel
Mar 19 at 13:09
If you mean this:
NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY
, I get: ! Undefined control sequence. foo ->BODY
– Sébastien Loisel
Mar 19 at 13:09
1
1
I'm not sure why you don't like
globalexpandafterletcsname barendcsnameBODY
: it's entirely normal TeX.– Joseph Wright♦
Mar 19 at 13:31
I'm not sure why you don't like
globalexpandafterletcsname barendcsnameBODY
: it's entirely normal TeX.– Joseph Wright♦
Mar 19 at 13:31
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
Mar 19 at 13:47
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
Mar 19 at 13:47
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
Mar 19 at 16:05
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
Mar 19 at 16:05
|
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
Mar 19 at 15:40
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♦
Mar 19 at 13:34
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
Mar 19 at 14:42
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
Mar 19 at 14:43
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
Mar 19 at 15:04
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
Mar 19 at 15:14
|
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
);
);
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
Mar 19 at 15:40
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
Mar 19 at 15:40
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 Mar 19 at 15:34
egregegreg
735k8919343259
735k8919343259
Oh this is good
– Sébastien Loisel
Mar 19 at 15:40
add a comment |
Oh this is good
– Sébastien Loisel
Mar 19 at 15:40
Oh this is good
– Sébastien Loisel
Mar 19 at 15:40
Oh this is good
– Sébastien Loisel
Mar 19 at 15:40
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♦
Mar 19 at 13:34
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
Mar 19 at 14:42
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
Mar 19 at 14:43
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
Mar 19 at 15:04
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
Mar 19 at 15:14
|
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♦
Mar 19 at 13:34
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
Mar 19 at 14:42
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
Mar 19 at 14:43
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
Mar 19 at 15:04
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
Mar 19 at 15:14
|
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 Mar 19 at 13:40
answered Mar 19 at 13:34
Joseph Wright♦Joseph Wright
206k23566895
206k23566895
This needs TL'19 or up-to-date MiKTeX: this is a new feature inxparse
.
– Joseph Wright♦
Mar 19 at 13:34
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
Mar 19 at 14:42
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
Mar 19 at 14:43
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
Mar 19 at 15:04
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
Mar 19 at 15:14
|
show 2 more comments
This needs TL'19 or up-to-date MiKTeX: this is a new feature inxparse
.
– Joseph Wright♦
Mar 19 at 13:34
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
Mar 19 at 14:42
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
Mar 19 at 14:43
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
Mar 19 at 15:04
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
Mar 19 at 15:14
This needs TL'19 or up-to-date MiKTeX: this is a new feature in
xparse
.– Joseph Wright♦
Mar 19 at 13:34
This needs TL'19 or up-to-date MiKTeX: this is a new feature in
xparse
.– Joseph Wright♦
Mar 19 at 13:34
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
Mar 19 at 14:42
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
Mar 19 at 14:42
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
Mar 19 at 14:43
@SébastienLoisel Well if you have anything that's not LaTeX2e robust, yes, but that is nowadays quite a low risk.
– Joseph Wright♦
Mar 19 at 14:43
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
Mar 19 at 15:04
What's an example of something not LaTeX2e robust?
– Sébastien Loisel
Mar 19 at 15:04
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
Mar 19 at 15:14
Nevermind, I tried with beginitemize...enditemize and it broke.
– Sébastien Loisel
Mar 19 at 15:14
|
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 Mar 19 at 17:01
Ulrich DiezUlrich Diez
5,725620
5,725620
add a comment |
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');
);
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
?let
does what it should do: use the the next token.– TeXnician
Mar 19 at 13:02
If you mean this:
NewEnvirontestcglobalexpandafterdefcsname fooendcsnameBODY
, I get:! Undefined control sequence. foo ->BODY
– Sébastien Loisel
Mar 19 at 13:09
1
I'm not sure why you don't like
globalexpandafterletcsname barendcsnameBODY
: it's entirely normal TeX.– Joseph Wright♦
Mar 19 at 13:31
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
Mar 19 at 13:47
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
Mar 19 at 16:05