Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. documentclass[10pt,a4paper,oneside]{book}
  2. newcounter{questionnumber}
  3. usepackage[brazil]{babel}
  4. usepackage[usenames,dvipsnames]{xcolor}
  5. %----------------------------------------------------
  6. %Here is the answer key environment suggested by another forum.
  7. %It stores the answers by the command answer{}, which allocates
  8. %an organized list of answers at the end of the document,
  9. %by the using of showanswers command.
  10.  
  11. usepackage{xparse}
  12. ExplSyntaxOn
  13.  
  14. % first of all we define the user level commands
  15. NewDocumentCommand{answer}{ m }{ malmedal_input_add:n { #1 } }
  16. NewDocumentCommand{showanswers}{ }{ malmedal_output_direct: }
  17.  
  18. % allocate some variables:
  19. % 1. a sequence for global storage of the inputs;
  20. % 2. a temporary sequence when we need to reverse;
  21. % 3. a counter (integer variable)
  22. seq_new:N g_malmedal_input_seq
  23. seq_new:N l_malmedal_temp_seq
  24. int_new:N l_malmedal_count_int
  25.  
  26. % store globally an input in the sequence
  27. cs_new:Npn malmedal_input_add:n #1
  28. {
  29. seq_gput_right:Nn g_malmedal_input_seq { #1 }
  30. }
  31.  
  32. % how to output in direct order; we simply do a mapping function calling
  33. % malmedal_print:n after incrementing the counter
  34. cs_new_protected:Npn malmedal_output_direct:
  35. {
  36. int_zero:N l_malmedal_count_int
  37. seq_map_inline:Nn g_malmedal_input_seq
  38. {
  39. int_incr:N l_malmedal_count_int
  40. malmedal_print:n { ##1 }
  41. }
  42. }
  43.  
  44. % the printing macro; change here for adapting to your wishes
  45. cs_new:Npn malmedal_print:n #1
  46. {
  47. textcolor{RoyalBlue}{textbf{Question} ~ bfseriesint_to_arabic:n { l_malmedal_count_int }} ~ : ~ #1 par
  48. }
  49. ExplSyntaxOff
  50.  
  51. %----------------------------------------------------
  52. %Here I've built the question and the alternatives environment.
  53.  
  54. newcommand{makequestion}[2]{refstepcounter{questionnumber}parvspace{1em}noindenttextbf{(#1hspace{0mm}-hspace{0mm}textbf{#2})hspace{1mm}Questionhspace{0.3em}thequestionnumber.}\vspace{-4mm}ignorespaces}
  55. newcounter{lettercounter}[questionnumber]
  56. newcommand{alternative}{(alph{lettercounter})}
  57. newenvironment{options}{begin{list}{alternative}{usecounter{lettercounter}}}{end{list}}
  58. %----------------------------------------------------
  59. %Here I've built the itens environment
  60.  
  61. newcounter{itemcounter}[questionnumber]
  62. newcommand{newitem}{alph{itemcounter})}
  63. newenvironment{itens}{begin{list}{newitem}{usecounter{itemcounter}}}{end{list}}
  64.  
  65.  
  66. begin{document}
  67.  
  68. makequestion{MIT}{2014}
  69. answer{A}
  70.  
  71. What do you think about life?
  72.  
  73. begin{options}
  74. item I think it's a word.
  75. item I think it's not a word.
  76. end{options}
  77.  
  78. makequestion{MIT}{2011}
  79. answer{B}
  80.  
  81. Is it a boy or a girl?
  82.  
  83. begin{options}
  84. item A boy
  85. item Yes.
  86. end{options}
  87.  
  88. makequestion{MIT}{2013}
  89. answer{How can I improve my code for a) and b) itens answers to be recognized and appear here, in the Answer Key?}
  90.  
  91. Answer the itens below:
  92.  
  93. begin{itens}
  94. item Is $2>1$?
  95. item Is $3<2$?
  96. end{itens}
  97.  
  98. showanswers
  99. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement