## Section4.12Interactive Exercises

PreTeXt has markup for a variety of interactive problem types, described individually in the subsections to follow. Generally, for a regular HTML build (Chapter 28), these will be interactive, informing the reader when their answer is correct, and providing feedback when their answer is not correct. When HTML is built to host on a Runestone server (Chapter 31), then student progress as part of a course will be recorded on the server. Some features, which will be noted below, such as execution of computer code, is more capable on a Runestone server.

Generally, an interactive exercise is authored much like a “regular” <exercise> (Section 3.9) with <statement>, <hint>, <answer>, <solution>. However, there is also some additional markup which serves as a signal that the exercise is more than a short-answer, or free-response, question. Usually, but not always, this signal is an additional element following <statement>. One consequence of this is that all but one type of interactive exercise will require a <statement> element to contain the question text.

Each type of interactive question has a static version for use in output formats like print, PDF, or braille. Details are given below. Note that since the ability for instant evaluation of a reader's answer means an author provides the solution and other feedback, this can then be incorporated into a static version as an automatically-generated <answer> and/or <solution> (in addition to any others an author provides). Note that an author can provide a <hint> for use in all output formats, but there are not any automatically-generated <hint> for static versions of interactive problems. Visibility of these solutions can be controlled via the mechanism applicable to all exercises, see Section 26.4.

Note the opportunity to provide feeback to the reader using a <feedback> element in various locations. These are generally optional, but highly encouraged as a way to improve the quality of your reader's experience.

### Subsection4.12.1True/False Exercises

A True/False exercise must have a <statement> element, and this element must have a @correct attribute, whose value is yes or no (there is no default value). That's it. The presence of the @correct attribute is the signal that this is a True/False exercise.

The text of the statement is the assertion the reader must determine is true or not. The @correct attribute is how an author describes if the statment is true (yes) or false (no). This is enough information for a conversion to formulate a version of the question. An optional <feedback> element may follow the <statement>, and should provide more thatn a binary explanation of the exercise.

Presentation as an interactive element will vary cosmetically, according to the output type targeted.

A static version gets an automatic <answer> that is simply “True” or “False”. The automatic <solution> is the same, plus the content of <feedback>.

### Subsection4.12.2Multiple-Choice Exercises

A multiple-choice exercise is signaled by a <choices> element (plural) following a <statement> and preceding an optional <hint>. The <choices> element is structured by a sequence of <choice> elements, whose content is a potential answer for the reader to choose. So the <statement> is the prompt or question, and the <choice> are the possible answers.

At least one <choice> has an attribute @correct set to the value yes. The default value of @correct is no. There may be several correct answers, indicated with this attribute. The presentation as an exercise with one answer or many is automatic. However, in the event there is exactly one correct answer, but you wish the reader to consider the possibility of multiple correct answers, you may set the @multiple-correct attribute on the <choices> element to yes. The default value is no.

Each <choice> element must be further structured with a <statement> and a <feedback>, which each can contain items such as paragraphs (<p>). In this way, the highly-encouraged feedback can be associated with each correct and incorrect choice.

The order of the <choice> as authored, is the order they will be given in a static version. To present the choices in different orders in an interactive version, set the @randomize attribute on the <choices> element to yes.

An automatic <answer> for the static version is simply the list markers for the correct choices. An automatic <solution> has an indication for each choice if it is correct or incorrect, along with the choice's feedback.

### Subsection4.12.3Parsons Problems

Parsons problems are named for Dale Parsons, one of their creators, along with Patricia Haden. They could also be called mixed-up blocks. A reader is presented with a set of blocks containing text, either computer code or natural language, and their goal is to assemble the blocks into a correct order. This could be a computer problem with a stated purpose, or could be a logical argument such as proof, or it could be a procedure such as a recipe. An interactive drag-and-drip interface is a very efficient presentation for a reader.

Similar to multiple-choice exercises, a <statement> is followed by a <blocks> element containing a sequence of <block> elements. The <blocks> element is teh signal that this is a Parsons problem. The <blocks> element may have several attributes:

• @numbered set to left or right indicates the blocks should be numbered, and on which side the numbers go. The default value is no.

• @language set to natural indicates the text of the blocks is natural language, while the use of a computer language should be indicated by naming the actual language employed. A list of languages will soon be added in Section 4.15. The default is natural.

• @indentation set to hide indicates that a computer code exercise will not include indentation common to each line of a block. In other words, the problem is slightly harder, as the interactive interface will require the reader to adjust the block horizontally to provide common indentation for the block. The default is show.

A <block> that has natural content is authored as usual, with a sequence of paragraphs (<p>) or similar. If the content is a computer language, then it should be authored as a sequence of lines, using the <cline> element, which allows for precise interpretation of indentation and non-standard characters. Include all indentation necessary for each line, no matter how @indentation is set. The content of the blocks, arranged properly, should form a syntactically correct program. If the reader is to provide indentation, PreTeXt will strip away the common amount of indentation.

A block may be a distractor, meaning it is not to be used at all in the solution. Indicate this with a @correct attribute on the <block> set to no (the default being yes). Furthermore, a given block of the solution can be authored with several alternatives, only one of which is correct. Indicate this by structuring a <block> with a sequence of <choice>. Each <choice> should be authored similarly to a <block>, and the one correct choice should have the <correct> attribute set to yes (the default being no).

The blocks should be authored in the correct order and the interactive interface will control the randomization. A block that is a distractor may be placed in any location amidst the other blocks. Each block should have an <@order> attribute that is a whole number, counting from 1. This is the fixed, mixed-up, order that will be presented in any static rendition. In static versions, sequences of blocks are in lists, which are numbered if the attribute has been set, but the left/right distinction is lost—all numbers are to the left. An automatic <answer> is provided if blocks are numbered, and it is just the block numbers in the correct order. An automatic <solution> is always generated with the text of the blocks listed in the correct order. For an exercise with computer code, the PreTeXt <program> element and the exercise's @language attribute will produce a syntax-highlighted listing.

There is no provision for a <feedback> element. Further explanation may be provided in a <hint>, <answer>, or <solution>. Also, a good interactive interface can provide assistance to a reader by telling them if they have too few or too many blocks, or combining or removing blocks, and so on.

As of 2022-06-14 work is underway to relax the strict ordering assumed of the blocks. So there will be extra markup to specify a poset or directed acyclic graph on the blocks.

### Subsection4.12.4Matching Exercises

A matching exercise asks a reader to pair a premise with a response. Similar to multiple-choice exercises and Parsons problems, a <matches> element follows a <statement> and this is the signal. The <matches> element is structured as a sequence of <match> elements, each of which has a <premise> element and the matching <response> element. Since the content of each premise and response is best kept short and simple as a phrase, the elements may also be simple phrases without the additional structure of <p> elements, or similar. That's it.

An interactive interface should randomize at least one of the lists of premises and responses, consulting the authored version for the correct pairings. For a static version, an author should put an <order> element on each <match> whose value is a whole number, starting from 1. Then the <premise> will appear in the authored order, while the <response> will be re-ordered according to the attribute.

A single <feedback> element may be given, as a peer of <statement>, in addition to authored <hint>, <answer>, or <solution>. For a static version an automatic <solution> presents the problem in the order the <match> were authored.

### Subsection4.12.5Clickable Area Exercises

Clickable Area is a misnomer, assuming an interactive version of this type of problem. Perhaps “Select Text” would be better. In any event “area” is not meant to connote a geometric notion, instead this is about a sequence of characters, either in natural language or in computer code.

A <statement> is a prompt, describing which sort of areas should be selected by the reader. Such as: Locate all the nouns in the following paragraph. This is followed by an <areas> element, which is the signal for this type of exercise. The <areas> element holds either (a) PreTeXt paragraphs or similar, or (b) a sequence of <cline>, understood to be program code. In the latter case, a @language attribute on the <areas> element will enable the right syntax highlighting in some output formats.

Within the content of the <areas> element an <area> element can be used to surround a run of characters. These cannot cross XML boundaries, such as a <cline> or <p>. A @correct attribute, with values yes or no, indicates the text is to be selected (clicked on) or that it is a distractor (tempting to click on). The default is yes, so only distractors need to be indicated.

A single overall <feedback> may be placed following the <areas> element.

Now an interactive version will allow the reader to click on and off the marked areas of text, and provide information about which are correct and which are not, in addition to general feedback.

Generally, a static version of the problem will not be clickable. <wink/> So your prompt might say something generic like “select” or “locate” since a reader might work the problem on paper by circling or underlining the areas. A static version includes an automatic <answer> which is a list of the correct areas as text, followed by a list of the incorrect areas as text. An automatic <solution> repeats the text in the <areas> element, and uses (accessible) visual cues to note the correct and incorrect text.

### Subsection4.12.6Fill-in-the-Blanks Exercises

As of 2022-06-14 a major effort is underway to provide comprehensive markup for fill-in-the-blank problems. Until then, there is transitional markup intended only to supply a migration path for projects originally authored for Runestone servers (Chapter 31). So (a) our documentation is sparse, and (b) there will be no backward-compatible improvements. So in particular, new projects should wait for the new markup. Also, studying examples may be a useful way to augment what is described here.

A <statement> is enriched with empty <var/> elements which will render as the blanks in the problem.

The signal for a fill-in problem is a <setup> element containing a sequence of <var> elements. Each <var> contains a sequence of <condition> elements that describe possible values (via regular expressions) which might appear in a blank. The first condition describes the correct answer(s), and then the subsequent conditions are descriptions of probable incorrect answers. Each <condition> has a <feedback>. So the first condition to match an entry provided via a blank will be noted as correct or incorrect, and its feedback will be relayed.

The <var> of the statement and the <var> of the setup are in a 1-1 correspondence, which establishes how the setup is associated with a blank.

A static version will include an automatic <solution> which “fills in” each blank with a correct answer, and then duplicates the feedback text, in order.

### Subsection4.12.7Coding Exercises and Projects

A Coding Exercise is formed by placing a <program> element after the <statement> of an <exercise>. The main distinction is that this is a signal that the interactivity is provided by the <program>, and therefore the <exercise> will not be understood as a short answer exercise (Subsection 4.12.8). For this reason, the <program> should be requested as one of the interactive realizations (Subsection 4.15.2, Subsection 4.15.3).

The identical construction may be used with any PROJECT-LIKE (List 4.2.2) such as an <activity>. As of 2022-06-17 this only applies to the form that uses a <statement>, but will soon also apply to <task> within PROJECT-LIKE.

Realize that it is always possible to place a <program> inside of a <statement>, and if there is no <program> that is after the <statement> (or another signal for an interactive exercise) then the <exercise> will be classified as a short-answer exercise. It may be instructive to understand that in a static realization, a <program> at the end of a <statement> may be visually identical to an <exercise> where the <program> is after the <statement>, even though the former is a short-answer exercise and the latter is a coding exercise (which will render differently for different output formats and hosting platforms).

Short Answer questions might also be known as Free Response questions, or Essay questions. A PreTeXt <exercise>, or a PROJECT-LIKE that is not structured by <task>, is implicitly of this nature. But you still need to signal that you wish such a problem to be interactive, typically with a text box where the student can enter an answer. So, similar to other types of exercises, add a <response/> element immediately after the <statement>. (We expect to add attributes for this element to influence the behavior of the text box.)