Randomly choose a symbol each time the document compiles

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|improve this question







New contributor




Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • 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














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.










share|improve this question







New contributor




Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • 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












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.










share|improve this question







New contributor




Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question







New contributor




Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









Matthew

161




161




New contributor




Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Matthew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • 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
















  • 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















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










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


enter image description here






share|improve this answer






















  • Every time I recompile, I get the same op...
    – 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

















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


enter image description here



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.






share|improve this answer






















  • 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










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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Matthew is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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






























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


enter image description here






share|improve this answer






















  • Every time I recompile, I get the same op...
    – 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














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


enter image description here






share|improve this answer






















  • Every time I recompile, I get the same op...
    – 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












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


enter image description here






share|improve this answer














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


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 1 hour ago

























answered 1 hour ago









David Purton

7,2091834




7,2091834











  • Every time I recompile, I get the same op...
    – 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






  • 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










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


enter image description here



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.






share|improve this answer






















  • 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














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


enter image description here



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.






share|improve this answer






















  • 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












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


enter image description here



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.






share|improve this answer














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


enter image description here



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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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










Matthew is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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.













 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

Installing NextGIS Connect into QGIS 3?

One-line joke