Randomly choose a symbol each time the document compiles
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I need to randomly change which symbol is attached to a particular command every time I compile my script.
I had hoped that this would be possible using the pgffor package, as in the minimal example below (where I am trying to redefine add each time I compile):
documentclassarticle
usepackagefdsymbol
usepackagepgffor
newcommandaddmedtriangleright
pgfmathsetseednumberpdfrandomseed
begindocument
pgfmathdeclarerandomlistchoicesrenewcommandaddpmrenewcommandadd+renewcommandaddcdot
foreachx in 1
pgfmathrandomitemchoicechoices
choicespace
$$5add4$$
enddocument
However this doesn't work. This is strange as this precise code works fine when I try to generate a random number from a list:
documentclassarticle
usepackagefdsymbol
usepackagepgffor
newcommandaddmedtriangleright
pgfmathsetseednumberpdfrandomseed
begindocument
pgfmathdeclarerandomlistchoices123
foreachx in 1
pgfmathrandomitemchoicechoices
choicespace
$$5add4$$
enddocument
Any ideas what I'm doing wrong here? Thanks in advance.
symbols random pgffor
New contributor
add a comment |Â
up vote
3
down vote
favorite
I need to randomly change which symbol is attached to a particular command every time I compile my script.
I had hoped that this would be possible using the pgffor package, as in the minimal example below (where I am trying to redefine add each time I compile):
documentclassarticle
usepackagefdsymbol
usepackagepgffor
newcommandaddmedtriangleright
pgfmathsetseednumberpdfrandomseed
begindocument
pgfmathdeclarerandomlistchoicesrenewcommandaddpmrenewcommandadd+renewcommandaddcdot
foreachx in 1
pgfmathrandomitemchoicechoices
choicespace
$$5add4$$
enddocument
However this doesn't work. This is strange as this precise code works fine when I try to generate a random number from a list:
documentclassarticle
usepackagefdsymbol
usepackagepgffor
newcommandaddmedtriangleright
pgfmathsetseednumberpdfrandomseed
begindocument
pgfmathdeclarerandomlistchoices123
foreachx in 1
pgfmathrandomitemchoicechoices
choicespace
$$5add4$$
enddocument
Any ideas what I'm doing wrong here? Thanks in advance.
symbols random pgffor
New contributor
Why do you use theforeach
loop? It doesn't seem to do anything in your example.
â David Purton
1 hour ago
As an aside, use[ â¦]
instead of$$ ⦠$$
for display maths. See tex.stackexchange.com/q/503/87678
â David Purton
1 hour ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I need to randomly change which symbol is attached to a particular command every time I compile my script.
I had hoped that this would be possible using the pgffor package, as in the minimal example below (where I am trying to redefine add each time I compile):
documentclassarticle
usepackagefdsymbol
usepackagepgffor
newcommandaddmedtriangleright
pgfmathsetseednumberpdfrandomseed
begindocument
pgfmathdeclarerandomlistchoicesrenewcommandaddpmrenewcommandadd+renewcommandaddcdot
foreachx in 1
pgfmathrandomitemchoicechoices
choicespace
$$5add4$$
enddocument
However this doesn't work. This is strange as this precise code works fine when I try to generate a random number from a list:
documentclassarticle
usepackagefdsymbol
usepackagepgffor
newcommandaddmedtriangleright
pgfmathsetseednumberpdfrandomseed
begindocument
pgfmathdeclarerandomlistchoices123
foreachx in 1
pgfmathrandomitemchoicechoices
choicespace
$$5add4$$
enddocument
Any ideas what I'm doing wrong here? Thanks in advance.
symbols random pgffor
New contributor
I need to randomly change which symbol is attached to a particular command every time I compile my script.
I had hoped that this would be possible using the pgffor package, as in the minimal example below (where I am trying to redefine add each time I compile):
documentclassarticle
usepackagefdsymbol
usepackagepgffor
newcommandaddmedtriangleright
pgfmathsetseednumberpdfrandomseed
begindocument
pgfmathdeclarerandomlistchoicesrenewcommandaddpmrenewcommandadd+renewcommandaddcdot
foreachx in 1
pgfmathrandomitemchoicechoices
choicespace
$$5add4$$
enddocument
However this doesn't work. This is strange as this precise code works fine when I try to generate a random number from a list:
documentclassarticle
usepackagefdsymbol
usepackagepgffor
newcommandaddmedtriangleright
pgfmathsetseednumberpdfrandomseed
begindocument
pgfmathdeclarerandomlistchoices123
foreachx in 1
pgfmathrandomitemchoicechoices
choicespace
$$5add4$$
enddocument
Any ideas what I'm doing wrong here? Thanks in advance.
symbols random pgffor
symbols random pgffor
New contributor
New contributor
New contributor
asked 2 hours ago
Matthew
161
161
New contributor
New contributor
Why do you use theforeach
loop? It doesn't seem to do anything in your example.
â David Purton
1 hour ago
As an aside, use[ â¦]
instead of$$ ⦠$$
for display maths. See tex.stackexchange.com/q/503/87678
â David Purton
1 hour ago
add a comment |Â
Why do you use theforeach
loop? It doesn't seem to do anything in your example.
â David Purton
1 hour ago
As an aside, use[ â¦]
instead of$$ ⦠$$
for display maths. See tex.stackexchange.com/q/503/87678
â David Purton
1 hour ago
Why do you use the
foreach
loop? It doesn't seem to do anything in your example.â David Purton
1 hour ago
Why do you use the
foreach
loop? It doesn't seem to do anything in your example.â David Purton
1 hour ago
As an aside, use
[ â¦]
instead of $$ ⦠$$
for display maths. See tex.stackexchange.com/q/503/87678â David Purton
1 hour ago
As an aside, use
[ â¦]
instead of $$ ⦠$$
for display maths. See tex.stackexchange.com/q/503/87678â David Purton
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
Unless I misunderstand your question, you don't need the renewcommand
macros or foreach
loop. You can also randomly change the operator mid way through the document.
documentclassarticle
usepackagefdsymbol
usepackagepgf
pgfmathsetseednumberpdfrandomseed
pgfmathdeclarerandomlistchoicesmedtrianglerightpm+cdot
begindocument
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
enddocument
Every time I recompile, I get the sameop
...
â Steven B. Segletes
1 hour ago
1
@StevenB.Segletes, that's weird. It works fine for me. Giving a random operator each time. Obviously some repeats with just four choices.
â David Purton
1 hour ago
Now it is working! I can't explain, but please take my upvote.
â Steven B. Segletes
24 mins ago
add a comment |Â
up vote
3
down vote
You don't need renewcommand
.
documentclassarticle
usepackagepgffor
%pgfmathsetseednumberpdfrandomseed
newcommandaddpgfmathrandomitemchoicechoiceschoice
pgfmathdeclarerandomlistchoicespm+cdot
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
A much more intuitive version with expl3
(not yet working with XeLaTeX, though).
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandadd
clist_rand_item:N c_matthew_add_symbols_clist
clist_const:Nn c_matthew_add_symbols_clist pm, +, cdot
ExplSyntaxOff
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
This idea has more advantages, because it can be used in a âÂÂfull expansionâ context, which the PGF version can't.
Why do you comment out the random seed? Without this, I get the same outcome each time I compile.
â David Purton
1 hour ago
@DavidPurton That's exactly for debugging. Uncomment it for the production version.
â egreg
59 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Unless I misunderstand your question, you don't need the renewcommand
macros or foreach
loop. You can also randomly change the operator mid way through the document.
documentclassarticle
usepackagefdsymbol
usepackagepgf
pgfmathsetseednumberpdfrandomseed
pgfmathdeclarerandomlistchoicesmedtrianglerightpm+cdot
begindocument
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
enddocument
Every time I recompile, I get the sameop
...
â Steven B. Segletes
1 hour ago
1
@StevenB.Segletes, that's weird. It works fine for me. Giving a random operator each time. Obviously some repeats with just four choices.
â David Purton
1 hour ago
Now it is working! I can't explain, but please take my upvote.
â Steven B. Segletes
24 mins ago
add a comment |Â
up vote
3
down vote
Unless I misunderstand your question, you don't need the renewcommand
macros or foreach
loop. You can also randomly change the operator mid way through the document.
documentclassarticle
usepackagefdsymbol
usepackagepgf
pgfmathsetseednumberpdfrandomseed
pgfmathdeclarerandomlistchoicesmedtrianglerightpm+cdot
begindocument
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
enddocument
Every time I recompile, I get the sameop
...
â Steven B. Segletes
1 hour ago
1
@StevenB.Segletes, that's weird. It works fine for me. Giving a random operator each time. Obviously some repeats with just four choices.
â David Purton
1 hour ago
Now it is working! I can't explain, but please take my upvote.
â Steven B. Segletes
24 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Unless I misunderstand your question, you don't need the renewcommand
macros or foreach
loop. You can also randomly change the operator mid way through the document.
documentclassarticle
usepackagefdsymbol
usepackagepgf
pgfmathsetseednumberpdfrandomseed
pgfmathdeclarerandomlistchoicesmedtrianglerightpm+cdot
begindocument
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
enddocument
Unless I misunderstand your question, you don't need the renewcommand
macros or foreach
loop. You can also randomly change the operator mid way through the document.
documentclassarticle
usepackagefdsymbol
usepackagepgf
pgfmathsetseednumberpdfrandomseed
pgfmathdeclarerandomlistchoicesmedtrianglerightpm+cdot
begindocument
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
pgfmathrandomitemopchoices
[ 5 op 4 ]
enddocument
edited 1 hour ago
answered 1 hour ago
David Purton
7,2091834
7,2091834
Every time I recompile, I get the sameop
...
â Steven B. Segletes
1 hour ago
1
@StevenB.Segletes, that's weird. It works fine for me. Giving a random operator each time. Obviously some repeats with just four choices.
â David Purton
1 hour ago
Now it is working! I can't explain, but please take my upvote.
â Steven B. Segletes
24 mins ago
add a comment |Â
Every time I recompile, I get the sameop
...
â Steven B. Segletes
1 hour ago
1
@StevenB.Segletes, that's weird. It works fine for me. Giving a random operator each time. Obviously some repeats with just four choices.
â David Purton
1 hour ago
Now it is working! I can't explain, but please take my upvote.
â Steven B. Segletes
24 mins ago
Every time I recompile, I get the same
op
...â Steven B. Segletes
1 hour ago
Every time I recompile, I get the same
op
...â Steven B. Segletes
1 hour ago
1
1
@StevenB.Segletes, that's weird. It works fine for me. Giving a random operator each time. Obviously some repeats with just four choices.
â David Purton
1 hour ago
@StevenB.Segletes, that's weird. It works fine for me. Giving a random operator each time. Obviously some repeats with just four choices.
â David Purton
1 hour ago
Now it is working! I can't explain, but please take my upvote.
â Steven B. Segletes
24 mins ago
Now it is working! I can't explain, but please take my upvote.
â Steven B. Segletes
24 mins ago
add a comment |Â
up vote
3
down vote
You don't need renewcommand
.
documentclassarticle
usepackagepgffor
%pgfmathsetseednumberpdfrandomseed
newcommandaddpgfmathrandomitemchoicechoiceschoice
pgfmathdeclarerandomlistchoicespm+cdot
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
A much more intuitive version with expl3
(not yet working with XeLaTeX, though).
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandadd
clist_rand_item:N c_matthew_add_symbols_clist
clist_const:Nn c_matthew_add_symbols_clist pm, +, cdot
ExplSyntaxOff
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
This idea has more advantages, because it can be used in a âÂÂfull expansionâ context, which the PGF version can't.
Why do you comment out the random seed? Without this, I get the same outcome each time I compile.
â David Purton
1 hour ago
@DavidPurton That's exactly for debugging. Uncomment it for the production version.
â egreg
59 mins ago
add a comment |Â
up vote
3
down vote
You don't need renewcommand
.
documentclassarticle
usepackagepgffor
%pgfmathsetseednumberpdfrandomseed
newcommandaddpgfmathrandomitemchoicechoiceschoice
pgfmathdeclarerandomlistchoicespm+cdot
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
A much more intuitive version with expl3
(not yet working with XeLaTeX, though).
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandadd
clist_rand_item:N c_matthew_add_symbols_clist
clist_const:Nn c_matthew_add_symbols_clist pm, +, cdot
ExplSyntaxOff
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
This idea has more advantages, because it can be used in a âÂÂfull expansionâ context, which the PGF version can't.
Why do you comment out the random seed? Without this, I get the same outcome each time I compile.
â David Purton
1 hour ago
@DavidPurton That's exactly for debugging. Uncomment it for the production version.
â egreg
59 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You don't need renewcommand
.
documentclassarticle
usepackagepgffor
%pgfmathsetseednumberpdfrandomseed
newcommandaddpgfmathrandomitemchoicechoiceschoice
pgfmathdeclarerandomlistchoicespm+cdot
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
A much more intuitive version with expl3
(not yet working with XeLaTeX, though).
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandadd
clist_rand_item:N c_matthew_add_symbols_clist
clist_const:Nn c_matthew_add_symbols_clist pm, +, cdot
ExplSyntaxOff
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
This idea has more advantages, because it can be used in a âÂÂfull expansionâ context, which the PGF version can't.
You don't need renewcommand
.
documentclassarticle
usepackagepgffor
%pgfmathsetseednumberpdfrandomseed
newcommandaddpgfmathrandomitemchoicechoiceschoice
pgfmathdeclarerandomlistchoicespm+cdot
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
A much more intuitive version with expl3
(not yet working with XeLaTeX, though).
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandadd
clist_rand_item:N c_matthew_add_symbols_clist
clist_const:Nn c_matthew_add_symbols_clist pm, +, cdot
ExplSyntaxOff
begindocument
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
$5add4$
enddocument
This idea has more advantages, because it can be used in a âÂÂfull expansionâ context, which the PGF version can't.
edited 53 mins ago
answered 1 hour ago
egreg
692k8518433092
692k8518433092
Why do you comment out the random seed? Without this, I get the same outcome each time I compile.
â David Purton
1 hour ago
@DavidPurton That's exactly for debugging. Uncomment it for the production version.
â egreg
59 mins ago
add a comment |Â
Why do you comment out the random seed? Without this, I get the same outcome each time I compile.
â David Purton
1 hour ago
@DavidPurton That's exactly for debugging. Uncomment it for the production version.
â egreg
59 mins ago
Why do you comment out the random seed? Without this, I get the same outcome each time I compile.
â David Purton
1 hour ago
Why do you comment out the random seed? Without this, I get the same outcome each time I compile.
â David Purton
1 hour ago
@DavidPurton That's exactly for debugging. Uncomment it for the production version.
â egreg
59 mins ago
@DavidPurton That's exactly for debugging. Uncomment it for the production version.
â egreg
59 mins ago
add a comment |Â
Matthew is a new contributor. Be nice, and check out our Code of Conduct.
Matthew is a new contributor. Be nice, and check out our Code of Conduct.
Matthew is a new contributor. Be nice, and check out our Code of Conduct.
Matthew 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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f457054%2frandomly-choose-a-symbol-each-time-the-document-compiles%23new-answer', 'question_page');
);
Post as a guest
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
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
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
Why do you use the
foreach
loop? It doesn't seem to do anything in your example.â David Purton
1 hour ago
As an aside, use
[ â¦]
instead of$$ ⦠$$
for display maths. See tex.stackexchange.com/q/503/87678â David Purton
1 hour ago