Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. documentclass[12pt]{article}
  2. usepackage[utf8]{inputenc}
  3. usepackage[english]{babel}
  4. usepackage{listings}
  5. usepackage{enumitem}
  6.  
  7. usepackage{etoolbox}
  8. usepackage{pgfkeys}
  9. usepackage{pgfmath}
  10.  
  11. % code for generating a random permutation
  12. newcounter{randomListLength}% current length of our random list
  13. newcounter{randomListPosition}% current list index
  14. newcounter{newRandomListElementPosition}% position to insert new element
  15. % insert #1 into the next position of newRandomList unless the position
  16. % index randomListPosition is equal to newRandomListElementPosition in
  17. % which case the newRandomListElement is added first
  18. newcommandrandomlyInsertElement[1]{%
  19. stepcounter{randomListPosition}%
  20. ifnumvalue{randomListPosition}=value{newRandomListElementPosition}%
  21. listxaddnewRandomList{newRandomListElement}%
  22. fi%
  23. listxaddnewRandomList{#1}%
  24. }
  25. % randomlyInsertInList{list name}{new list length}{new element}
  26. newcommandrandomlyInsertInList[3]{%
  27. pgfmathparse{random(1,#2)}%
  28. setcounter{newRandomListElementPosition}{pgfmathresult}%
  29. ifnumvalue{newRandomListElementPosition}=#2relax%
  30. listcsxadd{#1}{#3}%
  31. else%
  32. defnewRandomList{}% start with an empty list
  33. defnewRandomListElement{#3}% and the element that we need to add
  34. setcounter{randomListPosition}{0}% starting from position 0
  35. xdefcurrentList{csuse{#1}}
  36. forlistlooprandomlyInsertElementcurrentList%
  37. csxdef{#1}{newRandomList}%
  38. fi%
  39. }
  40.  
  41. % define some pgfkeys to allow key-value arguments
  42. pgfkeys{/randomList/.is family, /randomList,
  43. environment/.code = {globalletcsbeginRandomListEnvironment{#1}
  44. globalletcsendRandomListEnvironment{end#1}
  45. },
  46. enumerate/.style = {environment=enumerate},
  47. itemize/.style = {environment=itemize},
  48. description/.style = {environment=description},
  49. seed/.code = {pgfmathsetseed{#1}}
  50. }
  51. pgfkeys{/randomList, enumerate}% enumerate is the default
  52.  
  53. % finally, the code to construct the randomly permuted list
  54. makeatletter
  55. newcounter{randomListCounter}% for constructing randomListItem@<k>'s
  56.  
  57. % useRandomItem{k} prints item number k
  58. newcommanduseRandomItem[1]{csname randomListItem@#1endcsname}
  59.  
  60. % setRandomItem{k} saves item number k for future use
  61. % and builds a random permutation at the same time
  62. defsetRandomItem#1par{stepcounter{randomListCounter}%
  63. expandafterprotected@xdefcsname randomListItem@therandomListCounterendcsname{noexpanditem#1}%
  64. randomlyInsertInList{randomlyOrderedList}{therandomListCounter}{therandomListCounter}%
  65. }%
  66. letrealitem=item
  67. makeatother
  68. newenvironment{randomList}[1][]{% optional argument -> pgfkeys
  69. pgfkeys{/randomList, #1}% process optional arguments
  70. setcounter{randomListLength}{0}% initialise length of random list
  71. defrandomlyOrderedList{}% initialise the random list of items
  72. % Nthing is printed in the main environment. Instead, item is
  73. % used to slurp the "contents" of the item into randomListItem@<counter>
  74. letitemsetRandomItem%
  75. }
  76. {% now construct the list environment by looping over the randomly ordered list
  77. letitemrealitem
  78. setcounter{randomListCounter}{0}
  79. beginRandomListEnvironmentrelax
  80. forlistloopuseRandomItemrandomlyOrderedList
  81. endRandomListEnvironment
  82. }
  83.  
  84. % test compatibility with enumitem
  85. usepackage{enumitem}
  86. newlist{Testlist}{enumerate}{1} %
  87. setlist[Testlist]{label*=alph*.}
  88. setlist{nosep}parindent=0pt% for more compact output
  89.  
  90. lstset{
  91. basicstyle=bfseriesscriptsizett,
  92. }
  93.  
  94. begin{document}
  95. LARGE
  96. begin{center}
  97. Do the following give categorical, discrete, or continuous responses?
  98. end{center}
  99. begin{randomList}
  100. item 1
  101.  
  102. item 2
  103.  
  104. item 3
  105.  
  106. item 4
  107.  
  108. item 5
  109.  
  110. item 6
  111.  
  112. item 7
  113.  
  114. item 8
  115.  
  116. item 9
  117.  
  118. item 10
  119.  
  120. end{randomList}
  121. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement