
\startelements             dutch                     english
                            german                    czech
                            italian                   romanian
                            french

                     begin: beginvan                  start
                            anfang                    zacatek
                            inizio                    inceput
                            debut
                       end: eindvan                   stop
                            ende                      konec
                            fine                      sfarsit
                            fin

\stopelements


%
%   Zähler für die Punkte [summeP] = 0  
%
    \global\newcount\summeP \summeP=0
%
%   Die GesamtPunktZahl
%
    \ifx\MaxPkt\undefined 
        \def\MaxPkt{0}
    \fi
%
%
%   Schalter [ZeigeP] (intern) zur Steuerung der Anzeige der Punkte
%   Ausgangswert 0, d.h. die Punkte werden nicht angezeigt
%
    \chardef\ZeigeP=0
%
%   Schalter [addP] (intern) zur Steuerung der Berechnung der Gesamtpunkte
%   Ausgangswert 0, d.h. die Gesamtpunkte werden nicht berechnet
    \chardef\addP=0
%
%   Schalter [mitAZahl] (intern) zur Steuerung der Anzeige der Aufgabenanzahl
%   Ausgangswert 1, d.h. die Aufgabenzahl wird angezeigt
    \chardef\mitAZahl=1
%
%
%   Die Schalter für den Anwender  
%   direkt nach \starttext setzen
%   [1]
%   die Punkte der Aufgaben anzeigen
    \def\zeigePunkte{\chardef\ZeigeP=1}
%
%   [2]
%   die Gesamtpunktzahl berechnen
    \def\SummePunkte{\chardef\addP=1}
%
%   [3]
%   die Aufgabenanzahl nicht anzeigen
    \def\ohneAnzahl{\chardef\mitAZahl=0}
%
%
%   Berechnung der GesamtPunkte [getPunkte] durchführen
%
    \def\getPunkte[#1]{\global\advance\summeP by \number#1}
%
%
%   Punkte im rechten Rand ausgeben
%
    \def\showP[#1]{\inright{\hfill(#1 P.)}}
%
%
%   Die Behandlung der Punktangaben
% 
    \def\pkt[#1]%
    {%    
    \ifnum\ZeigeP=1
        \showP[#1]%
        \ifnum\addP=1
            \getPunkte[#1] 
       \fi
    \fi
    }
%

%
    \setuppapersize[a4][a4]
    \setuplayout[%
    height=27.0cm,
    rightmargin=2cm,%
    footer=1cm,%
    backspace=2.5cm,%
    topspace=1cm%
    ]
%

%\definecolor[gray][s=0.75]



\setupcolors  [state=start]
\definecolor  [colorone]    [r=0.625,g=0,b=0] %dark red
\definecolor  [colortwo]    [b=0.625,g=0,r=0] %dark blue

\def\assignment[#1]
  {\getrawparameters
    [Assign]
    [     title=
         course=,
       assigned=,
            due=,
              #1]
  \title{\Assigntitle}}

%D The \tex{title} takes care of setting up the assignment title. There are
%D probably better ways to do this!

\definefont [BigFontOne]  [RegularSlanted sa 1.5]
\definefont [BigFontTwo]  [Regular sa 1.5]





\setuphead[title]
 [  style=\BigFontOne,
  command=\assignmenttitle,
   before={\resetnumber[PROBLEM]\setuppagenumber[number=1]},
    after={\blank[big] \bgroup \colortwo
        \expanded{\Assignassigned}
    \hfill
     \expanded{\Assigndue}
   \egroup\blank},
 ]
%D I wanted the a frame with a shadow around the title. So I define a overlay
%D and use it as a background in \tex{assignmenttitle} below.

\startuniqueMPgraphic{shadow}
    fill OverlayBox shifted (3pt,-3pt) withcolor .8white ;
    fill OverlayBox withcolor white ;
    draw OverlayBox withcolor blue ;
    setbounds currentpicture to OverlayBox ;
\stopuniqueMPgraphic

\defineoverlay  [shadow]  [\uniqueMPgraphic{shadow}]

%D This macro does the actual typesetting of the title

\def\assignmenttitle#1#2%
  {\framed[
              width=broad,
              frame=off,
              align=middle,
    foregroundcolor=colortwo,
         % I want a shadow around the title frame
         background=shadow]
      {#2\\{\colorone\BigFontTwo\Assigncourse}}}

%D Next I setup the headers and footers. I want the header and footers to be
%D colored

\setupheader  [text]  [color=colortwo]
\setupfooter  [text]  [color=colortwo]

%D the assignment title to be shown in the header

\setupheadertexts [title]

%D say \quotation{Solutions} while generating solutions

\startmode[solution]
  \setupheadertexts [Solutions] []
\stopmode

%D show page number in middle of footer

\setupfootertexts [pagenumber]

%D show assigned and due dates in the footer

\setupfootertexts
  [My School]
  [Exam date]

%D On the first page, hide the header and only show page number in the footer.

\definetext [title] [footer]  [pagenumber]
\setuphead  [title] [header=high,footer=]

%D Now, I need to take care of the {\em body} of the document. First I define
%D the labeltext for problem, solution and points.

\setuplabeltext [problem=Questão,solution=Solução ]
\setuplabeltext [point=ponto,points=pontos]

%D Note the extra space after solution. This is because I use \mono{width=fit}
%D in \tex{defineenumeration[solution]} later.

%D Labeltext provide flexibility for the actual words used in the assignment.
%D This way, if I want to change problem to question, I can simply do
%D \starttyping
%D \setuplabeltext  [problem=Question]
%D \stoptyping

%D First I define an enumeration called \mono{PROBLEM}. This does bulk of the
%D work, but is hidden from the user.

\defineenumeration
  [PROBLEM]
  [     text={\labeltext{problem}},
    location=hanging,
   headstyle=\sc,
   headcolor=colorone,
      before={\resetnumber[formula]\page[desirable]},
       after=\blank,
  ]
  
  \defineenumeration
  [Question]
  [     text={\labeltext{problem}},
    location=hanging,
   headstyle=\sc,
   headcolor=colorone,
      before={\resetnumber[formula]\page[desirable]},
       after=\blank,
  ]

%D \macros{startproblem}
%D Now, I define the {\em real} \tex{startproblem}. This takes care of
%D references and points of each problem. The following syntax is allowed
%D \starttyping
%D \startproblem                % No tag or points
%D \startproblem [tag]          % Just the tag
%D \startproblem {points}       % Just the points
%D \startproblem [tag] {points} % Both the tag and the points
%D \stoptyping

\def\startproblem%
  {\dosingleempty\dostartproblem}

\def\dostartproblem[#1]%
  {\startPROBLEM[#1]\dosinglegroupempty\dodostartproblem}

\def\dodostartproblem#1%
  {\iffirstargument
  % Check if #1 = 1, use point, else use points
    \bgroup \colortwo (#1 \dopoints{#1}) \egroup
   \fi}

\def\dopoints#1%
  {\doifelse{#1}{1}{\labeltext{point}}{\labeltext{points}}}

\def\stopproblem%
  {\stopPROBLEM}

%D Next I setup itemize for the display of parts

%\setupitemize [each]  [left=(,right=),stopper=,color=colorone,repeat]
%\setupitemize [1]     [intro]
%\setupitemize [joinedup,packed]

%D Use characters (a,b,\unknown) at the first level and roman numberals (i, ii,
%D \unknown) at the second level.

%\setupitemize [1] [a,repeat]
%\setupitemize [2] [r,repeat]

%D \macros{startsolution}
%D In the default mode, the solution evironment should gobble its contents.
%D I copy the definition of \tex{starthiding} to {\em hide} the solutions.

\definebuffer [solution]
\setupbuffer  [solution]  [local=yes]

%D In solution mode, I redefine solution environment as an
%D enumeration without a number. There are probably better ways to define this
%D environment, but why reinvent the wheel?


\defineenumeration
    [Answer]
    [      text=\labeltext{solution},
         number=no,
      headstyle=bold,
      headcolor=colortwo,
       location=serried,
          width=fit,
         before=\startsolutionbackground,
          after=\stopsolutionbackground
    ]

%D The \filename{exam.cls} class in \LATEX\ allows you to put a frame around
%D the solution and the frame breaks across pages. I wanted to put a frame
%D around the solution, but something more informal than a rectangular frame.
%D \CONTEXT's manual gave hints on getting different kinds of frames, and I
%D finally settled for a randomized framed. The frame should
%D break around pages, so I used \tex{textbackground}.

\definetextbackground
    [solutionbackground]
    [           mp=background:random,
          location=paragraph,
     rulethickness=1pt,
        framecolor=colorone,
             width=local,
        leftoffset=1em,
       rightoffset=1em,
            before={\testpage[3]\blank[2*big]},
             after={\blank[2*big]}
    ]

%D The background in  \tex{textbackground} is drawn using a useMPgraphic
%D defined set by \mono{mp=}. I define a useMPgraphic \mono{background:random}
%D to get the frame that I wanted. The code looks a bit complicated, because
%D \tex{texbackground} is supposed to work in a multi||column documents.


%  A randomized frame
\startuseMPgraphic{background:random}
    path p;
    for i = 1 upto nofmultipars :
     p = (multipars[i]
      topenlarged 10pt
      bottomenlarged 10pt) randomized 4pt ;
    fill p withcolor lightgray ;
    draw p withcolor \MPvar{linecolor}
     withpen pencircle scaled \MPvar{linewidth};
    endfor;
\stopuseMPgraphic

%D An earlier attempt that draws a frame which is squeezed in the center.  To
%D use this change mp=background:random to mp=backgrond:squeezed in
%D \definetextbackground above.

\startuseMPgraphic{background:squeezed}
    path p;
    for i = 1 upto nofmultipars :
     p = multipars[i]
      topenlarged 10pt
      bottomenlarged 10pt
      squeezed 5pt
      randomized 1pt ;
      fill p withcolor lightgray ;
     draw p withcolor \MPvar{linecolor}
      withpen pencircle scaled \MPvar{linewidth};
    endfor;
\stopuseMPgraphic

%D By default, the textbackground extends till the page boundary. This does
%D not look good if a page break occurs when there is not enough material to
%D fit in the page. So, we want to limit textbackground till the typeset
%D material. This has not been interfaced yet, so I use a low level \TEX\
%D command.

\chardef\kindofpagetextareas\plusone
\stopmode

%D I also wanted an English rule at the end of each assignment. \CONTEXT\
%D already defines an English rule. I load \filename{meta-txt.tex} to use it.

\useMPlibrary [txt]

%D I want the English rule to match the color scheme of the entire document.

\setupMPvariables
  [EnglishRule]
  [color=colortwo,
   width=0.5\textwidth]

%D I redefined \tex{stopcomponent} to add the rule at the end of the file.

\let\normalstopcomponent\stopcomponent

\def\stopcomponent%
  {\dosomebreak\nobreak
  \framedtext[frame=off,strut=no,align=middle,width=\textwidth]
   {\EnglishRule}
   \normalstopcomponent}



%%%%%%%%%%%%%%%%%%


%\defineenumeration[Answer][text=Quest]
\defineenumeration
    [Answer]
    [      text=\labeltext{solution},
         number=yes,
      headstyle=bold,
      headcolor=colortwo,
       location=serried,
          width=fit,
         before=\startsolutionbackground,
          after=\stopsolutionbackground
    ]

%\defineenumeration[Question]

  \defineenumeration
  [Question]
  [     text={\labeltext{problem}},
    location=hanging,
   headstyle=\sc,
   headcolor=colorone,
   repeat=true,
      before={\resetnumber[formula]\page[desirable]},
       after=\blank,
  ]

\defineblock[answer,question]
\setupblock[answer][before={\startAnswer\resetscore},after={\savescore\stopAnswer}]
\setupblock[question][before={\startQuestion},after={\stopQuestion}]

\makecounter{totalscore}

\definelist[Score]
            [pagenumber=no,
             width=5em,
             height=broad,
             textcommand=\showscores,
             numbercommand=\showquestionnumber,
            ]

\def\showscores#1{\dotfill\emspace#1~pontos}
\def\showquestionnumber#1{Questão~#1}

\def\score[#1]%
   {\incrementcounter{totalscore}{#1}%
    \dotfill\emspace#1~pontos\endgraf}

\def\resetscore{\resetcounter{totalscore}}

\def\savescore{\expanded{\dowritetolist{Score}
    {\convertednumber[Answer]}{\countervalue{totalscore}}{Question}}}

\hideblocks[answer,question]

%%%%%%%%%%%%%%%%%
\def\generateexam
   {%\title{Exam}
   \assignment[
      title=Exam Title,
     course=Corse Title,  
     assigned={My School},
        due={ time }]
    \useblocks[question]
    \title{Question Score}
    \placelist[Score][criterium=all]
    \title{Correction Criterium}
\startitemize
\item
 Nas respostas que envolvam aplicação e/ou exposição de conceitos, serão tidos em conta os seguintes aspectos:
 \startitemize
 \item Explicação dos conceitos
\item Uso de linguagem científica
\item Expressão escrita
\stopitemize
\item
Nas respostas que envolvam cálculos, a cotação será desdobrada em:
\startitemize
\item Escrita correcta da expressão físico-matemática
\item Substituição de dados na expressão
\item Cálculos intermédios
\item Resultado final e unidade.
\stopitemize
\item
Na ausência de unidades, ou a sua indicação incorrecta, terá a penalização de um ponto no resultado final.
\item
Nos itens verdadeiro e falso cada resposta incorrecta será penalizada.
    \stopitemize
    
    \title{Critérios específicos de correcção}
    \useblocks[answer]}

\starttext
\zeigePunkte        % Punkte anzeigen
\SummePunkte        % Summe der Punkte berechnen
%\ohneAnzahl         % Gesamtzahl der Fragen nicht ausgeben
%\TitelvorFragen     % Der SpezialTitel auf der ersten Seite
%%%%%%%%%%%%%%
\startquestion
Leia atentamente as afirmações seguintes: \pkt[8]

\startitemize[A]
\item O ferro aparece na Natureza no estado nativo.
\item O cobre é muito utilizado devido à sua condutibilidade eléctrica.
\item A solda e o bronze têm em comum na sua constituição o estanho.
\item As ligas em que entra o mercúrio chamam-se amálgamas.
\item O ouro de 24 quilates é ouro puro.
\stopitemize

Seleccione a {\bf afirmação FALSA}. 


\startanswer
A \score[8]
\stopanswer

\stopquestion

%%%%%%%%%%%%%%
\startquestion 
Considere a reacção de oxidação-redução correspondente à equação
química \pkt[8]
\blank
Mg\high{2+}(aq) + H\low{2}(g) $
\mathbin{\lower.3ex\hbox{$\buildrel\textstyle\rightarrow\over
{\smash{\leftarrow}\vphantom{_{\vbox to.5ex{\vss}}}}$}} $Mg(s) + 2
H\high{+}(aq)
\blank
A constante de equilíbrio {\em K\low{c}} é muito menor
que 1, a 25 ºC.
\blank
Entre as seguintes alternativas, seleccione a {\bf
CORRECTA}.

\startitemize[A]
\item H\low{2}(g) oxida Mg(s) a Mg\high{2+}(aq).
\item $E$\high{0}(Mg\high{2+}(aq) / Mg(s)) > $E$\high{0}(H\high{+}(aq) / H\low{2}(g)). ($E$\high{0} = potencial normal de redução)
\item Mg(s) é um redutor mais forte do que H\low{2}(g), nas condições padrão.
\item A redução de Mg\high{2+}(aq) a Mg(s) é mais extensa do que a redução de H\high{+}(aq) a H\low{2}(g), nas condições padrão.
\item Mg\high{2+}(aq) é um oxidante mais forte do que H\high{+}(aq), nas condições padrão.
\stopitemize

\startanswer
C \score[8]
\stopanswer


\stopquestion



\generateexam


\stoptext
