\documentclass{article}
\usepackage{amsmath}
\usepackage
    [tight,
     pdftex,
     designiv,
     nodirectory
    ]{web}  % dvipsone, dvips, pdftex, dvipdfm
\usepackage{exerquiz}
\usepackage[indefIntegral]{dljslib}

\title{Partial Credit for Text Fill-in Questions}
\author{D. P. Story}
\subject{Sample file}
\keywords{LaTeX, PDF, derivative, calculus, JavaScript}

\university{NORTHWEST FLORIDA STATE COLLEGE\\
Department of Mathematics}
\email{dpstory@uakron.edu}
\version{2.0}
\copyrightyears{1999-\the\year}

\nocopyright
\norevisionLabel

\useBeginQuizButton[\BC{}\textColor{1 0 0}\CA{Start}] % use buttons
\useEndQuizButton[\BC{}\textColor{1 0 0}\CA{End}]
\PTsHook{($\eqPTs^{\text{pts}}$)}
\fancyQuizHeaders
\showCreditMarkup

\newcommand{\cs}[1]{\texttt{\char`\\#1}}

\begin{document}

\maketitle

\section{Introduction}

We introduce a new command \cs{RespBoxTxtPC}, for processing text
fill-in questions so that partial credit is awarded for the answer.
The idea and the syntax was suggested to me by Kate of Kenya.
Documentation is not available yet, we are content with presenting
an example.

\newpage

\section{A Quiz}

\titleQuiz{Quiz 1}
\begin{quiz}{q1}
\begin{questions}
\item\PTs{2} Who was the first President of the United States?\\[3bp]
\RespBoxTxtPC[\rectW{3in}]{3}*{3}%
    [0.5]{(\word{President}|\word{Pres.{0,1}}|\word{General}|\word{Gen.{0,1}})}
    [0.5]{(\word{George}|\word{Geo.{0,1}})}
    [1.0]{\word{Washington}}\kern1bp\CorrAnsButton{President George Washington}
\begin{solution}
One response to this question is
\medskip
\begin{quote}
President$^\text{0.5pt}$ (or Pres.\ or General or Gen.) George$^\text{0.5pt}$ (or Geo.)
Washington$^\text{1pt}$
\end{quote}
\end{solution}
\item\PTs{8} Write a short paragraph (in complete sentences) on the defeat of Napoleon Bonaparte by the Seventh
Coalition. Include the name of the famous battle, the country in which the battle occurred,
the year of the battle, and the name of the commander of the Anglo-Allied army.\\[3pt]
\RespBoxTxtPC[\Ff{\FfMultiline}\rectW{.9\linewidth}\rectH{4\baselineskip}]{3}*{7}%
    [1]{(Napoleon|Bonaparte)}
    [.5]{Battle}
    [.5]{defeated}
    [2]{Waterloo}
    [1]{Belgium}
    [1]{1815}
    [2]{((Duke\\s+of\\s+){0,1}Wellington|Arthur\\s+Wellesley)}\CorrAnsButton{Shift-click for a complete answer}
\begin{solution}
One such paragraph is
\begin{quote}\raggedright
\underbar{Napoleon}$^\text{1pt}$ (or \underbar{Bonaparte}) was
\underbar{defeated}$^\text{0.5pt}$ at the
\underbar{Battle}$^\text{0.5pt}$ of
\underbar{Waterloo}$^\text{2pt}$, \underbar{Belgium}$^\text{1pt}$,
in \underbar{1815}$^\text{1pt}$, by the \underbar{Duke of Wellington}$^\text{2pt}$
(or \underbar{Arthur Wellesley}).
\end{quote}
\end{solution}
\end{questions}
\end{quiz}\quad\PointsField\currQuiz\eqButton\currQuiz

\noindent
Answers: \AnswerField[\rectW{3in}]\currQuiz

\section{Syntax }

\textsf{Exerquiz} can now create text fill-in questions that awards
credit each time one of the key words are found in the student's input string.

\medskip\noindent
The command \cs{RespBoxTxtPC} is the one that creates a text fill-in question. Its
syntax is
\begin{small}
\begin{verbatim}
\RespBoxTxt[#1]#2[#3]#4[<num1>]{<word1>}...[<num_n>]{<word_n>}
\end{verbatim}
\end{small}%
The new command \cs{RespBoxTxtPC} behaves differently than \cs{RespBoxTxt}.
JavaScript performs a regular expression search for each word listed (the word,
can be a regular expression), if the word is found (the search is successful), the total credit
for this problem is incremented by the amount associated with the word.

\medskip\noindent\textbf{\hypertarget{paraRespBoxTxt}{Parameters:}}
\begin{enumerate}
\item[\ttfamily\#1:]Optional parameter used to modify the appearance of the
    text field.
\item[\ttfamily\#2:]This required parameter is a number indicating
the filtering method to be used. Permissible values of this parameter are
\begin{enumerate}
    \item[\ttfamily-1:] (The default) The author's and user's answers are not filtered
    in any way. (Spaces, case, and punctuation are preserved.)
    \item[\ttfamily0:] The author's and user's answers are converted to
    lower case, any white space and non-word characters are removed.
    \item[\ttfamily1:] The author's and user's answers are converted to
    lower case, any white space is removed.
    \item[\ttfamily2:] The author's and user's answers are stripped of
    white space.
    \item[\ttfamily 3:] Same as -1, but a case insensitive search is performed.
    \emph{This is the recommended value for this function.}
\end{enumerate}
See the JavaScript function \texttt{eqFilter} in \texttt{exerquiz.dtx} for
program code details.  Additional filtering options may be added.

\textbf{Recommendation:} For \cs{RespBoxTxtPC}, use either~-1
(case sensitive search) or~3 (case insensitive search).

\item[\ttfamily\#3:] Optional, a named destination to the
solution to the question. If this parameter appears, then a
solution must follow the question, enclosed in a \texttt{solution}
environment.  If the third parameter is a `\texttt*', then an automatic
naming scheme is used instead.
\item[\ttfamily\#4:] This required parameter is the
number of alternative answers that are acceptable. The alternative
answers are listed immediately after this parameter.
\item[]The parameters that follow \texttt{\#4} are of the form
\verb![<num>]{<word>}!. The \texttt{[<num>]} is the amount of credit
the user gets if his answer contains \texttt{<word>}. Actually,
\texttt{<word>} can be a regular expression so that a more sophisticated
search criteria can be set up. This is illustrated in the examples above,
and explained below.

A \cs{RespBoxTxtPC} question is deemed correct (and marked with a
green rectangle, in the case of a quiz) if at least one of the words
is found.

If a word does not have a partial credit \texttt{[<num>]} before it,
that word has a partial credit of zero, and may as well not be
included in the list of words.
\end{enumerate}

\section{Examples and Discussion}

In this section, we present examples with extended comments on the code.

\begin{quiz}{q2}%
\begin{questions}
\item\PTs{2} Who flew the airplane at Kitty Hawk, North Carolina, on December 17, 1903?
\RespBoxTxtPC{3}{3}[1]{Orville}[-.5]{Wilbur}[1]{Wright}\kern1bp\CorrAnsButton{Orville Wright}
\end{questions}
\end{quiz}\quad\PointsField\currQuiz\eqButton\currQuiz\hfill\AnswerField[\textSize{0}\rectW{1.5in}]\currQuiz

\noindent This is the simplest example of partial credit.
\begin{verbatim}
\RespBoxTxtPC{3}{3}[1]{Orville}[-.5]{Wilbur}[1]{Wright}
\end{verbatim}
The correct answer is ``Orville Wright.'' (One point for Orville, and one point for Wright.)
Wilbur did not fly the plane that day, so, I've assigned -.5 credit. If the user enters
``Wilbur Wright,'' only .5 points are given.

If the user enters ``xOrville xWright,'' full credit is awarded, this is because the strings
``Orville'' and ``Wright'' were found. Within the \cs{Resp\-Box\-Txt\-PC} command,
\verb!\\! is redefined; \verb!\\! takes one argument, and is used to insert escape sequences
into the string that have meaning to a regular search. We want to enter \verb!\\b!, which
stands for a word boundary.
\begin{quiz}{q3}%
\begin{questions}
\item\PTs{2} Who flew the airplane at Kitty Hawk, North Carolina, on December 17, 1903?
\RespBoxTxtPC{3}{3}[1]{\\bOrville\\b}[-.5]{\\bWilbur\\b}[1]{\\bWright\\b}\kern1bp\CorrAnsButton{Orville Wright}
\end{questions}
\end{quiz}\quad\PointsField\currQuiz\eqButton\currQuiz\hfill\AnswerField[\textSize{0}\rectW{1.5in}]\currQuiz

\noindent This is the simplest example of partial credit.
\begin{verbatim}
\RespBoxTxtPC{3}{3}
    [1]{\\bOrville\\b}
    [-.5]{\\bWilbur\\b}
    [1]{\\bWright\\b}
\end{verbatim}
Now, a response like ``xOrville xWrght'' awards no points, ``OrvilleWright'' awards no points as well.

The compare text routine (\texttt{compareTxt()}) breaks the author's answer words into an array (breaks a \texttt{<word>}
by at each space; for example, if \verb!{Orville Wright}! is one of the words, the compare breaks this into an array,
\texttt{["Orville","Wright"]}, and searches for each of these words. It is a successful search, and any credit
is awarded both words are found. For example,

\begin{quiz}{q4}%
\begin{questions}
\item\PTs{2} Who flew the airplane at Kitty Hawk, North Carolina, on December 17, 1903?
\RespBoxTxtPC{3}{2}[2]{Orville Wright}[1.5]{Wilbur Wright}\kern1bp\CorrAnsButton{Orville Wright}\kern1bp\CorrAnsButton{Orville Wright}
\end{questions}
\end{quiz}\quad\PointsField\currQuiz\eqButton\currQuiz\hfill\AnswerField[\textSize{0}\rectW{1.5in}]\currQuiz

\noindent This is the simplest example of partial credit.
\begin{verbatim}
\RespBoxTxtPC{3}{2}
    [2]{Orville Wright}
    [1.5]{Wilbur Wright}
\end{verbatim}
Here, you should get 2 points for ``Orville Wright'' and 1.5 points for ``Wilbur Wright.'' These words
can appear in any order, for example, ``Wright Orville'' is awarded 2 points. (This feature was part of
the \cs{Resp\-Box\-Txt} scheme of comparison.)

\medskip\noindent\textbf{\color{red}Important:} I don't really recommend having spaces in the \texttt{<word>} for \cs{RespBoxTxtPC}, except in this
simple case. Placing spaces in the \texttt{<word>} causes problems when more sophisticated searching
(such as \emph{alternation}) is used.

Alternation is useful for offering several alternative versions of
the same word, including alternate spellings. Let's look at the
George Washington question.

\begin{quiz}{q5}%
\begin{questions}
\item\PTs{2} Who was the first President of the United States?\\[3bp]
\RespBoxTxtPC[\rectW{3in}]{3}{3}%
    [0.5]{(\word{President}|\word{Pres.{0,1}}|\word{General}|\word{Gen.{0,1}})}
    [0.5]{(\word{George}|\word{Geo.{0,1}})}
    [1.0]{\word{Washington}}\kern1bp\CorrAnsButton{President George Washington}
\end{questions}
\end{quiz}\quad\PointsField\currQuiz\eqButton\currQuiz\hfill\AnswerField[\textSize{0}\rectW{1.5in}]\currQuiz

\begin{small}
\begin{verbatim}
\RespBoxTxtPC[\rectW{3in}]{3}*{3}
    [0.5]{(\word{President}|\word{Pres.{0,1}}|      % (1)
        \word{General}|\word{Gen.{0,1}})}           % (1)
    [0.5]{(\word{George}|\word{Geo.{0,1}})}         % (2)
    [1.0]{\word{Washington}}                        % (3)
\end{verbatim}
\end{small}%
\textbf{Note:} I've wrapped the first word around to fit it on the page, this
wrapping should not be done in the source file.

I've placed each \texttt{<word>} in parentheses, this is called
\emph{grouping}. Within each group, I've placed several \texttt{|}
characters, this is the symbol for \emph{alternation}.

As we've seen in the previous examples on the Wright brothers, in
most cases, it is important that some key words \emph{not appear}
as a substring of another word; consequently, we mark such as word
with \verb!\\b!. As a convenience, \textsf{exerquiz} defines
the \cs{word}; the code \verb!\word{AcroTeX}! expands to
\verb!\\bAcroTeX\\b!.

\medskip\noindent Comments on verbatim code:
\begin{itemize}
  \item In line~(1), we offer 0.5 points if the user enters ``President'', ``Pres.'', ``General'',
  or ``Gen.''.  We use \verb!{0,1}! following the period (.), this means, match 0 or 1 periods (.);
  consequently, ``Pres'' and ``Pres.'' are both matches. (This is not really needed here, credit
  would be given for ``Pres'' and ``Pres.'' if the matching word was just \texttt{Pres}.)
  \item In line~(2), we accept either ``George'' or ``Geo.'' (with or without the period).
  \item In line~(3), we accept the word ``Washington'' and award 1 point.
\end{itemize}

\begin{quiz}{q6}%
Now, we analyze the Napoleon question.
\begin{questions}
\item\PTs{8} Who was the first President of the United States?\\[3bp]
\RespBoxTxtPC[\Ff{\FfMultiline}\rectW{.9\linewidth}\rectH{4\baselineskip}]{3}*{7}%
    [1]{(Napoleon|Bonaparte)}
    [.5]{Battle}
    [.5]{defeated}
    [2]{Waterloo}
    [1]{Belgium}
    [1]{1815}
    [2]{((Duke\\s+of\\s+){0,1}Wellington|Arthur\\s+Wellesley)}\CorrAnsButton{Shift-click for a complete answer}
\end{questions}
\end{quiz}\quad\PointsField\currQuiz\eqButton\currQuiz\hfill\AnswerField[\textSize{0}\rectW{1.5in}]\currQuiz

\noindent This is the simplest example of partial credit.
\begin{verbatim}
\RespBoxTxtPC[\Ff{\FfMultiline} % <-- multiline text field
   \rectW{.9\linewidth}\rectH{4\baselineskip}]{3}*{7}
   [1]{(Napoleon|Bonaparte)}
   [.5]{Battle}
   [.5]{defeated}
   [2]{Waterloo}
   [1]{Belgium}
   [1]{1815}
   [2]{((Duke\\s+of\\s+){0,1}Wellington|Arthur\\s+Wellesley)}
\end{verbatim}
We award 1 point for either ``Napoleon'' or ``Bonaparte,'' and various points for various key words that
are expected to be in a complete sentence. More credit for the requested information, less credit for
other words in the sentence.

When using alternation, do not use spaces in your words. In the earlier examples, this was not a problem, here,
we demonstrate how to deal with spaces. In the last word,
\begin{verbatim}
    [2]{((Duke\\s+of\\s+){0,1}Wellington|Arthur\\s+Wellesley)}
\end{verbatim}
if a space is expected use \verb!\\s+!, this represents one or more spaces (in a
regular expression). Here, we accept ``Duke of'' followed by ``Wellington''. I've
insert grouping \verb!(Duke\\s+of\\s+)! followed by the repetition
character \verb!{0,1}!; altogether
\begin{verbatim}
    (Duke\\s+of\\s+){0,1}
\end{verbatim}
matches zero or one occurrences of the phrase ``Duke of''. with one or more spaces between ``Duke'' and ``of''
and one or more spaces following ``of''. Note, you may want to require ``Duke of''
to appear before ``Wellington'', in which case, our word would be
\begin{verbatim}
    Duke\\s+of\\s+Wellington
\end{verbatim}
We also accept the Duke's real name ``Arthur Wellesley''.

\end{document}
