Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- documentclass[12pt]{article}
- usepackage[utf8]{inputenc}
- usepackage[english]{babel}
- usepackage{listings}
- usepackage{enumitem}
- usepackage{etoolbox}
- usepackage{pgfkeys}
- usepackage{pgfmath}
- % code for generating a random permutation
- newcounter{randomListLength}% current length of our random list
- newcounter{randomListPosition}% current list index
- newcounter{newRandomListElementPosition}% position to insert new element
- % insert #1 into the next position of newRandomList unless the position
- % index randomListPosition is equal to newRandomListElementPosition in
- % which case the newRandomListElement is added first
- newcommandrandomlyInsertElement[1]{%
- stepcounter{randomListPosition}%
- ifnumvalue{randomListPosition}=value{newRandomListElementPosition}%
- listxaddnewRandomList{newRandomListElement}%
- fi%
- listxaddnewRandomList{#1}%
- }
- % randomlyInsertInList{list name}{new list length}{new element}
- newcommandrandomlyInsertInList[3]{%
- pgfmathparse{random(1,#2)}%
- setcounter{newRandomListElementPosition}{pgfmathresult}%
- ifnumvalue{newRandomListElementPosition}=#2relax%
- listcsxadd{#1}{#3}%
- else%
- defnewRandomList{}% start with an empty list
- defnewRandomListElement{#3}% and the element that we need to add
- setcounter{randomListPosition}{0}% starting from position 0
- xdefcurrentList{csuse{#1}}
- forlistlooprandomlyInsertElementcurrentList%
- csxdef{#1}{newRandomList}%
- fi%
- }
- % define some pgfkeys to allow key-value arguments
- pgfkeys{/randomList/.is family, /randomList,
- environment/.code = {globalletcsbeginRandomListEnvironment{#1}
- globalletcsendRandomListEnvironment{end#1}
- },
- enumerate/.style = {environment=enumerate},
- itemize/.style = {environment=itemize},
- description/.style = {environment=description},
- seed/.code = {pgfmathsetseed{#1}}
- }
- pgfkeys{/randomList, enumerate}% enumerate is the default
- % finally, the code to construct the randomly permuted list
- makeatletter
- newcounter{randomListCounter}% for constructing randomListItem@<k>'s
- % useRandomItem{k} prints item number k
- newcommanduseRandomItem[1]{csname randomListItem@#1endcsname}
- % setRandomItem{k} saves item number k for future use
- % and builds a random permutation at the same time
- defsetRandomItem#1par{stepcounter{randomListCounter}%
- expandafterprotected@xdefcsname randomListItem@therandomListCounterendcsname{noexpanditem#1}%
- randomlyInsertInList{randomlyOrderedList}{therandomListCounter}{therandomListCounter}%
- }%
- letrealitem=item
- makeatother
- newenvironment{randomList}[1][]{% optional argument -> pgfkeys
- pgfkeys{/randomList, #1}% process optional arguments
- setcounter{randomListLength}{0}% initialise length of random list
- defrandomlyOrderedList{}% initialise the random list of items
- % Nthing is printed in the main environment. Instead, item is
- % used to slurp the "contents" of the item into randomListItem@<counter>
- letitemsetRandomItem%
- }
- {% now construct the list environment by looping over the randomly ordered list
- letitemrealitem
- setcounter{randomListCounter}{0}
- beginRandomListEnvironmentrelax
- forlistloopuseRandomItemrandomlyOrderedList
- endRandomListEnvironment
- }
- % test compatibility with enumitem
- usepackage{enumitem}
- newlist{Testlist}{enumerate}{1} %
- setlist[Testlist]{label*=alph*.}
- setlist{nosep}parindent=0pt% for more compact output
- lstset{
- basicstyle=bfseriesscriptsizett,
- }
- begin{document}
- LARGE
- begin{center}
- Do the following give categorical, discrete, or continuous responses?
- end{center}
- begin{randomList}
- item 1
- item 2
- item 3
- item 4
- item 5
- item 6
- item 7
- item 8
- item 9
- item 10
- end{randomList}
- end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement