Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- documentclass[10pt,a4paper,oneside]{book}
- newcounter{questionnumber}
- usepackage[brazil]{babel}
- usepackage[usenames,dvipsnames]{xcolor}
- %----------------------------------------------------
- %Here is the answer key environment suggested by another forum.
- %It stores the answers by the command answer{}, which allocates
- %an organized list of answers at the end of the document,
- %by the using of showanswers command.
- usepackage{xparse}
- ExplSyntaxOn
- % first of all we define the user level commands
- NewDocumentCommand{answer}{ m }{ malmedal_input_add:n { #1 } }
- NewDocumentCommand{showanswers}{ }{ malmedal_output_direct: }
- % allocate some variables:
- % 1. a sequence for global storage of the inputs;
- % 2. a temporary sequence when we need to reverse;
- % 3. a counter (integer variable)
- seq_new:N g_malmedal_input_seq
- seq_new:N l_malmedal_temp_seq
- int_new:N l_malmedal_count_int
- % store globally an input in the sequence
- cs_new:Npn malmedal_input_add:n #1
- {
- seq_gput_right:Nn g_malmedal_input_seq { #1 }
- }
- % how to output in direct order; we simply do a mapping function calling
- % malmedal_print:n after incrementing the counter
- cs_new_protected:Npn malmedal_output_direct:
- {
- int_zero:N l_malmedal_count_int
- seq_map_inline:Nn g_malmedal_input_seq
- {
- int_incr:N l_malmedal_count_int
- malmedal_print:n { ##1 }
- }
- }
- % the printing macro; change here for adapting to your wishes
- cs_new:Npn malmedal_print:n #1
- {
- textcolor{RoyalBlue}{textbf{Question} ~ bfseriesint_to_arabic:n { l_malmedal_count_int }} ~ : ~ #1 par
- }
- ExplSyntaxOff
- %----------------------------------------------------
- %Here I've built the question and the alternatives environment.
- newcommand{makequestion}[2]{refstepcounter{questionnumber}parvspace{1em}noindenttextbf{(#1hspace{0mm}-hspace{0mm}textbf{#2})hspace{1mm}Questionhspace{0.3em}thequestionnumber.}\vspace{-4mm}ignorespaces}
- newcounter{lettercounter}[questionnumber]
- newcommand{alternative}{(alph{lettercounter})}
- newenvironment{options}{begin{list}{alternative}{usecounter{lettercounter}}}{end{list}}
- %----------------------------------------------------
- %Here I've built the itens environment
- newcounter{itemcounter}[questionnumber]
- newcommand{newitem}{alph{itemcounter})}
- newenvironment{itens}{begin{list}{newitem}{usecounter{itemcounter}}}{end{list}}
- begin{document}
- makequestion{MIT}{2014}
- answer{A}
- What do you think about life?
- begin{options}
- item I think it's a word.
- item I think it's not a word.
- end{options}
- makequestion{MIT}{2011}
- answer{B}
- Is it a boy or a girl?
- begin{options}
- item A boy
- item Yes.
- end{options}
- makequestion{MIT}{2013}
- answer{How can I improve my code for a) and b) itens answers to be recognized and appear here, in the Answer Key?}
- Answer the itens below:
- begin{itens}
- item Is $2>1$?
- item Is $3<2$?
- end{itens}
- showanswers
- end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement