Automation of preparation of blank tests

the Preparation of blank tests isn't my idea of fun. Moreover, you need to make a list of questions and answers, and forms to draw, and then make one reference form with the correct answers (to check it was easier).

However, TeX is very powerful, even able to solve the cubic equation! Did she not cope with such a simple task? Right, and how!


So, let's write a simple style file that allows text
the
\documentclass[a4paper,14pt]{extarticle}
\usepackage[koi8-r]{inputenc} % encoding of Classical
\usepackage[russian]{babel} % Rules word-break
\usepackage{./TESTS} % our tests
\begin{document}
\begin{enumerate}
\begin{q}{do you Understand what you  were  talking about?}
\item Yes \good
\item No
\end{q}
\begin{q}{How many answers can contain.}
\item only 3
\item only 4
\item as much as necessary
\item 2-4 \good
\end{q}
\begin{q}{How many environments/teams need to remember to compile test?}
\item a lot
\item 4 (\verb'\q', \verb'\good', \verb'\showtbl' and
\verb'\trueans')\good
\item 3
\end{q}
\end{enumerate}
\newpage
\showtbl
\newpage
\trueans
\end{document}

To here's a test:
test image

To it here's the form:
template for test

And here's a benchmark:
test etalon

For this we need a bit. For a start, redefine the enumerate environment so that it looked as we need. In addition, this environment should depend on our own counter, which we can use to match the numbers of answers and questions:
the
\newcounter{lst}
\renewenvironment{enumerate}%
{\begin{list}{\arabic{lst}.}{\usecounter{lst}\setlength{\itemsep}{0cm}%
\setlength{\parsep}{0cm}\setlength{\topsep}{2mm}}\item[]}{\end{list}}

The first team we have added your own counter lst. Then we override the environment enumerate: it will be counter lst, after the question number will be the point of additional spaces to insert will not (except for the two mm, dividing the questions among themselves).

Then we define the environment q, which will "wrap" answers. It should be a numbered list, the numbering of which is defined by Russian letters. We will also ask its own counter.
the
\newcounter{qwest}
\def\theqwest{\arabic{qwest}}
\newenvironment{q}[1]{\item #1
\begin{list}{\asbuk{qwest})}{\usecounter{qwest}}}{\end{list}\par}

The environment we ask with one required parameter — the text of the question.

In order to mark the correct answer, you can use the standard Chehovski output to a file, but it is possible not to fence bicycles and to use already existing interface — matejovska label. Because the label retains the value of the last modified of the counter, placing it after the text in the right answer, we automatically save the number of this response. But the number of the question will have to be maintained manually, we will put it in the label text with the prefix "q":
the
\newcount\total
\total=0
\def\good{\label{q\arabic{lst}}\global\advance\total by1}

Counter total will contain the total number of questions. Note that if we use more than one good team in question will get an error (the count total will exceed total number of questions, the text of the error will be talking about the wrong 'q').

To build forms and standard we need more counters:
the
\newcount\cone
\newcount\ctwo
\newcount\cthree

In addition, we define auxiliary commands. In order to select from our links to "q<question number>" the correct answer (and that he was a counter), override command ref:
the
\def\f@rst#1#2{#1}
\def\ref#1{\expandafter\@setref\csname r@#1\endcsname\f@rst#1}

Form and the standard answers are going to draw in the form of a table 10 questions in a row, and because we will still have to fill in the correct answers (which we formalize in the form of columns) in this table, each cell corresponding to one question, will represent the nested table column. The rooms are non-existent issues (when the number of questions is not a multiple of ten) model symbol of the X.
The masthead is the same for test and reference. So we use in both cases the same command to build this caps:
the
\def\l@a@n@{&}
\def\l@n@{\ifnum\cone < \ctwo\gdef\c@ll{\number\cone}\else\gdef\c@ll{\bf X}\fi
\global\advance\cone by1\global\advance\cthree by1
\l@@n@\hbox to 1cm{\hfil\c@ll\hfil}
\ifnum\cthree < 10\l@n@\fi}

The first definition had to do, because otherwise, the second symbol & revealed.
Team l@n@ checks, less if the current question number (cone) the total number of questions (ctwo), if so, in the header of the column is the question number, otherwise the symbol X. The current question number is incremented, as well as a count of the number of questions in the current row (cthree), if this counter is less than ten continues with a recursive call of the same command.

Table contents-Blanca simple (empty table), so it is logical to draw "in one sitting"
the
\def\bl@nk{\hbox to 2.5 cm{\hfil a)\hfil}&&&&&&&&&&\\\hline
\hbox to 2.5 cm{\hfil b)\hfil}&&&&&&&&&&\\\hline
\hbox to 2.5 cm{\hfil)\hfil}&&&&&&&&&&\\\hline
\hbox to 2.5 cm{\hfil d)\hfil}&&&&&&&&&&\\\hline\hline}

Here just draw a table with numbers of responses and empty cells.

For reference Blanca you must consider the room response, so for each question we will draw a separate table whose contents correspond to the correct answer:
the
\def\markX{\hbox to 1cm{\hfil\bf X\hfil}}
\def\@@one{\markX\\\hline\\\hline\\\hline\\}
\def\@@two{\\\hline\markX\\\hline\\\hline\\}
\def\@@three{\\\hline\\\hline\markX\\\hline\\}
\def\@@four{\\\hline\\\hline\\\hline\markX\\}
\def\the@ns#1{\hbox to 1cm{\begin{tabular}{|c}\ifcase#1\null\or\@@one\or
\@@two\or\@@three\or\@@four\fi
\end{tabular}}}

Team markX, we determined to reduce the paperwork that the command @@one...@@four output table-the column which marked the first...the fourth line is familiar X. The team@ns gives the right sign depending on the value of the argument — the numbers of the correct answer.

To fill Blanca reference use the following commands:
\def\l@@@{\ifnum\cone<\ctwo\gdef\c@ll{\the@ns{\ref{q\number\cone}}}\else\gdef\c@ll{}\fi
\global\advance\cone by1\global\advance\cthree by1
\l@@n@\c@ll\ifnum\cthree < 10\l@@@\fi}
\def\@@tru{\global\advance\cone by-10
\global\cthree=0\hbox to 2.5 cm{\begin{tabular}{|c}
\hbox to 2.5 cm{\hfil a)\hfil}\\\hline
\hbox to 2.5 cm{\hfil b)\hfil}\\\hline
\hbox to 2.5 cm{\hfil)\hfil}\\\hline
\hbox to 2.5 cm{\hfil d)\hfil}
\end{tabular}}\l@@@\\\hline\hline}

The second command populates directly the contents of the plate 10 questions correct answers; the first is recursively inserted plates-columns. It works almost the same team, forming a cap with room issues, but instead the number of the question's framing the sign, which marked the correct answer to this question.

For the recursive output of all tables (because of the issues we can have more than a decade, tablets will be, accordingly, more than one), use the command
the
\def\@@tmp{\ifnum\cone < \ctwo\global\cthree=0
\l@n@\\\hline\bl@nk\@@tmp\fi}

Filling is implemented by a team showtbl, which displays the title of the table (m@keh@ader), then the body of the table (@@tmp), and finally the base of the table (m@kefoot@r)
the
\def\m@keh@ader{\begin{center}\begin{tabular}{||c|c|c|c|c|c|c|c|c|c|c||}
\hline\hline
Var.~answer&\multicolumn{10}{|c||}{question Number}\\\hline}
\def\m@kefoot@r{\end{tabular}\end{center}}
\def\showtbl{{\tabcolsep=0pt\global\ctwo=\total\global\cone=0
\m@keh@ader\@@tmp\m@kefoot@r}}

Well, to implement the construction of the reference Blanca, we need to replace the team bl@nk @@tru (instead of empty cells, draw the cells with marks), and then perform the same thing that was done by the team showtbl:
the
\def\trueans{{\tabcolsep=0pt\global\ctwo=\total\global\cone=0
\m@keh@ader\gdef\bl@nk{\@@tru}\@@tmp\m@kefoot@r}}


All our style file ready.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

When the basin is small, or it's time to choose VPS server

Performance comparison of hierarchical models, Django and PostgreSQL

From Tomsk to Silicon Valley and Back