%%
%% This is file `qcm.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% qcm.dtx  (with options: `qcmstyle')
%%


%% Copyright (C) 2004, 2007 Didier Verna

%% This file is part of QCM.

%% QCM may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.1
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.1 or later is part of all distributions of LaTeX
%% version 1999/06/01 or later.

%% QCM consists of the files listed in the file `README'.

%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{qcm}[2004/11/27 v2.1
		      Multiple Choice Questionnaire style for LaTeX2e]

\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{verbatim}
\RequirePackage{tabularx}

\def\@headerfont{\bfseries}
\newcommand\headerfont[1]{\gdef\@headerfont{#1}}

\def\@X{X}
\newcommand\X[1]{\gdef\@X{#1}}

\def\pbs#1{\let\tmp=\\#1\let\\=\tmp}
\newcolumntype{D}{>{\pbs\centering}X}
\newcolumntype{Q}{>{\@headerfont}X}

\renewcommand\tabularxcolumn[1]{m{#1}}

\newcommand\makeform@nocorrection{%
  \addtocontents{frm}{\protect\end{tabularx}}
  \@starttoc{frm}}
\newcommand\makeform@correction{%
  \addtocontents{frm}{\protect\end{tabularx}}}

\newcommand\makemask@nocorrection{%
  \addtocontents{msk}{\protect\end{tabularx}}
  \@starttoc{msk}}
\newcommand\makemask@correction{%
  \addtocontents{msk}{\protect\end{tabularx}}}

\newlength\qcmspace
\setlength\qcmspace{0pt}

\newcommand\answerstitle[1]{\gdef\@answerstitle{#1}}

\def\@answerstitlefont{\bfseries}
\newcommand\answerstitlefont[1]{\gdef\@answerstitlefont{#1}}

\def\@answernumberfont{\bfseries}
\newcommand\answernumberfont[1]{\gdef\@answernumberfont{#1}}

\newcounter{qcm}\stepcounter{qcm}
\newcounter{@choice}

\def\@initorcheck{%
  \xdef\@choices{\the@choice}%
  \setcounter{@choice}{1}%
  \gdef\@arraydesc{|Q||}%
  \gdef\@headerline{}%
  \whiledo{\not{\value{@choice}>\@choices}}{
    \xdef\@arraydesc{\@arraydesc D|}
    \def\@appendheader{\g@addto@macro\@headerline}
    \@appendheader{&\protect\@headerfont}
    \edef\@the@choice{{\alph{@choice}}}
    \expandafter\@appendheader\@the@choice
    \stepcounter{@choice}}%
  \addtocontents{frm}{%
    \protect\begin{tabularx}{\protect\linewidth}{\@arraydesc}
    \protect\hline
    \@headerline\protect\\\protect\hline\protect\hline}%
  \addtocontents{msk}{%
    \protect\begin{tabularx}{\protect\linewidth}{\@arraydesc}
    \protect\hline
    \@headerline\protect\\\protect\hline\protect\hline}%
  \gdef\@initorcheck{%
    \ifthenelse{\value{@choice} = \@choices}{}{%
      \ClassError{QCM}{Question \theqcm: wrong number of choices
	(\the@choice\space instead of \@choices)}{%
	Questions must all have the same number of proposed answers.%
	\MessageBreak
	Type X <return> to quit, fix your QCM and rerun LaTeX.}}}}

\newenvironment{qcm}[1]{%
  %% \begin{qcm}
  \ifx\beforeqcm\undefined\else\beforeqcm\fi%
  \begin{minipage}[t]{\textwidth}
    \xdef\@formanswerline{\@qcmheader}%
    \xdef\@maskanswerline{\@qcmheader}%
    \fbox{\parbox[c]{\linewidth}{%
	\ifx\beforeqcmbody\undefined\else\beforeqcmbody\fi%
	#1}}
    \vspace\qcmspace\par
    {\@answerstitlefont\@answerstitle}
    \begin{list}{\@answernumberfont\alph{@choice}.~}{\usecounter{@choice}}}{%
  %% \end{qcm}
    \end{list}
    \@initorcheck%
    \addtocontents{frm}{\@formanswerline\protect\\\protect\hline}%
    \addtocontents{msk}{\@maskanswerline\protect\\\protect\hline}%
  \end{minipage}
  \stepcounter{qcm}}

\def\@truesymbol{$\rightarrow$~}
\def\@falsesymbol{$\times$~}
\newcommand\truesymbol[1]{\gdef\@truesymbol{#1}}
\newcommand\falsesymbol[1]{\gdef\@falsesymbol{#1}}

\def\@true@nocorrection{\item}
\def\@false@nocorrection{\item}
\def\@true@correction{\item[\@truesymbol\refstepcounter{@choice}]}
\def\@false@correction{\item[\@falsesymbol\refstepcounter{@choice}]}

\newcommand\true{%
  \xdef\@formanswerline{\@formanswerline&}%
  \xdef\@maskanswerline{\@maskanswerline&\@X}%
  \@true}%
\newcommand\false{%
  \xdef\@formanswerline{\@formanswerline&}%
  \xdef\@maskanswerline{\@maskanswerline&}%
  \@false}%

\def\@correctionstyle{\itshape}
\newcommand\correctionstyle[1]{\gdef\@correctionstyle{#1}}

\newenvironment{@correction}{\@correctionstyle}{}

\DeclareOption{english}{%
  \def\@qcmheader{Question n.\theqcm}
  \answerstitle{Possible answers:}}
\DeclareOption{french}{%
  \def\@qcmheader{Question n$^o$~\theqcm}
  \answerstitle{R\'eponses possibles~:}}
\DeclareOption{francais}{%
  \ExecuteOptions{french}}

\DeclareOption{nocorrection}{%
  \let\@true\@true@nocorrection
  \let\@false\@false@nocorrection
  \ifx\correction\undefined
    \let\correction\comment
    \let\endcorrection\endcomment
  \fi
  \def\makeform{\makeform@nocorrection}
  \def\makemask{\makemask@nocorrection}}
\DeclareOption{correction}{%
  \let\@true\@true@correction
  \let\@false\@false@correction
  \ifx\correction\undefined
    \let\correction\@correction
    \let\endcorrection\end@correction
  \fi
  \def\makeform{\makeform@correction}
  \def\makemask{\makemask@correction}}

\ExecuteOptions{english,nocorrection}
\ProcessOptions

\endinput
%%
%% End of file `qcm.sty'.
