<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.ubc.ca/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DavorCubranic</id>
	<title>UBC Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.ubc.ca/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DavorCubranic"/>
	<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/Special:Contributions/DavorCubranic"/>
	<updated>2026-09-16T17:57:44Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=416051</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=416051"/>
		<updated>2016-06-29T23:33:22Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Fix the displayed text for the link to Rserve home page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== WeBWorKiR User Guide ==&lt;br /&gt;
&lt;br /&gt;
The audience for this guide are problem authors who want to use R&#039;s&lt;br /&gt;
facilities in their WeBWorK questions. We assume that you already know&lt;br /&gt;
how to create problems with the PG language (which itself is a subset&lt;br /&gt;
of Perl) and are familiar with the concepts of macros in PG. We also&lt;br /&gt;
assume that your WeBWorKiR environment has been set up as described in&lt;br /&gt;
the [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide|installation guide]].&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR is a system that involves two separate servers: WeBWorK and&lt;br /&gt;
R. In a normal operation, when a student accesses WeBWorK via a web&lt;br /&gt;
browser to work on homework problems, WeBWorK runs the PG code&lt;br /&gt;
defining the problem to compute:&lt;br /&gt;
&lt;br /&gt;
a) values used in the question, for example a random vector of five integers&lt;br /&gt;
&lt;br /&gt;
b) the text of the question, typically given in format resembling LaTeX and optionally displaying values computed in (a)&lt;br /&gt;
&lt;br /&gt;
c) values of the correct answer, for example, the mean of the vector calculated in (a)&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR adds to this the ability to run arbitrary computations in R&lt;br /&gt;
and make their results available to the rest of the PG code as if they&lt;br /&gt;
were constructed using the standard PG functions. (In our running&lt;br /&gt;
example, we could construct the random vector in R with `sample`,&lt;br /&gt;
and/or calculate its mean with `mean`.) The reason why one might want&lt;br /&gt;
to do this is R&#039;s rich library of high-quality statistical functions&lt;br /&gt;
as well as its graphical abilities. While in theory these could be&lt;br /&gt;
both replicated with PG, it would take a huge effort that can be&lt;br /&gt;
better spent by simply using the functionality already available in R.&lt;br /&gt;
&lt;br /&gt;
The way this works is that WeBWorK uses a Perl module that can talk to&lt;br /&gt;
a server running the [http://www.rforge.net/Rserve/ Rserve] software,&lt;br /&gt;
which allows remote clients to execute R code on the Rserve&#039;s server&lt;br /&gt;
and returns the execution&#039;s result in response. The Perl module&lt;br /&gt;
converts this response from R&#039;s native values (e.g., a generic vector,&lt;br /&gt;
aka &amp;quot;list&amp;quot;) to those understandable to Perl (e.g., an array), making&lt;br /&gt;
them available to the rest of the PG code.&lt;br /&gt;
&lt;br /&gt;
== Loading the macros ==&lt;br /&gt;
&lt;br /&gt;
To use R code in a problem, include &amp;quot;RserveClient.pl&amp;quot; in the&lt;br /&gt;
&amp;quot;loadMacros&amp;quot; call at the start of the question. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
loadMacros(&lt;br /&gt;
  &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
  &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
  &amp;quot;RserveClient.pl&amp;quot;    # &amp;lt;--- R integration&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Rserve macros ==&lt;br /&gt;
&lt;br /&gt;
The Rserve software creates an R session for each remote client. This&lt;br /&gt;
means that clients&#039; interactions with R are kept separate from each&lt;br /&gt;
other, just as if you started R twice on your local computer. A&lt;br /&gt;
session persists as long as the client is connected, so that multiple&lt;br /&gt;
calls from the client using the same session see the objects created&lt;br /&gt;
in previous calls. (This behaviour mirrors what happens in a local&lt;br /&gt;
session, where each R command you execute at the console after&lt;br /&gt;
pressing ENTER sees the results of earlier commands.) When a sessions&lt;br /&gt;
is *closed*, its contents are wiped off without a trace, just like&lt;br /&gt;
quitting the R application run locally.&lt;br /&gt;
&lt;br /&gt;
The RserveClient offers macros to start and finish a session, and&lt;br /&gt;
execute R commands in the current session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_eval(&amp;quot;some R code&amp;quot;)&amp;lt;/code&amp;gt;: this function sends the R code given&lt;br /&gt;
as its string argument to Rserve for execution. It returns *an&lt;br /&gt;
array* representation of the R code&#039;s result. (This means that the&lt;br /&gt;
value of &amp;lt;code&amp;gt;rserve_eval(&amp;quot;pi&amp;quot;)&amp;lt;/code&amp;gt; is an array with a single element&lt;br /&gt;
3.14159265358979. If you want to keep this value and use it in the&lt;br /&gt;
rest of the problem, assign it to an array variable. For example:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;@pi = rserve_eval(&amp;quot;pi&amp;quot;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; Multiple calls within the same problem share the R session and the object workspace, so you can break up your R code in as many &amp;lt;tt&amp;gt;rserve_eval&amp;lt;/tt&amp;gt; statements as you&#039;d like.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_start()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rserve_finish()&amp;lt;/code&amp;gt;: Start up and close the current connection to the Rserve server. In&lt;br /&gt;
normal use, these functions are completely optional because the first&lt;br /&gt;
call to &amp;lt;code&amp;gt;rserve_eval&amp;lt;/code&amp;gt; will call start the Rserve session if one is not&lt;br /&gt;
already open. Similarly, the current session will be automatically closed at the end of the problem.&lt;br /&gt;
Other than backward compatibility, the only reason for using these&lt;br /&gt;
functions is to start a new clean session within a single problem,&lt;br /&gt;
which shouldn&#039;t be a common occurrence.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== A note on Perl quoting rules ===&lt;br /&gt;
&lt;br /&gt;
Beware of Perl&#039;s quoting rules when writing R code. The text in double&lt;br /&gt;
quotes gets interpreted for escape sequences (e.g., &amp;lt;code&amp;gt;&amp;quot;\n&amp;quot;&amp;lt;/code&amp;gt; represents a&lt;br /&gt;
newline) and variables (e.g., &amp;lt;code&amp;gt;&amp;quot;The value of pi is $pi[0]&amp;quot;&amp;lt;/code&amp;gt; will be&lt;br /&gt;
interpolated into &amp;lt;code&amp;gt;&amp;quot;The value of pi is 3.14159265358979&amp;quot;&amp;lt;/code&amp;gt;, given the&lt;br /&gt;
code above). This is a problem if you&#039;re trying to extract an element&lt;br /&gt;
of a list by name using the &amp;lt;code&amp;gt;&amp;quot;$&amp;quot;&amp;lt;/code&amp;gt; operator in R because the text&lt;br /&gt;
following it will be interpreted as a variable. For instance, running&lt;br /&gt;
&amp;lt;code&amp;gt;rserve_eval(&amp;quot;cars$speed&amp;quot;)&amp;lt;/code&amp;gt; will not return the &amp;quot;speed&amp;quot; column of the&lt;br /&gt;
standard &amp;quot;cars&amp;quot; dataset, because &amp;quot;$speed&amp;quot; in the string will be&lt;br /&gt;
replaced by the value of the PG variable &amp;lt;code&amp;gt;$speed&amp;lt;/code&amp;gt;, which if not yet&lt;br /&gt;
defined will be empty string, so that the R code that actually gets&lt;br /&gt;
executed is simply &amp;quot;cars&amp;quot;. Instead, using single quotes, which prevent&lt;br /&gt;
variable and escape sequence interpolation and instead keep the string&lt;br /&gt;
exactly as entered: &amp;lt;code&amp;gt;rserve_eval(&#039;cars$speed&#039;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
On the other hand, some time you actually might want variable&lt;br /&gt;
interpolation to be done, for instance to construct the R code that&lt;br /&gt;
uses values of variables constructed with PG functions. For instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$pi = Real(&amp;quot;pi&amp;quot;);&lt;br /&gt;
@difference = rserve_eval(&amp;quot;pi - $pi&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will calculate the difference between the value between R and PG&#039;s&lt;br /&gt;
values of &amp;quot;pi&amp;quot; and put the result in the &amp;lt;tt&amp;gt;@difference&amp;lt;/tt&amp;gt; array. Note that&lt;br /&gt;
the same R code can be constructed using Perl&#039;s string concatenation&lt;br /&gt;
operator dot (&amp;quot;.&amp;quot;): &amp;lt;tt&amp;gt;rserve_eval(&#039;pi - &#039; . $pi)&amp;lt;/tt&amp;gt;. Personally, I&lt;br /&gt;
recommend sticking with single quotes to prevent unwanted surprises,&lt;br /&gt;
and using the dot operator if needing to include the value of a PG&lt;br /&gt;
variable.&lt;br /&gt;
&lt;br /&gt;
== Displaying R graphics ==&lt;br /&gt;
&lt;br /&gt;
R has excellent facilities for creating production-quality statistical&lt;br /&gt;
graphics, from simple scatterplots to complex spatial visualizatons&lt;br /&gt;
overlaid on geographical maps. These graphics can be produced in a&lt;br /&gt;
variety of formats (in R parlance, devices), from the user&#039;s monitor&lt;br /&gt;
to PDF or JPG files. The RserveClient allows the author to present&lt;br /&gt;
these graphics in the question by bracketing the R graphing code with&lt;br /&gt;
macros &amp;lt;tt&amp;gt;rserve_start_plot&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;rserve_finish_plot&amp;lt;/tt&amp;gt;, and then showing&lt;br /&gt;
the produced image in the question with PG&#039;s macro &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; (see the&lt;br /&gt;
WeBWorK [http://webwork.maa.org/wiki/Image documentation]).&lt;br /&gt;
&lt;br /&gt;
The following code is a complete example&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
&lt;br /&gt;
loadMacros(&lt;br /&gt;
   &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
   &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
   &amp;quot;RserveClient.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Print problem number and point value (weight) for the problem&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
&lt;br /&gt;
#  Setup&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$mean = random(-2, 2, .5);&lt;br /&gt;
&lt;br /&gt;
$img = rserve_start_plot(&#039;png&#039;);&lt;br /&gt;
rserve_eval(&#039;curve(dnorm(x, mean=&#039; . $mean . &#039;), xlim=c(-4, 4)); 0&#039;);&lt;br /&gt;
$image_path = rserve_finish_plot($img);&lt;br /&gt;
&lt;br /&gt;
#  Text&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
&lt;br /&gt;
What is the mean of the normal distribution shown in the figure below:&lt;br /&gt;
\{ ans_rule(5) \}&lt;br /&gt;
&lt;br /&gt;
$PAR&lt;br /&gt;
&lt;br /&gt;
\{ image($image_path, width=&amp;gt;300, height=&amp;gt;300) \}:&lt;br /&gt;
END_TEXT&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
#  Answers&lt;br /&gt;
ANS(Real($mean)-&amp;gt;cmp);&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The four key lines are as follow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;$img = rserve_start_plot(&#039;png&#039;)&amp;lt;/code&amp;gt;: sets up R to plot to a &#039;PNG&#039;&lt;br /&gt;
file and returns a unique plot identifier to be used later.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_eval(&#039;curve(...)&#039;)&amp;lt;/code&amp;gt;: runs plotting commands on the R server&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;$image_path = rserve_finish_plot($img)&amp;lt;/code&amp;gt;: completes the plotting&lt;br /&gt;
to the PNG file and transfers it to a location on the WebWork&lt;br /&gt;
server. Returns the path of the file, which is stored in Perl variable &amp;lt;code&amp;gt;$image_path&amp;lt;/code&amp;gt;&lt;br /&gt;
and later used as the first argument to the &amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt; macro.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;\{ image($image_path, width=&amp;gt;300, height=&amp;gt;300) \}&amp;lt;/code&amp;gt;: inserts the&lt;br /&gt;
image into the web page.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Transferring files from the R server ==&lt;br /&gt;
&lt;br /&gt;
Sometimes it may be convenient to make a file from R server available to the student via a link in Webwork. (For instance, using R to generate a (potentially randomized) data file that the student can download to work on the problem offline.) The macro &amp;lt;code&amp;gt;rserve_get_file REMOTE_NAME [, LOCAL_NAME]&amp;lt;/code&amp;gt; can be used to transfer the file &#039;&#039;REMOTE_NAME&#039;&#039; from the R server to WebWork&#039;s temporary&lt;br /&gt;
file area, and returns the name of the local file that can then be&lt;br /&gt;
used by the &amp;lt;code&amp;gt;htmlLink&amp;lt;/code&amp;gt; macro. Specifying &#039;&#039;LOCAL_NAME&#039;&#039; is optional; if it is not specified, the&lt;br /&gt;
filename portion of the &#039;&#039;REMOTE_NAME&#039;&#039; is used.&lt;br /&gt;
&lt;br /&gt;
The following code is a complete example&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
&lt;br /&gt;
loadMacros(&lt;br /&gt;
   &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
   &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
   &amp;quot;RserveClient.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Print problem number and point value (weight) for the problem&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
&lt;br /&gt;
#  Setup&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
my ($intercept, $slope) = rserve_eval(&#039;coef(lm(log(dist)~log(speed), data = cars))&#039;);&lt;br /&gt;
&lt;br /&gt;
my ($remote_file) = rserve_eval(&#039;filename &amp;lt;- tempfile(fileext=&amp;quot;.csv&amp;quot;); write.csv(cars, filename); filename&#039;);&lt;br /&gt;
my $local_file = rserve_get_file($remote_file);&lt;br /&gt;
&lt;br /&gt;
($local_url = $local_file) =~ s|$tempDirectory|$tempURL|;&lt;br /&gt;
&lt;br /&gt;
#  Text&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
&lt;br /&gt;
What is the slope of the linear regression of log-transformed stopping distance vs. car speed in the dataset linked below:&lt;br /&gt;
\{ ans_rule(5) \}&lt;br /&gt;
&lt;br /&gt;
$PAR&lt;br /&gt;
&lt;br /&gt;
\{ htmlLink($local_url, &amp;quot;Download&amp;quot;) \} the problem data (CSV file).&lt;br /&gt;
&lt;br /&gt;
END_TEXT&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
#  Answers&lt;br /&gt;
ANS(Real($slope)-&amp;gt;cmp);&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The four key lines are as follow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;my ($remote_file) = rserve_eval(&#039;filename &amp;lt;- tempfile(fileext=&amp;quot;.csv&amp;quot;); write.csv(cars, filename); filename&#039;)&amp;lt;/code&amp;gt;: stores the desired dataset into a temporary CSV file on the R server and returns its path, which is stored in Perl variable &amp;lt;code&amp;gt;$remote_file&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;my $local_file = rserve_get_file($remote_file)&amp;lt;/code&amp;gt;: transfers the file from the R server to WeBWorK&#039;s temporary file area and returns its path, which is stored in Perl variable &amp;lt;code&amp;gt;$local_file&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;($local_url = $local_file) =~ s|$tempDirectory|$tempURL|&amp;lt;/code&amp;gt;: converts the local file path into a URL that can be used as an argument to the &amp;lt;code&amp;gt;htmlLink&amp;lt;/code&amp;gt; macro, saving it in Perl variable &amp;lt;code&amp;gt;$local_url&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;\{ htmlLink($local_url, &amp;quot;Download&amp;quot;) \}&amp;lt;/code&amp;gt;: inserts the&lt;br /&gt;
link to the downloaded file into the web page.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=388999</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/PG Structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=388999"/>
		<updated>2016-01-07T19:58:48Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add the WeBWorK category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WebWork problems are stored in PG files. These files are typically organized in the following way:&lt;br /&gt;
&lt;br /&gt;
== Tagging and Description ==&lt;br /&gt;
The tagging and description section describes the problem for future users and authors. The purpose of the tagging information is to make the problem easier to find by searching or browsing. Each tag must appear on its own line, starting at the first character, and be in the following format: &amp;lt;code&amp;gt;## Tagname(tag value)&amp;lt;/code&amp;gt;. There are three required tags, &amp;lt;tt&amp;gt;DBsubject&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;DBchapter&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;DBsection&amp;lt;/tt&amp;gt;, placing the problem in the [http://hobbes.la.asu.edu/Holt/chaps-and-secs.html hierarchy] that&#039;s exposed in the Library Browser. Problems should also a &amp;lt;tt&amp;gt;Level&amp;lt;/tt&amp;gt;, denoting its difficulty on a predefined [http://webwork.maa.org/wiki/Problem_Levels scale].&lt;br /&gt;
&lt;br /&gt;
Optional tags include &amp;lt;tt&amp;gt;Keywords&amp;lt;/tt&amp;gt;, for easier searching, as well as tags to indicate authorship (&amp;lt;tt&amp;gt;Author&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Institution&amp;lt;/tt&amp;gt;), and to link to a specific textbook (&amp;lt;tt&amp;gt;TitleText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EditionText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;AuthorText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Section1&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Problem1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
More information on tagging can be found on the [http://webwork.maa.org/wiki/Tagging_Problems WebWork MAA wiki].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## DBsubject(&#039;Arithmetic&#039;)&lt;br /&gt;
## DBchapter(&#039;Integers&#039;)&lt;br /&gt;
## DBsection(&#039;Addition/subtraction&#039;)&lt;br /&gt;
## Level(2)&lt;br /&gt;
## KEYWORDS(&#039;arithmetic&#039;, &#039;adding&#039;)&lt;br /&gt;
## Author(&#039;Davor Cubranic&#039;)&lt;br /&gt;
## Institution(&#039;University of British Columbia&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
The initialization section loads required macros for the problem. It &#039;&#039;must&#039;&#039;&#039; begin with the &amp;lt;code&amp;gt;DOCUMENT();&amp;lt;/code&amp;gt; command, followed by the &amp;lt;code&amp;gt;loadMacros&amp;lt;/code&amp;gt; command that loads additional commands used by the problem. For basic problems, the following is sufficient — template files for specific problem types will tell you if any other macros should be loaded.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
loadMacros(&lt;br /&gt;
&amp;quot;PGstandard.pl&amp;quot;,&lt;br /&gt;
&amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem Set-up ==&lt;br /&gt;
In this section, define variables specific to the problem, for instance various parameters or the correct answer value. These variables are used in subsequent sections either in the text displayed to the student, or to check the answer. You should begin this section with &amp;lt;code&amp;gt;Context&amp;lt;/code&amp;gt;, to tell WebWork the type of variables that are used. In this example, we use &amp;lt;code&amp;gt;Context(&amp;quot;Numeric&amp;quot;)&amp;lt;/code&amp;gt; to indicate that the following commands work on scalar numbers.&lt;br /&gt;
&lt;br /&gt;
There are many ways to assign value to variables. The two we show here are:&lt;br /&gt;
&lt;br /&gt;
# by a random draw from a range of values (&amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt;, which in this case chooses from a sequence starting at 2, ending at 9, and incrementing by 1, thus choosing integers in the range [2, 9]) &lt;br /&gt;
# by computing a value (&amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt;) from a math expression, in this case the real number calculated by adding one to the value of &amp;lt;tt&amp;gt;$a&amp;lt;/tt&amp;gt;. These are the so-called MathObjects, and they lie at heart of WebWork&#039;s functioning. For instance, MathObjects know how to compute or simplify fairly complicated mathematical expressions, how display themselves in a sensible way in the text of the problem, and how to compare themselves to the student&#039;s answer . See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_MathObjects introduction to MathObjects] and follow its links to learn additional features as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$a = random(2, 9, 1);&lt;br /&gt;
$a_plus_1 = Real(&amp;quot;$a + 1&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_Contexts introduction to contexts] and a [http://webwork.maa.org/wiki/ContextList list] of other types of contexts, such as matrices or intervals.&lt;br /&gt;
&lt;br /&gt;
== Text ==&lt;br /&gt;
The text section gives the text that is shown to the student. It begins with a line containing &amp;lt;code&amp;gt;TEXT(beginproblem());&amp;lt;/code&amp;gt;. Everything between the &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt; lines (each of which must appear alone on a line) is shown to the student. These are usually accompanied with a &amp;lt;code&amp;gt;Context()-&amp;gt;texStrings&amp;lt;/code&amp;gt;, to tell MathObjects (such as &amp;lt;code&amp;gt;$a&amp;lt;/code&amp;gt; in the previous example) to display themselves using TeX formatting, and &amp;lt;code&amp;gt;Context()-&amp;gt;normalStrings&amp;lt;/code&amp;gt; to turn the default behaviour back on.&lt;br /&gt;
&lt;br /&gt;
The text can be formatted with a number of special characters and variables:&lt;br /&gt;
&lt;br /&gt;
* mathematical equations can be typeset with a LaTeX-like formatting macros within &amp;lt;code&amp;gt;\(&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\)&amp;lt;/code&amp;gt; delimiters (displayed inline with text) or &amp;lt;code&amp;gt;\[&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\]&amp;lt;/code&amp;gt; (displayed in their own block).&lt;br /&gt;
* line breaks are denoted with &amp;lt;code&amp;gt;$BR&amp;lt;/code&amp;gt; and new paragraphs with &amp;lt;code&amp;gt;$PAR&amp;lt;/code&amp;gt;.&lt;br /&gt;
* additional formatting is done using special variables to typeset text in bold (between &amp;lt;code&amp;gt;$BBOLD&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EBOLD&amp;lt;/code&amp;gt;) or italic (&amp;lt;code&amp;gt;$BITALIC&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EITALIC&amp;lt;/code&amp;gt;)&lt;br /&gt;
* if you need to execute any code in the text section, enclose it with &amp;lt;code&amp;gt;\{&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\}&amp;lt;/code&amp;gt; delimiters. The resulting value is converted to text and inserted at that point in the section. There are quite a few built-in functions that are used in this manner to, for instance, show images or tables. More fundamentally, this method is used to insert a field for student&#039;s answer. In the following example, we use &amp;lt;code&amp;gt;ans_rule(6)&amp;lt;/code&amp;gt; to insert a blank text entry field six characters wide:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
What number is one greater than \( $a \)?&lt;br /&gt;
$PAR&lt;br /&gt;
\( $a + 1 = \) \{ ans_rule(35) \}&lt;br /&gt;
END_TEXT&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Answer and Solution ==&lt;br /&gt;
The answer and solution section specifies how the answer(s) to the problem is(are) marked for correctness. Optionally, it can also give a solution that is shown to the student after the problem set is complete.&lt;br /&gt;
&lt;br /&gt;
The student&#039;s answer is evaluated with the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command, in which we give it an &amp;quot;answer checker&amp;quot; that compares the student&#039;s entry with the correct value (here, &amp;lt;code&amp;gt;$a_plus_1-&amp;gt;cmp()&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The optional solution is only visible to students after the homework deadline. In it, you are free to explain the correct solution using a combination of text and math formulas just as in the problem text. The only difference is that this section is enclosed in &amp;lt;code&amp;gt;BEGIN_SOLUTION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_SOLUTION&amp;lt;/code&amp;gt; pair, rather than &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Finally, your document &#039;&#039;&#039;must&#039;&#039;&#039; end with a &amp;lt;code&amp;gt;ENDDOCUMENT();&amp;lt;/code&amp;gt; as the last command in the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($a_plus_1-&amp;gt;cmp());&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_SOLUTION&lt;br /&gt;
Because \( $a + 1 = $a_plus_1 \), the correct answer is \( $a_plus_1 \).&lt;br /&gt;
&lt;br /&gt;
END_SOLUTION&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
Because PG files are really syntactically correct Perl code, you are free to use all of Perl&#039;s standard functionality. (Well, almost: functions that would expose potential security holes, such as accessing files or running processes, are disabled.) In particular, this means that you are free to include comments in your file, starting them with the standard Perl comment character &amp;lt;tt&amp;gt;#&amp;lt;/tt&amp;gt;. You will see comments in the attached complete PG file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Complete source code ==&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Pg structure.pg.txt|Template file source.]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_response&amp;diff=388998</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric response</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_response&amp;diff=388998"/>
		<updated>2016-01-07T19:58:21Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add the WeBWorK category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a single correct answer that is a scalar and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method. E.g., &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
The default setting accepts as correct student answers that differ from the correct value by 0.1 percent. If this isn&#039;t what you want, you will need to set an alternative value for the answer checker&#039;s tolerance. For example, &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolerance =&amp;gt; 0))&amp;lt;/code&amp;gt;, but in that case be careful of rounding and numerical accuracy issues.&lt;br /&gt;
&lt;br /&gt;
See the page on [[Documentation:WeBWorK/Problem Authoring Templates/Numeric tolerance|numeric tolerance]] for more templates, and the [http://webwork.maa.org/wiki/Context_flags#tolerance MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric response.pg.txt|Template file source.]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=388997</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric tolerance</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=388997"/>
		<updated>2016-01-07T19:58:16Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add the WeBWorK category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a scalar correct answer that is acceptable within some tolerance limites and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, specifying the tolerance within it. There are two types of tollerance:&lt;br /&gt;
## absolute: student&#039;s answer is accepted if the absolute difference with the correct answer is lower than the tolerance. For instance, if the correct value is 42, and absolute tolerance value is 0.5, then students answers in the interval (41.5, 42.5) will be accepted. (Note that the interval is open: 41.5 and 42.5 will not be accepted as correct.) This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;absolute&#039;, tolerance =&amp;gt; 0.5))&amp;lt;/code&amp;gt;.&lt;br /&gt;
## relative: student&#039;s answer is accepted if the absolute difference of the correct value and student&#039;s answer divided by the correct value is lower than the tolerance. For instance, if the correct value is 42, and relative tolerance value is 0.1 (10%), then students&#039; answers must be in the interval (37.8, 46.2). This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;relative&#039;, tolerance =&amp;gt; 0.1))&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
This method expects the tolerance interval to be symmetric around the correct value. If you want an asymmetric interval, you have to use a custom answer checker and do the comparison yourself. For instance, let&#039;s say you want to allow tolerance of -10% and +20% — i.e., if the correct answer is 42, then student answers in the interval (37.8, 50.4) are accepted:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($meaning_of_life-&amp;gt;cmp(checker =&amp;gt; sub {&lt;br /&gt;
    my ($correct, $student) = @_;&lt;br /&gt;
    my $cv = $correct-&amp;gt;value;&lt;br /&gt;
    my $sv = $student-&amp;gt;value;&lt;br /&gt;
    return $sv &amp;gt; ($cv * .9) &amp;amp;&amp;amp;&lt;br /&gt;
        $sv &amp;lt; ($cv * 1.2);&lt;br /&gt;
}));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the MAA wiki for details of configuring and using the [http://webwork.maa.org/wiki/Context_flags#tolerance built-in tolerance checking]; and [http://webwork.maa.org/wiki/Custom_Answer_Checkers custom answer checkers].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric tolerance.pg.txt|Template file source.]]&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric custom tolerance.pg.txt|Template file using a custom checker.]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_from_list&amp;diff=388996</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric from list</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_from_list&amp;diff=388996"/>
		<updated>2016-01-07T19:58:11Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add the WeBWorK category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a correct answer that is a scalar entered by the student into a text field, but there may be more than one correct value, any of which is acceptable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;List&amp;lt;/code&amp;gt; of &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObjects with the correct values and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = List(Real(0), Real(42));&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, giving it a custom &#039;&#039; &#039;&#039;&#039;list&#039;&#039;&#039; &#039;&#039; answer checker that will give full points if the student&#039;s answer is any of the acceptable values. The custom checker in this case receives as arguments a reference to the list of correct values, reference to the student&#039;s answer (also a list, even if containing zero or one elements), and a reference to the AnswerHash, a data structure of additional information about the answer checker and the student&#039;s answer (see the [http://webwork.maa.org/wiki/Custom_Answer_Checkers MAA wiki] for the full details). Your checker needs to iterate through the list of correct values, compare each one to the student&#039;s answer, and award the full points (i.e., the score of length equal to the number of acceptable answers) if any of them match, or zero otherwise. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($meaning_of_life-&amp;gt;cmp(list_checker =&amp;gt; sub {&lt;br /&gt;
   my ($correct, $student, $ansHash) = @_;&lt;br /&gt;
   my $score = 0;&lt;br /&gt;
   my @errors; # stores error messages&lt;br /&gt;
   if (scalar(@{$student} == 1)) {&lt;br /&gt;
      my $answer = ${$student}[0];&lt;br /&gt;
&lt;br /&gt;
      # iterate through correct values and compare them to&lt;br /&gt;
      # the student&#039;s answer&lt;br /&gt;
      foreach my $value (@{$correct}) {&lt;br /&gt;
         # this uses the currently active tolerance value &lt;br /&gt;
         # (e.g., as set for the context or the specific Real MathObject)&lt;br /&gt;
         if (($value &amp;lt;=&amp;gt; $answer) == 0) {&lt;br /&gt;
            # WebWork interprets &amp;quot;score&amp;quot; as the number of correct&lt;br /&gt;
            # values in the student&#039;s answer. In this case, getting&lt;br /&gt;
            # one value correct should be treated as getting all of&lt;br /&gt;
            # them correct:&lt;br /&gt;
            $score = scalar(@{$correct});&lt;br /&gt;
            last;&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
      # if we get to here and the score is still 0, the&lt;br /&gt;
      # student&#039;s answer didn&#039;t match any of the correct values&lt;br /&gt;
      if ($score == 0 &amp;amp;&amp;amp; ! $ansHash-&amp;gt;{isPreview}) {&lt;br /&gt;
         push @errors, &amp;quot;Not correct&amp;quot;;&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   elsif (! $ansHash-&amp;gt;{isPreview}) {&lt;br /&gt;
      push @errors, &amp;quot;You have to enter a single number&amp;quot;;&lt;br /&gt;
   }&lt;br /&gt;
   return ($score, @errors);&lt;br /&gt;
}));&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the [http://webwork.maa.org/wiki/Custom_Answer_Checkers_for_Lists MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric from list.pg.txt|Template file source.]]&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=388995</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=388995"/>
		<updated>2016-01-07T19:56:41Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add the WeBWorK category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We have created a number of template files that you can customize to use in your own WebWork problems. &lt;br /&gt;
&lt;br /&gt;
If you are new to WebWork, here is a template for the basic [[Documentation:WeBWorK/Problem_Authoring_Templates/PG_Structure|problem structure]].&lt;br /&gt;
&lt;br /&gt;
The templates are organized by the type of answer they accept:&lt;br /&gt;
&lt;br /&gt;
Short answer:&lt;br /&gt;
# Numerical, only one response accepted: [[Documentation:WeBWorK/Problem_Authoring_Templates/Numeric response|template]].&lt;br /&gt;
# Numerical, response accepted within specified tolerance: [[Documentation:WeBWorK/Problem_Authoring_Templates/Numeric tolerance|template]].&lt;br /&gt;
# Numerical, response accepted from list: [[Documentation:WeBWorK/Problem_Authoring_Templates/Numeric from list|template]].&lt;br /&gt;
# String response&lt;br /&gt;
&lt;br /&gt;
Multiple choice:&lt;br /&gt;
# One correct answer, no responses anchored.&lt;br /&gt;
# One correct answer, one response anchored.&lt;br /&gt;
# More than one correct answer (anchoring would be as above, so extra template for anchoring not required).&lt;br /&gt;
# Answer selected from pull-down menu.&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R&amp;diff=388950</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R&amp;diff=388950"/>
		<updated>2016-01-07T00:36:56Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: The subpages have been renamed with the correct spelling of &amp;quot;WeBWorK&amp;quot;, so we need to update the link to them&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Documentation:WeBWorK|WeBWorK]] is widely used in math courses&lt;br /&gt;
around the world, but its adoption in statistics has been limited. One&lt;br /&gt;
reason is that while WebWork implements a broad range of arithmetic&lt;br /&gt;
and calculus-type operations, it has little support for statistical&lt;br /&gt;
concepts such as probability distributions or statistical models.&lt;br /&gt;
&lt;br /&gt;
The WeBWorKiR (WeBWorK integrating R) project offers a solution in the&lt;br /&gt;
form of integration between WeBWorK and the&lt;br /&gt;
[http://www.r-project.org statistical computing software R]. The open&lt;br /&gt;
source software R is extremely popular in statistical research,&lt;br /&gt;
analysis, and education. It provides a huge range of operations for&lt;br /&gt;
statistical computation and graphics. The WeBWorKiR project has two&lt;br /&gt;
main goals: (i) to allow WeBWorK to communicate with R and (ii) the&lt;br /&gt;
creation of a large collection of homework questions for use in&lt;br /&gt;
undergraduate instruction in statistics. With the WeBWorKiR project,&lt;br /&gt;
instructors can use R code in their WebWorK problems to generate data,&lt;br /&gt;
perform analyses, and create figures.&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR has been developed in the Department of Statistics since&lt;br /&gt;
June 2012, with the funding from Teaching and Learning Improvement&lt;br /&gt;
Fund. It has been used in a number of second- and third-year&lt;br /&gt;
Statistics courses at UBC, reaching around 3000 students so far. The&lt;br /&gt;
aim is that problems created and tested on students through the&lt;br /&gt;
WeBWorKiR project are made available to all educators via WeBWorK&#039;s&lt;br /&gt;
Open Problem Library.&lt;br /&gt;
&lt;br /&gt;
If you are an instructor, please look at the [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide|authoring]] guide for&lt;br /&gt;
information on writing WebWork questions that make use of R. If you&lt;br /&gt;
are a WebWork system administrator, you can find setup information in&lt;br /&gt;
our [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide|installation guide]].&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;br /&gt;
&lt;br /&gt;
== Subpages ==&lt;br /&gt;
{{Special:PrefixIndex/Documentation:WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/}}&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Documentation:WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide&amp;diff=388949</id>
		<title>Documentation:WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Installation guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Documentation:WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide&amp;diff=388949"/>
		<updated>2016-01-07T00:35:21Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: DavorCubranic moved page Documentation:WeBWork/The WeBWorKiR Project: Integrating WeBWorK with R/Installation guide to Documentation:WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Installation guide: Use correct and consistent spelli...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Documentation:WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Installation guide]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide&amp;diff=388948</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Installation guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide&amp;diff=388948"/>
		<updated>2016-01-07T00:35:20Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: DavorCubranic moved page Documentation:WeBWork/The WeBWorKiR Project: Integrating WeBWorK with R/Installation guide to Documentation:WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Installation guide: Use correct and consistent spelli...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== WeBWorKiR Installation Guide ==&lt;br /&gt;
&lt;br /&gt;
The audience for this guide are system administrators who want to set&lt;br /&gt;
up R integration in WeBWorK. We assume that you already have, or know&lt;br /&gt;
how to set up, a basic WeBWorK server. If not, please see the&lt;br /&gt;
[http://webwork.maa.org/wiki/Release_notes_for_WeBWorK_2.8 release notes] on the WeBWorK wiki and the [http://webwork.maa.org/wiki/Installation_Manual_for_2.8_on_Ubuntu_12.04 guide] to installing WeBWorK on an Ubuntu server. You may also find&lt;br /&gt;
Jason Aubrey&#039;s [https://github.com/aubreyja/ww_install/ ww_install] installation script useful.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
After you have a working WeBWorK server, there are three distinct steps that need to happen:&lt;br /&gt;
&lt;br /&gt;
# set up the R server&lt;br /&gt;
# install the Perl module for the Perl-R bridge&lt;br /&gt;
# configure WeBWorK to use this module in PG&lt;br /&gt;
&lt;br /&gt;
=== Set up the R server ===&lt;br /&gt;
&lt;br /&gt;
Your R server (which can be on the same server as WeBWorK, but in a real-world scenario will more likely run on its own hardware/VM), is quite easy to set up:&lt;br /&gt;
&lt;br /&gt;
# install R following OS-specific instructions on the project [http://www.r-project.org homepage].&lt;br /&gt;
# install the [http://www.rforge.net/Rserve/ Rserve] server, which allows remote clients to execute R code on the Rserve&#039;s server and returns the execution&#039;s result in response. The easiest way is to run (as an administrative user) &amp;lt;code&amp;gt;Rscript -e &#039;install.packages(&amp;quot;Rserve&amp;quot;, repo=&amp;quot;http://cran.rstudio.com&amp;quot;)&#039;&amp;lt;/code&amp;gt;. Note that this package includes C source that needs to be compiled, so you have to have the basic developer tools present on the server.&lt;br /&gt;
# run the Rserve service as appropriate to your system. The command you need to run is &amp;quot;R CMD Rserve&amp;quot;. This will start the Rserve daemon which will listen on port 6311. The daemon only accepts connections from the localhost; if you run WebWork and Rserve on separate servers, read the final section of this page for additional configuration steps for your system.&lt;br /&gt;
&lt;br /&gt;
=== Install the Perl-R bridge ===&lt;br /&gt;
&lt;br /&gt;
Perl module [http://search.cpan.org/perldoc?Statistics::R::IO Statistics::R::IO] implements Rserve&#039;s communication protocol in Perl and provides translation from R data structures to Perl&#039;s. It is available on CPAN and can be installed in the standard manner for Perl modules, e.g., by running (as an admin user) &amp;lt;code&amp;gt;cpan Statistics::R::IO&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Configure Webwork to use the Perl-R bridge in PG ===&lt;br /&gt;
&lt;br /&gt;
Once the Perl module RserveClient is installed, you can make its functionality available in webwork problems by installing the RserveClient.pl macro and adding the module to the list of modules preloaded by WeBWorK. We use use &amp;quot;${WW_PREFIX}&amp;quot; to indicate the directory where WeBWorK is installed. (This directory will, for instance, contain subdirectories &amp;quot;webwork2&amp;quot; and &amp;quot;pg&amp;quot;; a typical choice is &amp;quot;/opt/webwork&amp;quot;, but a different one may be used on your system.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;install RserveClient.pl macro into &amp;quot;$WW_PREFIX/pg/macros&amp;quot;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget -q -O ${WW_PREFIX}/pg/macros/RserveClient.pl \&lt;br /&gt;
https://raw.githubusercontent.com/cubranic/Statistics-R-IO/release/extras/WebWork/RserveClient.pl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;perhaps a better solution, but depending on having the Perl module File::ShareDir, ensures that the RserveClient.pl macro matches the version of Statistics::R::IO that you have installed:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cp &amp;quot;`perl -MFile::ShareDir -e &#039;print File::ShareDir::dist_file(\&amp;quot;Statistics-R-IO\&amp;quot;, \&amp;quot;WebWork/RserveClient.pl\&amp;quot;)&#039;`&amp;quot; \&lt;br /&gt;
   ${WW_PREFIX}/pg/macros/RserveClient.pl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;add the RserveClient module(s) to the list of modules preloaded by&lt;br /&gt;
WeBWorK, so that it is available to the RserveClient.pl macro. You can&lt;br /&gt;
do this by modifying &amp;quot;${WW_PREFIX}/webwork2/conf/defaults.conf&amp;quot;,&lt;br /&gt;
but since it&#039;s a local configuration, you should put it in&lt;br /&gt;
localOverrides.conf:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;gt;&amp;gt; ${WW_PREFIX}/webwork2/conf/localOverrides.conf &amp;lt;&amp;lt;&#039;EOF&#039;&lt;br /&gt;
push @{$pg{modules}},&lt;br /&gt;
   [qw( Statistics::R::IO::Rserve )],&lt;br /&gt;
   [qw( Statistics::R::IO::ParserState )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Character )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Double )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Environment )],&lt;br /&gt;
   [qw( Statistics::R::REXP::GlobalEnvironment )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Integer )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Language )],&lt;br /&gt;
   [qw( Statistics::R::REXP::List )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Logical )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Null )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Raw )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Symbol )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Unknown )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Vector )],&lt;br /&gt;
   [qw( Statistics::R::REXP )],&lt;br /&gt;
   [qw( IO::File )],&lt;br /&gt;
   [qw( IO::Handle )],&lt;br /&gt;
   [qw( Moose )],&lt;br /&gt;
   [qw( Class::MOP )];&lt;br /&gt;
$pg{specialPGEnvironmentVars}{Rserve} = {host =&amp;gt; &amp;quot;localhost&amp;quot;};&lt;br /&gt;
&lt;br /&gt;
1;&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional configuration when WeBWorK and R are on separate hosts ===&lt;br /&gt;
&lt;br /&gt;
If you run WeBWorK and R on separate hosts, you can either set up a tunnel to forward port 6311 from WeBWorK to R&#039;s host, or do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;set up Rserve to listen on all network interfaces, not just localhost by adding a line &amp;quot;remote enable&amp;quot; to file &amp;quot;/etc/Rserv.conf&amp;quot;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cat &amp;lt;&#039;EOF&#039; &amp;gt;&amp;gt; /etc/Rserv.conf&lt;br /&gt;
remote enable&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;use the correct host name (instead of &amp;quot;localhost&amp;quot;) in the &amp;quot;Rserve host&amp;quot; line of &amp;quot;localOverrides.conf&amp;quot;. For example:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$pg{specialPGEnvironmentVars}{Rserve} = {host =&amp;gt; &amp;quot;www.example.com&amp;quot;};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in this case you will also want to set up the Rserve host&#039;s firewall to only allow connections from the WeBWorK host(s), or otherwise it will happily execute arbitrary code from any Rserve client anywhere on the internet!&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Documentation:WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=388947</id>
		<title>Documentation:WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Documentation:WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=388947"/>
		<updated>2016-01-07T00:34:44Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: DavorCubranic moved page Documentation:WeBWork/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide to Documentation:WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide: Use correct and consistent spelling of...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Documentation:WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=388946</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=388946"/>
		<updated>2016-01-07T00:34:44Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: DavorCubranic moved page Documentation:WeBWork/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide to Documentation:WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide: Use correct and consistent spelling of...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== WeBWorKiR User Guide ==&lt;br /&gt;
&lt;br /&gt;
The audience for this guide are problem authors who want to use R&#039;s&lt;br /&gt;
facilities in their WeBWorK questions. We assume that you already know&lt;br /&gt;
how to create problems with the PG language (which itself is a subset&lt;br /&gt;
of Perl) and are familiar with the concepts of macros in PG. We also&lt;br /&gt;
assume that your WeBWorKiR environment has been set up as described in&lt;br /&gt;
the [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide|installation guide]].&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR is a system that involves two separate servers: WeBWorK and&lt;br /&gt;
R. In a normal operation, when a student accesses WeBWorK via a web&lt;br /&gt;
browser to work on homework problems, WeBWorK runs the PG code&lt;br /&gt;
defining the problem to compute:&lt;br /&gt;
&lt;br /&gt;
a) values used in the question, for example a random vector of five integers&lt;br /&gt;
&lt;br /&gt;
b) the text of the question, typically given in format resembling LaTeX and optionally displaying values computed in (a)&lt;br /&gt;
&lt;br /&gt;
c) values of the correct answer, for example, the mean of the vector calculated in (a)&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR adds to this the ability to run arbitrary computations in R&lt;br /&gt;
and make their results available to the rest of the PG code as if they&lt;br /&gt;
were constructed using the standard PG functions. (In our running&lt;br /&gt;
example, we could construct the random vector in R with `sample`,&lt;br /&gt;
and/or calculate its mean with `mean`.) The reason why one might want&lt;br /&gt;
to do this is R&#039;s rich library of high-quality statistical functions&lt;br /&gt;
as well as its graphical abilities. While in theory these could be&lt;br /&gt;
both replicated with PG, it would take a huge effort that can be&lt;br /&gt;
better spent by simply using the functionality already available in R.&lt;br /&gt;
&lt;br /&gt;
The way this works is that WeBWorK uses a Perl module that can talk to&lt;br /&gt;
a server running the [[http://www.rforge.net/Rserve/|Rserve]] software,&lt;br /&gt;
which allows remote clients to execute R code on the Rserve&#039;s server&lt;br /&gt;
and returns the execution&#039;s result in response. The Perl module&lt;br /&gt;
converts this response from R&#039;s native values (e.g., a generic vector,&lt;br /&gt;
aka &amp;quot;list&amp;quot;) to those understandable to Perl (e.g., an array), making&lt;br /&gt;
them available to the rest of the PG code.&lt;br /&gt;
&lt;br /&gt;
== Loading the macros ==&lt;br /&gt;
&lt;br /&gt;
To use R code in a problem, include &amp;quot;RserveClient.pl&amp;quot; in the&lt;br /&gt;
&amp;quot;loadMacros&amp;quot; call at the start of the question. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
loadMacros(&lt;br /&gt;
  &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
  &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
  &amp;quot;RserveClient.pl&amp;quot;    # &amp;lt;--- R integration&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Rserve macros ==&lt;br /&gt;
&lt;br /&gt;
The Rserve software creates an R session for each remote client. This&lt;br /&gt;
means that clients&#039; interactions with R are kept separate from each&lt;br /&gt;
other, just as if you started R twice on your local computer. A&lt;br /&gt;
session persists as long as the client is connected, so that multiple&lt;br /&gt;
calls from the client using the same session see the objects created&lt;br /&gt;
in previous calls. (This behaviour mirrors what happens in a local&lt;br /&gt;
session, where each R command you execute at the console after&lt;br /&gt;
pressing ENTER sees the results of earlier commands.) When a sessions&lt;br /&gt;
is *closed*, its contents are wiped off without a trace, just like&lt;br /&gt;
quitting the R application run locally.&lt;br /&gt;
&lt;br /&gt;
The RserveClient offers macros to start and finish a session, and&lt;br /&gt;
execute R commands in the current session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_eval(&amp;quot;some R code&amp;quot;)&amp;lt;/code&amp;gt;: this function sends the R code given&lt;br /&gt;
as its string argument to Rserve for execution. It returns *an&lt;br /&gt;
array* representation of the R code&#039;s result. (This means that the&lt;br /&gt;
value of &amp;lt;code&amp;gt;rserve_eval(&amp;quot;pi&amp;quot;)&amp;lt;/code&amp;gt; is an array with a single element&lt;br /&gt;
3.14159265358979. If you want to keep this value and use it in the&lt;br /&gt;
rest of the problem, assign it to an array variable. For example:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;@pi = rserve_eval(&amp;quot;pi&amp;quot;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; Multiple calls within the same problem share the R session and the object workspace, so you can break up your R code in as many &amp;lt;tt&amp;gt;rserve_eval&amp;lt;/tt&amp;gt; statements as you&#039;d like.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_start()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rserve_finish()&amp;lt;/code&amp;gt;: Start up and close the current connection to the Rserve server. In&lt;br /&gt;
normal use, these functions are completely optional because the first&lt;br /&gt;
call to &amp;lt;code&amp;gt;rserve_eval&amp;lt;/code&amp;gt; will call start the Rserve session if one is not&lt;br /&gt;
already open. Similarly, the current session will be automatically closed at the end of the problem.&lt;br /&gt;
Other than backward compatibility, the only reason for using these&lt;br /&gt;
functions is to start a new clean session within a single problem,&lt;br /&gt;
which shouldn&#039;t be a common occurrence.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== A note on Perl quoting rules ===&lt;br /&gt;
&lt;br /&gt;
Beware of Perl&#039;s quoting rules when writing R code. The text in double&lt;br /&gt;
quotes gets interpreted for escape sequences (e.g., &amp;lt;code&amp;gt;&amp;quot;\n&amp;quot;&amp;lt;/code&amp;gt; represents a&lt;br /&gt;
newline) and variables (e.g., &amp;lt;code&amp;gt;&amp;quot;The value of pi is $pi[0]&amp;quot;&amp;lt;/code&amp;gt; will be&lt;br /&gt;
interpolated into &amp;lt;code&amp;gt;&amp;quot;The value of pi is 3.14159265358979&amp;quot;&amp;lt;/code&amp;gt;, given the&lt;br /&gt;
code above). This is a problem if you&#039;re trying to extract an element&lt;br /&gt;
of a list by name using the &amp;lt;code&amp;gt;&amp;quot;$&amp;quot;&amp;lt;/code&amp;gt; operator in R because the text&lt;br /&gt;
following it will be interpreted as a variable. For instance, running&lt;br /&gt;
&amp;lt;code&amp;gt;rserve_eval(&amp;quot;cars$speed&amp;quot;)&amp;lt;/code&amp;gt; will not return the &amp;quot;speed&amp;quot; column of the&lt;br /&gt;
standard &amp;quot;cars&amp;quot; dataset, because &amp;quot;$speed&amp;quot; in the string will be&lt;br /&gt;
replaced by the value of the PG variable &amp;lt;code&amp;gt;$speed&amp;lt;/code&amp;gt;, which if not yet&lt;br /&gt;
defined will be empty string, so that the R code that actually gets&lt;br /&gt;
executed is simply &amp;quot;cars&amp;quot;. Instead, using single quotes, which prevent&lt;br /&gt;
variable and escape sequence interpolation and instead keep the string&lt;br /&gt;
exactly as entered: &amp;lt;code&amp;gt;rserve_eval(&#039;cars$speed&#039;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
On the other hand, some time you actually might want variable&lt;br /&gt;
interpolation to be done, for instance to construct the R code that&lt;br /&gt;
uses values of variables constructed with PG functions. For instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$pi = Real(&amp;quot;pi&amp;quot;);&lt;br /&gt;
@difference = rserve_eval(&amp;quot;pi - $pi&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will calculate the difference between the value between R and PG&#039;s&lt;br /&gt;
values of &amp;quot;pi&amp;quot; and put the result in the &amp;lt;tt&amp;gt;@difference&amp;lt;/tt&amp;gt; array. Note that&lt;br /&gt;
the same R code can be constructed using Perl&#039;s string concatenation&lt;br /&gt;
operator dot (&amp;quot;.&amp;quot;): &amp;lt;tt&amp;gt;rserve_eval(&#039;pi - &#039; . $pi)&amp;lt;/tt&amp;gt;. Personally, I&lt;br /&gt;
recommend sticking with single quotes to prevent unwanted surprises,&lt;br /&gt;
and using the dot operator if needing to include the value of a PG&lt;br /&gt;
variable.&lt;br /&gt;
&lt;br /&gt;
== Displaying R graphics ==&lt;br /&gt;
&lt;br /&gt;
R has excellent facilities for creating production-quality statistical&lt;br /&gt;
graphics, from simple scatterplots to complex spatial visualizatons&lt;br /&gt;
overlaid on geographical maps. These graphics can be produced in a&lt;br /&gt;
variety of formats (in R parlance, devices), from the user&#039;s monitor&lt;br /&gt;
to PDF or JPG files. The RserveClient allows the author to present&lt;br /&gt;
these graphics in the question by bracketing the R graphing code with&lt;br /&gt;
macros &amp;lt;tt&amp;gt;rserve_start_plot&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;rserve_finish_plot&amp;lt;/tt&amp;gt;, and then showing&lt;br /&gt;
the produced image in the question with PG&#039;s macro &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; (see the&lt;br /&gt;
WeBWorK [http://webwork.maa.org/wiki/Image documentation]).&lt;br /&gt;
&lt;br /&gt;
The following code is a complete example&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
&lt;br /&gt;
loadMacros(&lt;br /&gt;
   &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
   &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
   &amp;quot;RserveClient.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Print problem number and point value (weight) for the problem&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
&lt;br /&gt;
#  Setup&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$mean = random(-2, 2, .5);&lt;br /&gt;
&lt;br /&gt;
$img = rserve_start_plot(&#039;png&#039;);&lt;br /&gt;
rserve_eval(&#039;curve(dnorm(x, mean=&#039; . $mean . &#039;), xlim=c(-4, 4)); 0&#039;);&lt;br /&gt;
$image_path = rserve_finish_plot($img);&lt;br /&gt;
&lt;br /&gt;
#  Text&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
&lt;br /&gt;
What is the mean of the normal distribution shown in the figure below:&lt;br /&gt;
\{ ans_rule(5) \}&lt;br /&gt;
&lt;br /&gt;
$PAR&lt;br /&gt;
&lt;br /&gt;
\{ image($image_path, width=&amp;gt;300, height=&amp;gt;300) \}:&lt;br /&gt;
END_TEXT&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
#  Answers&lt;br /&gt;
ANS(Real($mean)-&amp;gt;cmp);&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The four key lines are as follow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;$img = rserve_start_plot(&#039;png&#039;)&amp;lt;/code&amp;gt;: sets up R to plot to a &#039;PNG&#039;&lt;br /&gt;
file and returns a unique plot identifier to be used later.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_eval(&#039;curve(...)&#039;)&amp;lt;/code&amp;gt;: runs plotting commands on the R server&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;$image_path = rserve_finish_plot($img)&amp;lt;/code&amp;gt;: completes the plotting&lt;br /&gt;
to the PNG file and transfers it to a location on the WebWork&lt;br /&gt;
server. Returns the path of the file, which is stored in Perl variable &amp;lt;code&amp;gt;$image_path&amp;lt;/code&amp;gt;&lt;br /&gt;
and later used as the first argument to the &amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt; macro.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;\{ image($image_path, width=&amp;gt;300, height=&amp;gt;300) \}&amp;lt;/code&amp;gt;: inserts the&lt;br /&gt;
image into the web page.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Transferring files from the R server ==&lt;br /&gt;
&lt;br /&gt;
Sometimes it may be convenient to make a file from R server available to the student via a link in Webwork. (For instance, using R to generate a (potentially randomized) data file that the student can download to work on the problem offline.) The macro &amp;lt;code&amp;gt;rserve_get_file REMOTE_NAME [, LOCAL_NAME]&amp;lt;/code&amp;gt; can be used to transfer the file &#039;&#039;REMOTE_NAME&#039;&#039; from the R server to WebWork&#039;s temporary&lt;br /&gt;
file area, and returns the name of the local file that can then be&lt;br /&gt;
used by the &amp;lt;code&amp;gt;htmlLink&amp;lt;/code&amp;gt; macro. Specifying &#039;&#039;LOCAL_NAME&#039;&#039; is optional; if it is not specified, the&lt;br /&gt;
filename portion of the &#039;&#039;REMOTE_NAME&#039;&#039; is used.&lt;br /&gt;
&lt;br /&gt;
The following code is a complete example&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
&lt;br /&gt;
loadMacros(&lt;br /&gt;
   &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
   &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
   &amp;quot;RserveClient.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Print problem number and point value (weight) for the problem&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
&lt;br /&gt;
#  Setup&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
my ($intercept, $slope) = rserve_eval(&#039;coef(lm(log(dist)~log(speed), data = cars))&#039;);&lt;br /&gt;
&lt;br /&gt;
my ($remote_file) = rserve_eval(&#039;filename &amp;lt;- tempfile(fileext=&amp;quot;.csv&amp;quot;); write.csv(cars, filename); filename&#039;);&lt;br /&gt;
my $local_file = rserve_get_file($remote_file);&lt;br /&gt;
&lt;br /&gt;
($local_url = $local_file) =~ s|$tempDirectory|$tempURL|;&lt;br /&gt;
&lt;br /&gt;
#  Text&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
&lt;br /&gt;
What is the slope of the linear regression of log-transformed stopping distance vs. car speed in the dataset linked below:&lt;br /&gt;
\{ ans_rule(5) \}&lt;br /&gt;
&lt;br /&gt;
$PAR&lt;br /&gt;
&lt;br /&gt;
\{ htmlLink($local_url, &amp;quot;Download&amp;quot;) \} the problem data (CSV file).&lt;br /&gt;
&lt;br /&gt;
END_TEXT&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
#  Answers&lt;br /&gt;
ANS(Real($slope)-&amp;gt;cmp);&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The four key lines are as follow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;my ($remote_file) = rserve_eval(&#039;filename &amp;lt;- tempfile(fileext=&amp;quot;.csv&amp;quot;); write.csv(cars, filename); filename&#039;)&amp;lt;/code&amp;gt;: stores the desired dataset into a temporary CSV file on the R server and returns its path, which is stored in Perl variable &amp;lt;code&amp;gt;$remote_file&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;my $local_file = rserve_get_file($remote_file)&amp;lt;/code&amp;gt;: transfers the file from the R server to WeBWorK&#039;s temporary file area and returns its path, which is stored in Perl variable &amp;lt;code&amp;gt;$local_file&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;($local_url = $local_file) =~ s|$tempDirectory|$tempURL|&amp;lt;/code&amp;gt;: converts the local file path into a URL that can be used as an argument to the &amp;lt;code&amp;gt;htmlLink&amp;lt;/code&amp;gt; macro, saving it in Perl variable &amp;lt;code&amp;gt;$local_url&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;\{ htmlLink($local_url, &amp;quot;Download&amp;quot;) \}&amp;lt;/code&amp;gt;: inserts the&lt;br /&gt;
link to the downloaded file into the web page.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=378227</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric tolerance</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=378227"/>
		<updated>2015-09-24T16:36:09Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Clarify the meaning of the absolute difference&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a scalar correct answer that is acceptable within some tolerance limites and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, specifying the tolerance within it. There are two types of tollerance:&lt;br /&gt;
## absolute: student&#039;s answer is accepted if the absolute difference with the correct answer is lower than the tolerance. For instance, if the correct value is 42, and absolute tolerance value is 0.5, then students answers in the interval (41.5, 42.5) will be accepted. (Note that the interval is open: 41.5 and 42.5 will not be accepted as correct.) This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;absolute&#039;, tolerance =&amp;gt; 0.5))&amp;lt;/code&amp;gt;.&lt;br /&gt;
## relative: student&#039;s answer is accepted if the absolute difference of the correct value and student&#039;s answer divided by the correct value is lower than the tolerance. For instance, if the correct value is 42, and relative tolerance value is 0.1 (10%), then students&#039; answers must be in the interval (37.8, 46.2). This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;relative&#039;, tolerance =&amp;gt; 0.1))&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
This method expects the tolerance interval to be symmetric around the correct value. If you want an asymmetric interval, you have to use a custom answer checker and do the comparison yourself. For instance, let&#039;s say you want to allow tolerance of -10% and +20% — i.e., if the correct answer is 42, then student answers in the interval (37.8, 50.4) are accepted:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($meaning_of_life-&amp;gt;cmp(checker =&amp;gt; sub {&lt;br /&gt;
    my ($correct, $student) = @_;&lt;br /&gt;
    my $cv = $correct-&amp;gt;value;&lt;br /&gt;
    my $sv = $student-&amp;gt;value;&lt;br /&gt;
    return $sv &amp;gt; ($cv * .9) &amp;amp;&amp;amp;&lt;br /&gt;
        $sv &amp;lt; ($cv * 1.2);&lt;br /&gt;
}));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the MAA wiki for details of configuring and using the [http://webwork.maa.org/wiki/Context_flags#tolerance built-in tolerance checking]; and [http://webwork.maa.org/wiki/Custom_Answer_Checkers custom answer checkers].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric tolerance.pg.txt|Template file source.]]&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric custom tolerance.pg.txt|Template file using a custom checker.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=344388</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric tolerance</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=344388"/>
		<updated>2015-01-31T00:52:09Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Fix code example and add a link to the template using the custom checker&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a scalar correct answer that is acceptable within some tolerance limites and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, specifying the tolerance within it. There are two types of tollerance:&lt;br /&gt;
## absolute: the decimal distance from the correct answer that will be allowed. For instance, if the correct value is 42, and absolute tolerance value is 0.5, then students answers in the interval (41.5, 42.5) will be accepted. This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;absolute&#039;, tolerance =&amp;gt; 0.5))&amp;lt;/code&amp;gt;.&lt;br /&gt;
## relative: student&#039;s answer are accepted if the absolute difference of the correct value and student&#039;s answer divided by the correct value is lower than the tolerance. For instance, if the correct value is 42, and relative tolerance value is 0.1 (10%), then students&#039; answers must be in the interval (37.8, 46.2). This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;relative&#039;, tolerance =&amp;gt; 0.1))&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
This method expects the tolerance interval to be symmetric around the correct value. If you want an asymmetric interval, you have to use a custom answer checker and do the comparison yourself. For instance, let&#039;s say you want to allow tolerance of -10% and +20% — i.e., if the correct answer is 42, then student answers in the interval (37.8, 50.4) are accepted:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($meaning_of_life-&amp;gt;cmp(checker =&amp;gt; sub {&lt;br /&gt;
    my ($correct, $student) = @_;&lt;br /&gt;
    my $cv = $correct-&amp;gt;value;&lt;br /&gt;
    my $sv = $student-&amp;gt;value;&lt;br /&gt;
    return $sv &amp;gt; ($cv * .9) &amp;amp;&amp;amp;&lt;br /&gt;
        $sv &amp;lt; ($cv * 1.2);&lt;br /&gt;
}));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the MAA wiki for details of configuring and using the [http://webwork.maa.org/wiki/Context_flags#tolerance built-in tolerance checking]; and [http://webwork.maa.org/wiki/Custom_Answer_Checkers custom answer checkers].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric tolerance.pg.txt|Template file source.]]&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric custom tolerance.pg.txt|Template file using a custom checker.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=File:Numeric_custom_tolerance.pg.txt&amp;diff=344387</id>
		<title>File:Numeric custom tolerance.pg.txt</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=File:Numeric_custom_tolerance.pg.txt&amp;diff=344387"/>
		<updated>2015-01-31T00:51:30Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: User created page with UploadWizard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=={{int:filedesc}}==&lt;br /&gt;
{{Information&lt;br /&gt;
|description={{en|1=WebWork problem template for a numeric response accepted within an asymmetric tolerance range using a custom answer checker.}}&lt;br /&gt;
|date=2015-01-30 16:48:54&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:DavorCubranic|DavorCubranic]]&lt;br /&gt;
|permission=&lt;br /&gt;
|other_versions=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=={{int:license-header}}==&lt;br /&gt;
{{self|cc-by-sa-3.0}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Uploaded with UploadWizard]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=344377</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric tolerance</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=344377"/>
		<updated>2015-01-31T00:30:04Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add an example of a custom checker for asymmetric tolerance interval&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a scalar correct answer that is acceptable within some tolerance limites and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, specifying the tolerance within it. There are two types of tollerance:&lt;br /&gt;
## absolute: the decimal distance from the correct answer that will be allowed. For instance, if the correct value is 42, and absolute tolerance value is 0.5, then students answers in the interval (41.5, 42.5) will be accepted. This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;absolute&#039;, tolerance =&amp;gt; 0.5))&amp;lt;/code&amp;gt;.&lt;br /&gt;
## relative: student&#039;s answer are accepted if the absolute difference of the correct value and student&#039;s answer divided by the correct value is lower than the tolerance. For instance, if the correct value is 42, and relative tolerance value is 0.1 (10%), then students&#039; answers must be in the interval (37.8, 46.2). This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;relative&#039;, tolerance =&amp;gt; 0.1))&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
This method expects the tolerance interval to be symmetric around the correct value. If you want an asymmetric interval, you have to use a custom answer checker and do the comparison yourself. For instance, let&#039;s say you want to allow tolerance of -10% and +20% — i.e., if the correct answer is 42, then student answers in the interval (37.8, 50.4) are accepted:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($meaning_of_life-&amp;gt;cmp(checker =&amp;gt; sub {&lt;br /&gt;
    my ($correct, $student) = @_;&lt;br /&gt;
    my $cv = $correct-&amp;gt;value;&lt;br /&gt;
    my $sv = $student-&amp;gt;value;&lt;br /&gt;
    return $sv &amp;gt; ($cv * .9) &amp;amp;&amp;amp;&lt;br /&gt;
        $sv &amp;gt; ($cv * 1.2);&lt;br /&gt;
}));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the MAA wiki for details of configuring and using the [http://webwork.maa.org/wiki/Context_flags#tolerance built-in tolerance checking]; and [http://webwork.maa.org/wiki/Custom_Answer_Checkers custom answer checkers].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric tolerance.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_response&amp;diff=344168</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric response</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_response&amp;diff=344168"/>
		<updated>2015-01-29T01:03:00Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add a link to the template source file&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a single correct answer that is a scalar and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method. E.g., &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
The default setting accepts as correct student answers that differ from the correct value by 0.1 percent. If this isn&#039;t what you want, you will need to set an alternative value for the answer checker&#039;s tolerance. For example, &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolerance =&amp;gt; 0))&amp;lt;/code&amp;gt;, but in that case be careful of rounding and numerical accuracy issues.&lt;br /&gt;
&lt;br /&gt;
See the page on [[Documentation:WeBWorK/Problem Authoring Templates/Numeric tolerance|numeric tolerance]] for more templates, and the [http://webwork.maa.org/wiki/Context_flags#tolerance MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric response.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=File:Numeric_response.pg.txt&amp;diff=344167</id>
		<title>File:Numeric response.pg.txt</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=File:Numeric_response.pg.txt&amp;diff=344167"/>
		<updated>2015-01-29T01:02:09Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: User created page with UploadWizard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=={{int:filedesc}}==&lt;br /&gt;
{{Information&lt;br /&gt;
|description={{en|1=WebWork problem template for numeric responses.}}&lt;br /&gt;
|date=2015-01-28 17:01:32&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:DavorCubranic|DavorCubranic]]&lt;br /&gt;
|permission=&lt;br /&gt;
|other_versions=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=={{int:license-header}}==&lt;br /&gt;
{{self|cc-by-sa-3.0}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Uploaded with UploadWizard]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=File:Numeric_tolerance.pg.txt&amp;diff=344152</id>
		<title>File:Numeric tolerance.pg.txt</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=File:Numeric_tolerance.pg.txt&amp;diff=344152"/>
		<updated>2015-01-29T00:00:19Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: DavorCubranic uploaded a new version of &amp;amp;quot;File:Numeric tolerance.pg.txt&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=={{int:filedesc}}==&lt;br /&gt;
{{Information&lt;br /&gt;
|description={{en|1=WebWork problem template for a numeric response accepted within a given tolerance.}}&lt;br /&gt;
|date=2015-01-28 15:55:26&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:DavorCubranic|DavorCubranic]]&lt;br /&gt;
|permission=&lt;br /&gt;
|other_versions=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=={{int:license-header}}==&lt;br /&gt;
{{self|cc-by-sa-3.0}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Uploaded with UploadWizard]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=344151</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric tolerance</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=344151"/>
		<updated>2015-01-28T23:56:43Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add a link to the complete template source code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a scalar correct answer that is acceptable within some tolerance limites and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, specifying the tolerance within it. There are two types of tollerance:&lt;br /&gt;
## absolute: the decimal distance from the correct answer that will be allowed. For instance, if the correct value is 42, and absolute tolerance value is 0.5, then students answers in the interval (41.5, 42.5) will be accepted. This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;absolute&#039;, tolerance =&amp;gt; 0.5))&amp;lt;/code&amp;gt;.&lt;br /&gt;
## relative: student&#039;s answer are accepted if the absolute difference of the correct value and student&#039;s answer divided by the correct value is lower than the tolerance. For instance, if the correct value is 42, and relative tolerance value is 0.1 (10%), then students&#039; answers must be in the interval (37.8, 46.2). This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;relative&#039;, tolerance =&amp;gt; 0.1))&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
See [http://webwork.maa.org/wiki/Context_flags#tolerance MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric tolerance.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=File:Numeric_tolerance.pg.txt&amp;diff=344150</id>
		<title>File:Numeric tolerance.pg.txt</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=File:Numeric_tolerance.pg.txt&amp;diff=344150"/>
		<updated>2015-01-28T23:56:07Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: User created page with UploadWizard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=={{int:filedesc}}==&lt;br /&gt;
{{Information&lt;br /&gt;
|description={{en|1=WebWork problem template for a numeric response accepted within a given tolerance.}}&lt;br /&gt;
|date=2015-01-28 15:55:26&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:DavorCubranic|DavorCubranic]]&lt;br /&gt;
|permission=&lt;br /&gt;
|other_versions=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=={{int:license-header}}==&lt;br /&gt;
{{self|cc-by-sa-3.0}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Uploaded with UploadWizard]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=344145</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric tolerance</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=344145"/>
		<updated>2015-01-28T23:39:49Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Fix missing parentheses in code samples&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a scalar correct answer that is acceptable within some tolerance limites and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, specifying the tolerance within it. There are two types of tollerance:&lt;br /&gt;
## absolute: the decimal distance from the correct answer that will be allowed. For instance, if the correct value is 42, and absolute tolerance value is 0.5, then students answers in the interval (41.5, 42.5) will be accepted. This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;absolute&#039;, tolerance =&amp;gt; 0.5))&amp;lt;/code&amp;gt;.&lt;br /&gt;
## relative: student&#039;s answer are accepted if the absolute difference of the correct value and student&#039;s answer divided by the correct value is lower than the tolerance. For instance, if the correct value is 42, and relative tolerance value is 0.1 (10%), then students&#039; answers must be in the interval (37.8, 46.2). This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;relative&#039;, tolerance =&amp;gt; 0.1))&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
See [http://webwork.maa.org/wiki/Context_flags#tolerance MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Pg structure.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=File:Numeric_from_list.pg.txt&amp;diff=344113</id>
		<title>File:Numeric from list.pg.txt</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=File:Numeric_from_list.pg.txt&amp;diff=344113"/>
		<updated>2015-01-28T21:11:46Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: User created page with UploadWizard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=={{int:filedesc}}==&lt;br /&gt;
{{Information&lt;br /&gt;
|description={{en|1=WebWork problem template that for a numerical response accepted from a list.}}&lt;br /&gt;
|date=2015-01-28 13:10:52&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:DavorCubranic|DavorCubranic]]&lt;br /&gt;
|permission=&lt;br /&gt;
|other_versions=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=={{int:license-header}}==&lt;br /&gt;
{{self|cc-by-sa-3.0}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Uploaded with UploadWizard]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_from_list&amp;diff=344112</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric from list</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_from_list&amp;diff=344112"/>
		<updated>2015-01-28T21:09:49Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Fix the template code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a correct answer that is a scalar entered by the student into a text field, but there may be more than one correct value, any of which is acceptable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;List&amp;lt;/code&amp;gt; of &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObjects with the correct values and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = List(Real(0), Real(42));&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, giving it a custom &#039;&#039; &#039;&#039;&#039;list&#039;&#039;&#039; &#039;&#039; answer checker that will give full points if the student&#039;s answer is any of the acceptable values. The custom checker in this case receives as arguments a reference to the list of correct values, reference to the student&#039;s answer (also a list, even if containing zero or one elements), and a reference to the AnswerHash, a data structure of additional information about the answer checker and the student&#039;s answer (see the [http://webwork.maa.org/wiki/Custom_Answer_Checkers MAA wiki] for the full details). Your checker needs to iterate through the list of correct values, compare each one to the student&#039;s answer, and award the full points (i.e., the score of length equal to the number of acceptable answers) if any of them match, or zero otherwise. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($meaning_of_life-&amp;gt;cmp(list_checker =&amp;gt; sub {&lt;br /&gt;
   my ($correct, $student, $ansHash) = @_;&lt;br /&gt;
   my $score = 0;&lt;br /&gt;
   my @errors; # stores error messages&lt;br /&gt;
   if (scalar(@{$student} == 1)) {&lt;br /&gt;
      my $answer = ${$student}[0];&lt;br /&gt;
&lt;br /&gt;
      # iterate through correct values and compare them to&lt;br /&gt;
      # the student&#039;s answer&lt;br /&gt;
      foreach my $value (@{$correct}) {&lt;br /&gt;
         # this uses the currently active tolerance value &lt;br /&gt;
         # (e.g., as set for the context or the specific Real MathObject)&lt;br /&gt;
         if (($value &amp;lt;=&amp;gt; $answer) == 0) {&lt;br /&gt;
            # WebWork interprets &amp;quot;score&amp;quot; as the number of correct&lt;br /&gt;
            # values in the student&#039;s answer. In this case, getting&lt;br /&gt;
            # one value correct should be treated as getting all of&lt;br /&gt;
            # them correct:&lt;br /&gt;
            $score = scalar(@{$correct});&lt;br /&gt;
            last;&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
      # if we get to here and the score is still 0, the&lt;br /&gt;
      # student&#039;s answer didn&#039;t match any of the correct values&lt;br /&gt;
      if ($score == 0 &amp;amp;&amp;amp; ! $ansHash-&amp;gt;{isPreview}) {&lt;br /&gt;
         push @errors, &amp;quot;Not correct&amp;quot;;&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   elsif (! $ansHash-&amp;gt;{isPreview}) {&lt;br /&gt;
      push @errors, &amp;quot;You have to enter a single number&amp;quot;;&lt;br /&gt;
   }&lt;br /&gt;
   return ($score, @errors);&lt;br /&gt;
}));&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the [http://webwork.maa.org/wiki/Custom_Answer_Checkers_for_Lists MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Numeric from list.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_from_list&amp;diff=344099</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric from list</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_from_list&amp;diff=344099"/>
		<updated>2015-01-28T19:59:48Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add details and an example of the custom list answer checker&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a correct answer that is a scalar entered by the student into a text field, but there may be more than one correct value, any of which is acceptable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;List&amp;lt;/code&amp;gt; of &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObjects with the correct values and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = List(Real(0), Real(42));&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, giving it a custom answer checker that will give full points if the student&#039;s answer is any of the acceptable values. The custom checker in this case receives as arguments a reference to the list of correct values, reference to the student&#039;s answer (also a list, even if containing zero or one elements), and a reference to the AnswerHash, a data structure of additional information about the answer checker and the student&#039;s answer (see the [http://webwork.maa.org/wiki/Custom_Answer_Checkers MAA wiki] for the full details). Your checker needs to iterate through the list of correct values, compare each one to the student&#039;s answer, and award the full points (i.e., the score of 1) if any of them match, or zero otherwise. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($meaning_of_life-&amp;gt;cmp(list_checker =&amp;gt; sub {&lt;br /&gt;
my ($correct, $student, $ansHash) = @_;&lt;br /&gt;
my $score = 0;&lt;br /&gt;
my @errors; # stores error messages&lt;br /&gt;
if (scalar(@{$student} == 1) {&lt;br /&gt;
   my $answer = ${$student}[0];&lt;br /&gt;
   foreach my $x (@{$correct}) {&lt;br /&gt;
      # this uses the currently active tolerance value &lt;br /&gt;
      # (e.g., as set for the context or the specific Real MathObject)&lt;br /&gt;
      if (($x &amp;lt;=&amp;gt; $answer) == 0) {&lt;br /&gt;
         $score = 1;&lt;br /&gt;
         break;&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   # if we get to here and the score is still 0, the&lt;br /&gt;
   # student&#039;s answer didn&#039;t match any of the correct values&lt;br /&gt;
   if (score == 0 &amp;amp;&amp;amp; ! $ansHash-&amp;gt;{isPreview}) {&lt;br /&gt;
      push @errors, &amp;quot;Not correct&amp;quot;;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
elsif (! $ansHash-&amp;gt;{isPreview}) {&lt;br /&gt;
   push @errors, &amp;quot;You have to enter a single number&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
return ($score, @errors);&lt;br /&gt;
}));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the [http://webwork.maa.org/wiki/Custom_Answer_Checkers_for_Lists MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Pg structure.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_from_list&amp;diff=344033</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric from list</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_from_list&amp;diff=344033"/>
		<updated>2015-01-28T00:56:58Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Create the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a correct answer that is a scalar entered by the student into a text field, but there may be more than one correct value, any of which is acceptable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;List&amp;lt;code&amp;gt; of &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObjects with the correct values and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = List(Real(0), Real(42));&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, giving it a custom answer checker that will give full points if the student&#039;s answer is any of the acceptable values.&lt;br /&gt;
&lt;br /&gt;
See the [http://webwork.maa.org/wiki/Custom_Answer_Checkers_for_Lists MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Pg structure.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=344032</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=344032"/>
		<updated>2015-01-28T00:50:30Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add a link to the &amp;quot;Numeric from list&amp;quot; template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We have created a number of template files that you can customize to use in your own WebWork problems. &lt;br /&gt;
&lt;br /&gt;
If you are new to WebWork, here is a template for the basic [[Documentation:WeBWorK/Problem_Authoring_Templates/PG_Structure|problem structure]].&lt;br /&gt;
&lt;br /&gt;
The templates are organized by the type of answer they accept:&lt;br /&gt;
&lt;br /&gt;
Short answer:&lt;br /&gt;
# Numerical, only one response accepted: [[Documentation:WeBWorK/Problem_Authoring_Templates/Numeric response|template]].&lt;br /&gt;
# Numerical, response accepted within specified tolerance: [[Documentation:WeBWorK/Problem_Authoring_Templates/Numeric tolerance|template]].&lt;br /&gt;
# Numerical, response accepted from list: [[Documentation:WeBWorK/Problem_Authoring_Templates/Numeric from list|template]].&lt;br /&gt;
# String response&lt;br /&gt;
&lt;br /&gt;
Multiple choice:&lt;br /&gt;
# One correct answer, no responses anchored.&lt;br /&gt;
# One correct answer, one response anchored.&lt;br /&gt;
# More than one correct answer (anchoring would be as above, so extra template for anchoring not required).&lt;br /&gt;
# Answer selected from pull-down menu.&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_response&amp;diff=344030</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric response</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_response&amp;diff=344030"/>
		<updated>2015-01-28T00:33:20Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add an example of changing numeric tolerance&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a single correct answer that is a scalar and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method. E.g., &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
The default setting accepts as correct student answers that differ from the correct value by 0.1 percent. If this isn&#039;t what you want, you will need to set an alternative value for the answer checker&#039;s tolerance. For example, &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolerance =&amp;gt; 0))&amp;lt;/code&amp;gt;, but in that case be careful of rounding and numerical accuracy issues.&lt;br /&gt;
&lt;br /&gt;
See the page on [[Documentation:WeBWorK/Problem Authoring Templates/Numeric tolerance|numeric tolerance]] for more templates, and the [http://webwork.maa.org/wiki/Context_flags#tolerance MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Pg structure.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=343325</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric tolerance</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=343325"/>
		<updated>2015-01-24T00:25:52Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Provide tolerance explanation and examples&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a scalar correct answer that is acceptable within some tolerance limites and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method, specifying the tolerance within it. There are two types of tollerance:&lt;br /&gt;
## absolute: the decimal distance from the correct answer that will be allowed. For instance, if the correct value is 42, and absolute tolerance value is 0.5, then students answers in the interval (41.5, 42.5) will be accepted. This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;absolute&#039;, tolerance =&amp;gt; 0.5)&amp;lt;/code&amp;gt;.&lt;br /&gt;
## relative: student&#039;s answer are accepted if the absolute difference of the correct value and student&#039;s answer divided by the correct value is lower than the tolerance. For instance, if the correct value is 42, and relative tolerance value is 0.1 (10%), then students&#039; answers must be in the interval (37.8, 46.2). This is done as follows: &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp(tolType =&amp;gt; &#039;relative&#039;, tolerance =&amp;gt; 0.1)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
See [http://webwork.maa.org/wiki/Context_flags#tolerance MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Pg structure.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=343278</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=343278"/>
		<updated>2015-01-23T22:17:53Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add a link to the &amp;quot;Numeric with tolerance&amp;quot; template)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We have created a number of template files that you can customize to use in your own WebWork problems. &lt;br /&gt;
&lt;br /&gt;
If you are new to WebWork, here is a template for the basic [[Documentation:WeBWorK/Problem_Authoring_Templates/PG_Structure|problem structure]].&lt;br /&gt;
&lt;br /&gt;
The templates are organized by the type of answer they accept:&lt;br /&gt;
&lt;br /&gt;
Short answer:&lt;br /&gt;
# Numerical, only one response accepted: [[Documentation:WeBWorK/Problem_Authoring_Templates/Numeric response|template]].&lt;br /&gt;
# Numerical, response accepted within specified tolerance: [[Documentation:WeBWorK/Problem_Authoring_Templates/Numeric tolerance|template]].&lt;br /&gt;
# Numerical, response accepted from list.&lt;br /&gt;
# String response&lt;br /&gt;
&lt;br /&gt;
Multiple choice:&lt;br /&gt;
# One correct answer, no responses anchored.&lt;br /&gt;
# One correct answer, one response anchored.&lt;br /&gt;
# More than one correct answer (anchoring would be as above, so extra template for anchoring not required).&lt;br /&gt;
# Answer selected from pull-down menu.&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=343276</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric tolerance</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_tolerance&amp;diff=343276"/>
		<updated>2015-01-23T22:16:30Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Initial outline&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a scalar correct answer that is acceptable within some tolerance limites and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method. E.g., &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
See [http://webwork.maa.org/wiki/Context_flags#tolerance MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Pg structure.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=342914</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=342914"/>
		<updated>2015-01-22T01:02:59Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add a link to the &amp;quot;Numeric response&amp;quot; template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We have created a number of template files that you can customize to use in your own WebWork problems. &lt;br /&gt;
&lt;br /&gt;
If you are new to WebWork, here is a template for the basic [[Documentation:WeBWorK/Problem_Authoring_Templates/PG_Structure|problem structure]].&lt;br /&gt;
&lt;br /&gt;
The templates are organized by the type of answer they accept:&lt;br /&gt;
&lt;br /&gt;
Short answer:&lt;br /&gt;
# Numerical, only one response accepted: [[Documentation:WeBWorK/Problem_Authoring_Templates/Numeric response|template]].&lt;br /&gt;
# Numerical, response accepted within specified tolerance.&lt;br /&gt;
# Numerical, response accepted from list.&lt;br /&gt;
# String response&lt;br /&gt;
&lt;br /&gt;
Multiple choice:&lt;br /&gt;
# One correct answer, no responses anchored.&lt;br /&gt;
# One correct answer, one response anchored.&lt;br /&gt;
# More than one correct answer (anchoring would be as above, so extra template for anchoring not required).&lt;br /&gt;
# Answer selected from pull-down menu.&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_response&amp;diff=342912</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/Numeric response</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/Numeric_response&amp;diff=342912"/>
		<updated>2015-01-22T01:01:25Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Initial page content&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Goal ==&lt;br /&gt;
&lt;br /&gt;
Your problem has a single correct answer that is a scalar and that the student enters into a text field.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to your code:&lt;br /&gt;
&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Problem Set-up|problem set-up]] section, create a &amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt; MathObject with the correct value and assign it to a known variable. E.g, &amp;lt;code&amp;gt;$meaning_of_life = Real(42);&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In the [[Documentation:WeBWorK/Problem Authoring Templates/PG Structure#Answer and Solution|answer]] section, call the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command with the correct value&#039;s &amp;lt;code&amp;gt;cmp&amp;lt;/code&amp;gt; method. E.g., &amp;lt;code&amp;gt;ANS($meaning_of_life-&amp;gt;cmp)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
The default setting accepts as correct student answers that differ from the correct value by 0.1 percent. If this isn&#039;t what you want, you will need to set an alternative value for the answer checker&#039;s tolerance. See [http://webwork.maa.org/wiki/Context_flags#tolerance MAA wiki] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Source code ==&lt;br /&gt;
&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Pg structure.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=342616</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=342616"/>
		<updated>2015-01-21T00:52:34Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Reorganize and add a link to the basic template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We have created a number of template files that you can customize to use in your own WebWork problems. &lt;br /&gt;
&lt;br /&gt;
If you are new to WebWork, here is a template for the basic [[Documentation:WeBWorK/Problem_Authoring_Templates/PG_Structure|problem structure]].&lt;br /&gt;
&lt;br /&gt;
The templates are organized by the type of answer they accept:&lt;br /&gt;
&lt;br /&gt;
Short answer:&lt;br /&gt;
# Numerical, only one response accepted.&lt;br /&gt;
# Numerical, response accepted within specified tolerance.&lt;br /&gt;
# Numerical, response accepted from list.&lt;br /&gt;
# String response&lt;br /&gt;
&lt;br /&gt;
Multiple choice:&lt;br /&gt;
# One correct answer, no responses anchored.&lt;br /&gt;
# One correct answer, one response anchored.&lt;br /&gt;
# More than one correct answer (anchoring would be as above, so extra template for anchoring not required).&lt;br /&gt;
# Answer selected from pull-down menu.&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342615</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/PG Structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342615"/>
		<updated>2015-01-21T00:50:20Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Attach template file source&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WebWork problems are stored in PG files. These files are typically organized in the following way:&lt;br /&gt;
&lt;br /&gt;
== Tagging and Description ==&lt;br /&gt;
The tagging and description section describes the problem for future users and authors. The purpose of the tagging information is to make the problem easier to find by searching or browsing. Each tag must appear on its own line, starting at the first character, and be in the following format: &amp;lt;code&amp;gt;## Tagname(tag value)&amp;lt;/code&amp;gt;. There are three required tags, &amp;lt;tt&amp;gt;DBsubject&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;DBchapter&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;DBsection&amp;lt;/tt&amp;gt;, placing the problem in the [http://hobbes.la.asu.edu/Holt/chaps-and-secs.html hierarchy] that&#039;s exposed in the Library Browser. Problems should also a &amp;lt;tt&amp;gt;Level&amp;lt;/tt&amp;gt;, denoting its difficulty on a predefined [http://webwork.maa.org/wiki/Problem_Levels scale].&lt;br /&gt;
&lt;br /&gt;
Optional tags include &amp;lt;tt&amp;gt;Keywords&amp;lt;/tt&amp;gt;, for easier searching, as well as tags to indicate authorship (&amp;lt;tt&amp;gt;Author&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Institution&amp;lt;/tt&amp;gt;), and to link to a specific textbook (&amp;lt;tt&amp;gt;TitleText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EditionText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;AuthorText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Section1&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Problem1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
More information on tagging can be found on the [http://webwork.maa.org/wiki/Tagging_Problems WebWork MAA wiki].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## DBsubject(&#039;Arithmetic&#039;)&lt;br /&gt;
## DBchapter(&#039;Integers&#039;)&lt;br /&gt;
## DBsection(&#039;Addition/subtraction&#039;)&lt;br /&gt;
## Level(2)&lt;br /&gt;
## KEYWORDS(&#039;arithmetic&#039;, &#039;adding&#039;)&lt;br /&gt;
## Author(&#039;Davor Cubranic&#039;)&lt;br /&gt;
## Institution(&#039;University of British Columbia&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
The initialization section loads required macros for the problem. It &#039;&#039;must&#039;&#039;&#039; begin with the &amp;lt;code&amp;gt;DOCUMENT();&amp;lt;/code&amp;gt; command, followed by the &amp;lt;code&amp;gt;loadMacros&amp;lt;/code&amp;gt; command that loads additional commands used by the problem. For basic problems, the following is sufficient — template files for specific problem types will tell you if any other macros should be loaded.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
loadMacros(&lt;br /&gt;
&amp;quot;PGstandard.pl&amp;quot;,&lt;br /&gt;
&amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem Set-up ==&lt;br /&gt;
In this section, define variables specific to the problem, for instance various parameters or the correct answer value. These variables are used in subsequent sections either in the text displayed to the student, or to check the answer. You should begin this section with &amp;lt;code&amp;gt;Context&amp;lt;/code&amp;gt;, to tell WebWork the type of variables that are used. In this example, we use &amp;lt;code&amp;gt;Context(&amp;quot;Numeric&amp;quot;)&amp;lt;/code&amp;gt; to indicate that the following commands work on scalar numbers.&lt;br /&gt;
&lt;br /&gt;
There are many ways to assign value to variables. The two we show here are:&lt;br /&gt;
&lt;br /&gt;
# by a random draw from a range of values (&amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt;, which in this case chooses from a sequence starting at 2, ending at 9, and incrementing by 1, thus choosing integers in the range [2, 9]) &lt;br /&gt;
# by computing a value (&amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt;) from a math expression, in this case the real number calculated by adding one to the value of &amp;lt;tt&amp;gt;$a&amp;lt;/tt&amp;gt;. These are the so-called MathObjects, and they lie at heart of WebWork&#039;s functioning. For instance, MathObjects know how to compute or simplify fairly complicated mathematical expressions, how display themselves in a sensible way in the text of the problem, and how to compare themselves to the student&#039;s answer . See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_MathObjects introduction to MathObjects] and follow its links to learn additional features as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$a = random(2, 9, 1);&lt;br /&gt;
$a_plus_1 = Real(&amp;quot;$a + 1&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_Contexts introduction to contexts] and a [http://webwork.maa.org/wiki/ContextList list] of other types of contexts, such as matrices or intervals.&lt;br /&gt;
&lt;br /&gt;
== Text ==&lt;br /&gt;
The text section gives the text that is shown to the student. It begins with a line containing &amp;lt;code&amp;gt;TEXT(beginproblem());&amp;lt;/code&amp;gt;. Everything between the &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt; lines (each of which must appear alone on a line) is shown to the student. These are usually accompanied with a &amp;lt;code&amp;gt;Context()-&amp;gt;texStrings&amp;lt;/code&amp;gt;, to tell MathObjects (such as &amp;lt;code&amp;gt;$a&amp;lt;/code&amp;gt; in the previous example) to display themselves using TeX formatting, and &amp;lt;code&amp;gt;Context()-&amp;gt;normalStrings&amp;lt;/code&amp;gt; to turn the default behaviour back on.&lt;br /&gt;
&lt;br /&gt;
The text can be formatted with a number of special characters and variables:&lt;br /&gt;
&lt;br /&gt;
* mathematical equations can be typeset with a LaTeX-like formatting macros within &amp;lt;code&amp;gt;\(&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\)&amp;lt;/code&amp;gt; delimiters (displayed inline with text) or &amp;lt;code&amp;gt;\[&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\]&amp;lt;/code&amp;gt; (displayed in their own block).&lt;br /&gt;
* line breaks are denoted with &amp;lt;code&amp;gt;$BR&amp;lt;/code&amp;gt; and new paragraphs with &amp;lt;code&amp;gt;$PAR&amp;lt;/code&amp;gt;.&lt;br /&gt;
* additional formatting is done using special variables to typeset text in bold (between &amp;lt;code&amp;gt;$BBOLD&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EBOLD&amp;lt;/code&amp;gt;) or italic (&amp;lt;code&amp;gt;$BITALIC&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EITALIC&amp;lt;/code&amp;gt;)&lt;br /&gt;
* if you need to execute any code in the text section, enclose it with &amp;lt;code&amp;gt;\{&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\}&amp;lt;/code&amp;gt; delimiters. The resulting value is converted to text and inserted at that point in the section. There are quite a few built-in functions that are used in this manner to, for instance, show images or tables. More fundamentally, this method is used to insert a field for student&#039;s answer. In the following example, we use &amp;lt;code&amp;gt;ans_rule(6)&amp;lt;/code&amp;gt; to insert a blank text entry field six characters wide:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
What number is one greater than \( $a \)?&lt;br /&gt;
$PAR&lt;br /&gt;
\( $a + 1 = \) \{ ans_rule(35) \}&lt;br /&gt;
END_TEXT&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Answer and Solution ==&lt;br /&gt;
The answer and solution section specifies how the answer(s) to the problem is(are) marked for correctness. Optionally, it can also give a solution that is shown to the student after the problem set is complete.&lt;br /&gt;
&lt;br /&gt;
The student&#039;s answer is evaluated with the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command, in which we give it an &amp;quot;answer checker&amp;quot; that compares the student&#039;s entry with the correct value (here, &amp;lt;code&amp;gt;$a_plus_1-&amp;gt;cmp()&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The optional solution is only visible to students after the homework deadline. In it, you are free to explain the correct solution using a combination of text and math formulas just as in the problem text. The only difference is that this section is enclosed in &amp;lt;code&amp;gt;BEGIN_SOLUTION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_SOLUTION&amp;lt;/code&amp;gt; pair, rather than &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Finally, your document &#039;&#039;&#039;must&#039;&#039;&#039; end with a &amp;lt;code&amp;gt;ENDDOCUMENT();&amp;lt;/code&amp;gt; as the last command in the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($a_plus_1-&amp;gt;cmp());&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_SOLUTION&lt;br /&gt;
Because \( $a + 1 = $a_plus_1 \), the correct answer is \( $a_plus_1 \).&lt;br /&gt;
&lt;br /&gt;
END_SOLUTION&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
Because PG files are really syntactically correct Perl code, you are free to use all of Perl&#039;s standard functionality. (Well, almost: functions that would expose potential security holes, such as accessing files or running processes, are disabled.) In particular, this means that you are free to include comments in your file, starting them with the standard Perl comment character &amp;lt;tt&amp;gt;#&amp;lt;/tt&amp;gt;. You will see comments in the attached complete PG file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Complete source code ==&lt;br /&gt;
Please download the following attachment to access the code in a single file. Unfortunately, the Wiki restricts filename extensions, so that it couldn&#039;t end in &amp;quot;.pg&amp;quot;, which is what WebWork expects. You can rename it after downloading, or simply copy-and-paste its contents into the standard WebWork browser-based problem editor.&lt;br /&gt;
&lt;br /&gt;
[[Media:Pg structure.pg.txt|Template file source.]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=File:Pg_structure.pg.txt&amp;diff=342611</id>
		<title>File:Pg structure.pg.txt</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=File:Pg_structure.pg.txt&amp;diff=342611"/>
		<updated>2015-01-21T00:39:37Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: User created page with UploadWizard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=={{int:filedesc}}==&lt;br /&gt;
{{Information&lt;br /&gt;
|description={{en|1=This is a minimum useful WebWork problem file, showing the required structure and basic functionality.}}&lt;br /&gt;
|date=2015-01-20 16:37:54&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:DavorCubranic|DavorCubranic]]&lt;br /&gt;
|permission=&lt;br /&gt;
|other_versions=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=={{int:license-header}}==&lt;br /&gt;
{{self|cc-by-sa-3.0}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Uploaded with UploadWizard]]&lt;br /&gt;
[[Category:WebWork]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342608</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/PG Structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342608"/>
		<updated>2015-01-21T00:36:44Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Remove &amp;#039;$SOLUTION&amp;#039; and add a note on comments&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WebWork problems are stored in PG files. These files are typically organized in the following way:&lt;br /&gt;
&lt;br /&gt;
== Tagging and Description ==&lt;br /&gt;
The tagging and description section describes the problem for future users and authors. The purpose of the tagging information is to make the problem easier to find by searching or browsing. Each tag must appear on its own line, starting at the first character, and be in the following format: &amp;lt;code&amp;gt;## Tagname(tag value)&amp;lt;/code&amp;gt;. There are three required tags, &amp;lt;tt&amp;gt;DBsubject&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;DBchapter&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;DBsection&amp;lt;/tt&amp;gt;, placing the problem in the [http://hobbes.la.asu.edu/Holt/chaps-and-secs.html hierarchy] that&#039;s exposed in the Library Browser. Problems should also a &amp;lt;tt&amp;gt;Level&amp;lt;/tt&amp;gt;, denoting its difficulty on a predefined [http://webwork.maa.org/wiki/Problem_Levels scale].&lt;br /&gt;
&lt;br /&gt;
Optional tags include &amp;lt;tt&amp;gt;Keywords&amp;lt;/tt&amp;gt;, for easier searching, as well as tags to indicate authorship (&amp;lt;tt&amp;gt;Author&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Institution&amp;lt;/tt&amp;gt;), and to link to a specific textbook (&amp;lt;tt&amp;gt;TitleText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EditionText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;AuthorText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Section1&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Problem1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
More information on tagging can be found on the [http://webwork.maa.org/wiki/Tagging_Problems WebWork MAA wiki].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## DBsubject(&#039;Arithmetic&#039;)&lt;br /&gt;
## DBchapter(&#039;Integers&#039;)&lt;br /&gt;
## DBsection(&#039;Addition/subtraction&#039;)&lt;br /&gt;
## Level(2)&lt;br /&gt;
## KEYWORDS(&#039;arithmetic&#039;, &#039;adding&#039;)&lt;br /&gt;
## Author(&#039;Davor Cubranic&#039;)&lt;br /&gt;
## Institution(&#039;University of British Columbia&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
The initialization section loads required macros for the problem. It &#039;&#039;must&#039;&#039;&#039; begin with the &amp;lt;code&amp;gt;DOCUMENT();&amp;lt;/code&amp;gt; command, followed by the &amp;lt;code&amp;gt;loadMacros&amp;lt;/code&amp;gt; command that loads additional commands used by the problem. For basic problems, the following is sufficient — template files for specific problem types will tell you if any other macros should be loaded.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
loadMacros(&lt;br /&gt;
&amp;quot;PGstandard.pl&amp;quot;,&lt;br /&gt;
&amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem Set-up ==&lt;br /&gt;
In this section, define variables specific to the problem, for instance various parameters or the correct answer value. These variables are used in subsequent sections either in the text displayed to the student, or to check the answer. You should begin this section with &amp;lt;code&amp;gt;Context&amp;lt;/code&amp;gt;, to tell WebWork the type of variables that are used. In this example, we use &amp;lt;code&amp;gt;Context(&amp;quot;Numeric&amp;quot;)&amp;lt;/code&amp;gt; to indicate that the following commands work on scalar numbers.&lt;br /&gt;
&lt;br /&gt;
There are many ways to assign value to variables. The two we show here are:&lt;br /&gt;
&lt;br /&gt;
# by a random draw from a range of values (&amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt;, which in this case chooses from a sequence starting at 2, ending at 9, and incrementing by 1, thus choosing integers in the range [2, 9]) &lt;br /&gt;
# by computing a value (&amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt;) from a math expression, in this case the real number calculated by adding one to the value of &amp;lt;tt&amp;gt;$a&amp;lt;/tt&amp;gt;. These are the so-called MathObjects, and they lie at heart of WebWork&#039;s functioning. For instance, MathObjects know how to compute or simplify fairly complicated mathematical expressions, how display themselves in a sensible way in the text of the problem, and how to compare themselves to the student&#039;s answer . See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_MathObjects introduction to MathObjects] and follow its links to learn additional features as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$a = random(2, 9, 1);&lt;br /&gt;
$a_plus_1 = Real(&amp;quot;$a + 1&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_Contexts introduction to contexts] and a [http://webwork.maa.org/wiki/ContextList list] of other types of contexts, such as matrices or intervals.&lt;br /&gt;
&lt;br /&gt;
== Text ==&lt;br /&gt;
The text section gives the text that is shown to the student. It begins with a line containing &amp;lt;code&amp;gt;TEXT(beginproblem());&amp;lt;/code&amp;gt;. Everything between the &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt; lines (each of which must appear alone on a line) is shown to the student. These are usually accompanied with a &amp;lt;code&amp;gt;Context()-&amp;gt;texStrings&amp;lt;/code&amp;gt;, to tell MathObjects (such as &amp;lt;code&amp;gt;$a&amp;lt;/code&amp;gt; in the previous example) to display themselves using TeX formatting, and &amp;lt;code&amp;gt;Context()-&amp;gt;normalStrings&amp;lt;/code&amp;gt; to turn the default behaviour back on.&lt;br /&gt;
&lt;br /&gt;
The text can be formatted with a number of special characters and variables:&lt;br /&gt;
&lt;br /&gt;
* mathematical equations can be typeset with a LaTeX-like formatting macros within &amp;lt;code&amp;gt;\(&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\)&amp;lt;/code&amp;gt; delimiters (displayed inline with text) or &amp;lt;code&amp;gt;\[&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\]&amp;lt;/code&amp;gt; (displayed in their own block).&lt;br /&gt;
* line breaks are denoted with &amp;lt;code&amp;gt;$BR&amp;lt;/code&amp;gt; and new paragraphs with &amp;lt;code&amp;gt;$PAR&amp;lt;/code&amp;gt;.&lt;br /&gt;
* additional formatting is done using special variables to typeset text in bold (between &amp;lt;code&amp;gt;$BBOLD&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EBOLD&amp;lt;/code&amp;gt;) or italic (&amp;lt;code&amp;gt;$BITALIC&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EITALIC&amp;lt;/code&amp;gt;)&lt;br /&gt;
* if you need to execute any code in the text section, enclose it with &amp;lt;code&amp;gt;\{&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\}&amp;lt;/code&amp;gt; delimiters. The resulting value is converted to text and inserted at that point in the section. There are quite a few built-in functions that are used in this manner to, for instance, show images or tables. More fundamentally, this method is used to insert a field for student&#039;s answer. In the following example, we use &amp;lt;code&amp;gt;ans_rule(6)&amp;lt;/code&amp;gt; to insert a blank text entry field six characters wide:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
What number is one greater than \( $a \)?&lt;br /&gt;
$PAR&lt;br /&gt;
\( $a + 1 = \) \{ ans_rule(35) \}&lt;br /&gt;
END_TEXT&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Answer and Solution ==&lt;br /&gt;
The answer and solution section specifies how the answer(s) to the problem is(are) marked for correctness. Optionally, it can also give a solution that is shown to the student after the problem set is complete.&lt;br /&gt;
&lt;br /&gt;
The student&#039;s answer is evaluated with the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command, in which we give it an &amp;quot;answer checker&amp;quot; that compares the student&#039;s entry with the correct value (here, &amp;lt;code&amp;gt;$a_plus_1-&amp;gt;cmp()&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The optional solution is only visible to students after the homework deadline. In it, you are free to explain the correct solution using a combination of text and math formulas just as in the problem text. The only difference is that this section is enclosed in &amp;lt;code&amp;gt;BEGIN_SOLUTION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_SOLUTION&amp;lt;/code&amp;gt; pair, rather than &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Finally, your document &#039;&#039;&#039;must&#039;&#039;&#039; end with a &amp;lt;code&amp;gt;ENDDOCUMENT();&amp;lt;/code&amp;gt; as the last command in the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($a_plus_1-&amp;gt;cmp());&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_SOLUTION&lt;br /&gt;
Because \( $a + 1 = $a_plus_1 \), the correct answer is \( $a_plus_1 \).&lt;br /&gt;
&lt;br /&gt;
END_SOLUTION&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
Because PG files are really syntactically correct Perl code, you are free to use all of Perl&#039;s standard functionality. (Well, almost: functions that would expose potential security holes, such as accessing files or running processes, are disabled.) In particular, this means that you are free to include comments in your file, starting them with the standard Perl comment character &amp;lt;tt&amp;gt;#&amp;lt;/tt&amp;gt;. You will see comments in the attached complete PG file.&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342591</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/PG Structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342591"/>
		<updated>2015-01-21T00:20:26Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Enter appropriate problem tags&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WebWork problems are stored in PG files. These files are typically structured in the following way:&lt;br /&gt;
&lt;br /&gt;
== Tagging and Description ==&lt;br /&gt;
The tagging and description section describes the problem for future users and authors. The purpose of the tagging information is to make the problem easier to find by searching or browsing. Each tag must appear on its own line, starting at the first character, and be in the following format: &amp;lt;code&amp;gt;## Tagname(tag value)&amp;lt;/code&amp;gt;. There are three required tags, &amp;lt;tt&amp;gt;DBsubject&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;DBchapter&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;DBsection&amp;lt;/tt&amp;gt;, placing the problem in the [http://hobbes.la.asu.edu/Holt/chaps-and-secs.html hierarchy] that&#039;s exposed in the Library Browser. Problems should also a &amp;lt;tt&amp;gt;Level&amp;lt;/tt&amp;gt;, denoting its difficulty on a predefined [http://webwork.maa.org/wiki/Problem_Levels scale].&lt;br /&gt;
&lt;br /&gt;
Optional tags include &amp;lt;tt&amp;gt;Keywords&amp;lt;/tt&amp;gt;, for easier searching, as well as tags to indicate authorship (&amp;lt;tt&amp;gt;Author&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Institution&amp;lt;/tt&amp;gt;), and to link to a specific textbook (&amp;lt;tt&amp;gt;TitleText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EditionText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;AuthorText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Section1&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Problem1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
More information on tagging can be found on the [http://webwork.maa.org/wiki/Tagging_Problems WebWork MAA wiki].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## DBsubject(&#039;Arithmetic&#039;)&lt;br /&gt;
## DBchapter(&#039;Integers&#039;)&lt;br /&gt;
## DBsection(&#039;Addition/subtraction&#039;)&lt;br /&gt;
## Level(2)&lt;br /&gt;
## KEYWORDS(&#039;arithmetic&#039;, &#039;adding&#039;)&lt;br /&gt;
## Author(&#039;Davor Cubranic&#039;)&lt;br /&gt;
## Institution(&#039;University of British Columbia&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
The initialization section loads required macros for the problem. It &#039;&#039;must&#039;&#039;&#039; begin with the &amp;lt;code&amp;gt;DOCUMENT();&amp;lt;/code&amp;gt; command, followed by the &amp;lt;code&amp;gt;loadMacros&amp;lt;/code&amp;gt; command that loads additional commands used by the problem. For basic problems, the following is sufficient — template files for specific problem types will tell you if any other macros should be loaded.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
loadMacros(&lt;br /&gt;
&amp;quot;PGstandard.pl&amp;quot;,&lt;br /&gt;
&amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem Set-up ==&lt;br /&gt;
In this section, define variables specific to the problem, for instance various parameters or the correct answer value. These variables are used in subsequent sections either in the text displayed to the student, or to check the answer. You should begin this section with &amp;lt;code&amp;gt;Context&amp;lt;/code&amp;gt;, to tell WebWork the type of variables that are used. In this example, we use &amp;lt;code&amp;gt;Context(&amp;quot;Numeric&amp;quot;)&amp;lt;/code&amp;gt; to indicate that the following commands work on scalar numbers.&lt;br /&gt;
&lt;br /&gt;
There are many ways to assign value to variables. The two we show here are:&lt;br /&gt;
&lt;br /&gt;
# by a random draw from a range of values (&amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt;, which in this case chooses from a sequence starting at 2, ending at 9, and incrementing by 1, thus choosing integers in the range [2, 9]) &lt;br /&gt;
# by computing a value (&amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt;) from a math expression, in this case the real number calculated by adding one to the value of &amp;lt;tt&amp;gt;$a&amp;lt;/tt&amp;gt;. These are the so-called MathObjects, and they lie at heart of WebWork&#039;s functioning. For instance, MathObjects know how to compute or simplify fairly complicated mathematical expressions, how display themselves in a sensible way in the text of the problem, and how to compare themselves to the student&#039;s answer . See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_MathObjects introduction to MathObjects] and follow its links to learn additional features as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$a = random(2, 9, 1);&lt;br /&gt;
$a_plus_1 = Real(&amp;quot;$a + 1&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_Contexts introduction to contexts] and a [http://webwork.maa.org/wiki/ContextList list] of other types of contexts, such as matrices or intervals.&lt;br /&gt;
&lt;br /&gt;
== Text ==&lt;br /&gt;
The text section gives the text that is shown to the student. It begins with a line containing &amp;lt;code&amp;gt;TEXT(beginproblem());&amp;lt;/code&amp;gt;. Everything between the &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt; lines (each of which must appear alone on a line) is shown to the student. These are usually accompanied with a &amp;lt;code&amp;gt;Context()-&amp;gt;texStrings&amp;lt;/code&amp;gt;, to tell MathObjects (such as &amp;lt;code&amp;gt;$a&amp;lt;/code&amp;gt; in the previous example) to display themselves using TeX formatting, and &amp;lt;code&amp;gt;Context()-&amp;gt;normalStrings&amp;lt;/code&amp;gt; to turn the default behaviour back on.&lt;br /&gt;
&lt;br /&gt;
The text can be formatted with a number of special characters and variables:&lt;br /&gt;
&lt;br /&gt;
* mathematical equations can be typeset with a LaTeX-like formatting macros within &amp;lt;code&amp;gt;\(&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\)&amp;lt;/code&amp;gt; delimiters (displayed inline with text) or &amp;lt;code&amp;gt;\[&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\]&amp;lt;/code&amp;gt; (displayed in their own block).&lt;br /&gt;
* line breaks are denoted with &amp;lt;code&amp;gt;$BR&amp;lt;/code&amp;gt; and new paragraphs with &amp;lt;code&amp;gt;$PAR&amp;lt;/code&amp;gt;.&lt;br /&gt;
* additional formatting is done using special variables to typeset text in bold (between &amp;lt;code&amp;gt;$BBOLD&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EBOLD&amp;lt;/code&amp;gt;) or italic (&amp;lt;code&amp;gt;$BITALIC&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EITALIC&amp;lt;/code&amp;gt;)&lt;br /&gt;
* if you need to execute any code in the text section, enclose it with &amp;lt;code&amp;gt;\{&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\}&amp;lt;/code&amp;gt; delimiters. The resulting value is converted to text and inserted at that point in the section. There are quite a few built-in functions that are used in this manner to, for instance, show images or tables. More fundamentally, this method is used to insert a field for student&#039;s answer. In the following example, we use &amp;lt;code&amp;gt;ans_rule(6)&amp;lt;/code&amp;gt; to insert a blank text entry field six characters wide:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
What number is one greater than \( $a \)?&lt;br /&gt;
$PAR&lt;br /&gt;
\( $a + 1 = \) \{ ans_rule(35) \}&lt;br /&gt;
END_TEXT&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Answer and Solution ==&lt;br /&gt;
The answer and solution section specifies how the answer(s) to the problem is(are) marked for correctness. Optionally, it can also give a solution that is shown to the student after the problem set is complete.&lt;br /&gt;
&lt;br /&gt;
The student&#039;s answer is evaluated with the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command, in which we give it an &amp;quot;answer checker&amp;quot; that compares the student&#039;s entry with the correct value (here, &amp;lt;code&amp;gt;$a_plus_1-&amp;gt;cmp()&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The optional solution is only visible to students after the homework deadline. In it, you are free to explain the correct solution using a combination of text and math formulas just as in the problem text. The only difference is that this section is enclosed in &amp;lt;code&amp;gt;BEGIN_SOLUTION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_SOLUTION&amp;lt;/code&amp;gt; pair, rather than &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt;. You may use the special &amp;lt;code&amp;gt;$SOLUTION&amp;lt;/code&amp;gt; variable to create a heading titled &amp;quot;Solution&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Finally, your document &#039;&#039;&#039;must&#039;&#039;&#039; end with a &amp;lt;code&amp;gt;ENDDOCUMENT();&amp;lt;/code&amp;gt; as the last command in the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($a_plus_1-&amp;gt;cmp());&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_SOLUTION&lt;br /&gt;
$SOLUTION&lt;br /&gt;
Because \( $a + 1 = $a_plus_1 \), the correct answer is \( $a_plus_1 \).&lt;br /&gt;
&lt;br /&gt;
END_SOLUTION&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342590</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/PG Structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342590"/>
		<updated>2015-01-21T00:13:47Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Write the &amp;quot;Text&amp;quot; section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WebWork problems are stored in PG files. These files are typically structured in the following way:&lt;br /&gt;
&lt;br /&gt;
== Tagging and Description ==&lt;br /&gt;
The tagging and description section describes the problem for future users and authors. The purpose of the tagging information is to make the problem easier to find by searching or browsing. Each tag must appear on its own line, starting at the first character, and be in the following format: &amp;lt;code&amp;gt;## Tagname(tag value)&amp;lt;/code&amp;gt;. There are three required tags, &amp;lt;tt&amp;gt;DBsubject&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;DBchapter&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;DBsection&amp;lt;/tt&amp;gt;, placing the problem in the [[http://hobbes.la.asu.edu/Holt/chaps-and-secs.html|hierarchy]] that&#039;s exposed in the Library Browser. Problems should also a &amp;lt;tt&amp;gt;Level&amp;lt;/tt&amp;gt;, denoting its difficulty on a predefined [http://webwork.maa.org/wiki/Problem_Levels scale].&lt;br /&gt;
&lt;br /&gt;
Optional tags include &amp;lt;tt&amp;gt;Keywords&amp;lt;/tt&amp;gt;, for easier searching, as well as tags to indicate authorship (&amp;lt;tt&amp;gt;Author&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Institution&amp;lt;/tt&amp;gt;), and to link to a specific textbook (&amp;lt;tt&amp;gt;TitleText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EditionText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;AuthorText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Section1&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Problem1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
More information on tagging can be found on the [http://webwork.maa.org/wiki/Tagging_Problems WebWork MAA wiki].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## DBsubject(&#039;WeBWorK&#039;)&lt;br /&gt;
## DBchapter(&#039;Demos&#039;)&lt;br /&gt;
## DBsection(&#039;Problem&#039;)&lt;br /&gt;
## KEYWORDS(&#039;&#039;)&lt;br /&gt;
## TitleText1(&#039;&#039;)&lt;br /&gt;
## EditionText1(&#039;&#039;)&lt;br /&gt;
## AuthorText1(&#039;&#039;)&lt;br /&gt;
## Section1(&#039;&#039;)&lt;br /&gt;
## Problem1(&#039;&#039;)&lt;br /&gt;
## Author(&#039;Gavin LaRose&#039;)&lt;br /&gt;
## Institution(&#039;UMich&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
The initialization section loads required macros for the problem. It &#039;&#039;must&#039;&#039;&#039; begin with the &amp;lt;code&amp;gt;DOCUMENT();&amp;lt;/code&amp;gt; command, followed by the &amp;lt;code&amp;gt;loadMacros&amp;lt;/code&amp;gt; command that loads additional commands used by the problem. For basic problems, the following is sufficient — template files for specific problem types will tell you if any other macros should be loaded.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
loadMacros(&lt;br /&gt;
&amp;quot;PGstandard.pl&amp;quot;,&lt;br /&gt;
&amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem Set-up ==&lt;br /&gt;
In this section, define variables specific to the problem, for instance various parameters or the correct answer value. These variables are used in subsequent sections either in the text displayed to the student, or to check the answer. You should begin this section with &amp;lt;code&amp;gt;Context&amp;lt;/code&amp;gt;, to tell WebWork the type of variables that are used. In this example, we use &amp;lt;code&amp;gt;Context(&amp;quot;Numeric&amp;quot;)&amp;lt;/code&amp;gt; to indicate that the following commands work on scalar numbers.&lt;br /&gt;
&lt;br /&gt;
There are many ways to assign value to variables. The two we show here are:&lt;br /&gt;
&lt;br /&gt;
# by a random draw from a range of values (&amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt;, which in this case chooses from a sequence starting at 2, ending at 9, and incrementing by 1, thus choosing integers in the range [2, 9]) &lt;br /&gt;
# by computing a value (&amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt;) from a math expression, in this case the real number calculated by adding one to the value of &amp;lt;tt&amp;gt;$a&amp;lt;/tt&amp;gt;. These are the so-called MathObjects, and they lie at heart of WebWork&#039;s functioning. For instance, MathObjects know how to compute or simplify fairly complicated mathematical expressions, how display themselves in a sensible way in the text of the problem, and how to compare themselves to the student&#039;s answer . See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_MathObjects introduction to MathObjects] and follow its links to learn additional features as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$a = random(2, 9, 1);&lt;br /&gt;
$a_plus_1 = Real(&amp;quot;$a + 1&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_Contexts introduction to contexts] and a [http://webwork.maa.org/wiki/ContextList list] of other types of contexts, such as matrices or intervals.&lt;br /&gt;
&lt;br /&gt;
== Text ==&lt;br /&gt;
The text section gives the text that is shown to the student. It begins with a line containing &amp;lt;code&amp;gt;TEXT(beginproblem());&amp;lt;/code&amp;gt;. Everything between the &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt; lines (each of which must appear alone on a line) is shown to the student. These are usually accompanied with a &amp;lt;code&amp;gt;Context()-&amp;gt;texStrings&amp;lt;/code&amp;gt;, to tell MathObjects (such as &amp;lt;code&amp;gt;$a&amp;lt;/code&amp;gt; in the previous example) to display themselves using TeX formatting, and &amp;lt;code&amp;gt;Context()-&amp;gt;normalStrings&amp;lt;/code&amp;gt; to turn the default behaviour back on.&lt;br /&gt;
&lt;br /&gt;
The text can be formatted with a number of special characters and variables:&lt;br /&gt;
&lt;br /&gt;
* mathematical equations can be typeset with a LaTeX-like formatting macros within &amp;lt;code&amp;gt;\(&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\)&amp;lt;/code&amp;gt; delimiters (displayed inline with text) or &amp;lt;code&amp;gt;\[&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\]&amp;lt;/code&amp;gt; (displayed in their own block).&lt;br /&gt;
* line breaks are denoted with &amp;lt;code&amp;gt;$BR&amp;lt;/code&amp;gt; and new paragraphs with &amp;lt;code&amp;gt;$PAR&amp;lt;/code&amp;gt;.&lt;br /&gt;
* additional formatting is done using special variables to typeset text in bold (between &amp;lt;code&amp;gt;$BBOLD&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EBOLD&amp;lt;/code&amp;gt;) or italic (&amp;lt;code&amp;gt;$BITALIC&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EITALIC&amp;lt;/code&amp;gt;)&lt;br /&gt;
* if you need to execute any code in the text section, enclose it with &amp;lt;code&amp;gt;\{&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\}&amp;lt;/code&amp;gt; delimiters. The resulting value is converted to text and inserted at that point in the section. There are quite a few built-in functions that are used in this manner to, for instance, show images or tables. More fundamentally, this method is used to insert a field for student&#039;s answer. In the following example, we use &amp;lt;code&amp;gt;ans_rule(6)&amp;lt;/code&amp;gt; to insert a blank text entry field six characters wide:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
What number is one greater than \( $a \)?&lt;br /&gt;
$PAR&lt;br /&gt;
\( $a + 1 = \) \{ ans_rule(35) \}&lt;br /&gt;
END_TEXT&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Answer and Solution ==&lt;br /&gt;
The answer and solution section specifies how the answer(s) to the problem is(are) marked for correctness. Optionally, it can also give a solution that is shown to the student after the problem set is complete.&lt;br /&gt;
&lt;br /&gt;
The student&#039;s answer is evaluated with the &amp;lt;code&amp;gt;ANS&amp;lt;/code&amp;gt; command, in which we give it an &amp;quot;answer checker&amp;quot; that compares the student&#039;s entry with the correct value (here, &amp;lt;code&amp;gt;$a_plus_1-&amp;gt;cmp()&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The optional solution is only visible to students after the homework deadline. In it, you are free to explain the correct solution using a combination of text and math formulas just as in the problem text. The only difference is that this section is enclosed in &amp;lt;code&amp;gt;BEGIN_SOLUTION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_SOLUTION&amp;lt;/code&amp;gt; pair, rather than &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt;. You may use the special &amp;lt;code&amp;gt;$SOLUTION&amp;lt;/code&amp;gt; variable to create a heading titled &amp;quot;Solution&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Finally, your document &#039;&#039;&#039;must&#039;&#039;&#039; end with a &amp;lt;code&amp;gt;ENDDOCUMENT();&amp;lt;/code&amp;gt; as the last command in the file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ANS($a_plus_1-&amp;gt;cmp());&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_SOLUTION&lt;br /&gt;
$SOLUTION&lt;br /&gt;
Because \( $a + 1 = $a_plus_1 \), the correct answer is \( $a_plus_1 \).&lt;br /&gt;
&lt;br /&gt;
END_SOLUTION&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342572</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/PG Structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342572"/>
		<updated>2015-01-20T23:19:22Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Expand the paragraph on MathObjects&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WebWork problems are stored in PG files. These files are typically structured in the following way:&lt;br /&gt;
&lt;br /&gt;
== Tagging and Description ==&lt;br /&gt;
The tagging and description section describes the problem for future users and authors. The purpose of the tagging information is to make the problem easier to find by searching or browsing. Each tag must appear on its own line, starting at the first character, and be in the following format: &amp;lt;code&amp;gt;## Tagname(tag value)&amp;lt;/code&amp;gt;. There are three required tags, &amp;lt;tt&amp;gt;DBsubject&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;DBchapter&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;DBsection&amp;lt;/tt&amp;gt;, placing the problem in the [[http://hobbes.la.asu.edu/Holt/chaps-and-secs.html|hierarchy]] that&#039;s exposed in the Library Browser. Problems should also a &amp;lt;tt&amp;gt;Level&amp;lt;/tt&amp;gt;, denoting its difficulty on a predefined [http://webwork.maa.org/wiki/Problem_Levels scale].&lt;br /&gt;
&lt;br /&gt;
Optional tags include &amp;lt;tt&amp;gt;Keywords&amp;lt;/tt&amp;gt;, for easier searching, as well as tags to indicate authorship (&amp;lt;tt&amp;gt;Author&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Institution&amp;lt;/tt&amp;gt;), and to link to a specific textbook (&amp;lt;tt&amp;gt;TitleText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EditionText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;AuthorText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Section1&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Problem1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
More information on tagging can be found on the [http://webwork.maa.org/wiki/Tagging_Problems WebWork MAA wiki].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## DBsubject(&#039;WeBWorK&#039;)&lt;br /&gt;
## DBchapter(&#039;Demos&#039;)&lt;br /&gt;
## DBsection(&#039;Problem&#039;)&lt;br /&gt;
## KEYWORDS(&#039;&#039;)&lt;br /&gt;
## TitleText1(&#039;&#039;)&lt;br /&gt;
## EditionText1(&#039;&#039;)&lt;br /&gt;
## AuthorText1(&#039;&#039;)&lt;br /&gt;
## Section1(&#039;&#039;)&lt;br /&gt;
## Problem1(&#039;&#039;)&lt;br /&gt;
## Author(&#039;Gavin LaRose&#039;)&lt;br /&gt;
## Institution(&#039;UMich&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
The initialization section loads required macros for the problem. It &#039;&#039;must&#039;&#039;&#039; begin with the &amp;lt;code&amp;gt;DOCUMENT();&amp;lt;/code&amp;gt; command, followed by the &amp;lt;code&amp;gt;loadMacros&amp;lt;/code&amp;gt; command that loads additional commands used by the problem. For basic problems, the following is sufficient — template files for specific problem types will tell you if any other macros should be loaded.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
loadMacros(&lt;br /&gt;
&amp;quot;PGstandard.pl&amp;quot;,&lt;br /&gt;
&amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem Set-up ==&lt;br /&gt;
In this section, define variables specific to the problem, for instance various parameters or the correct answer value. These variables are used in subsequent sections either in the text displayed to the student, or to check the answer. You should begin this section with &amp;lt;code&amp;gt;Context&amp;lt;/code&amp;gt;, to tell WebWork the type of variables that are used. In this example, we use &amp;lt;code&amp;gt;Context(&amp;quot;Numeric&amp;quot;)&amp;lt;/code&amp;gt; to indicate that the following commands work on scalar numbers.&lt;br /&gt;
&lt;br /&gt;
There are many ways to assign value to variables. The two we show here are:&lt;br /&gt;
&lt;br /&gt;
# by a random draw from a range of values (&amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt;, which in this case chooses from a sequence starting at 2, ending at 9, and incrementing by 1, thus choosing integers in the range [2, 9]) &lt;br /&gt;
# by computing a value (&amp;lt;code&amp;gt;Real&amp;lt;/code&amp;gt;) from a math expression, in this case the real number calculated by adding one to the value of &amp;lt;tt&amp;gt;$a&amp;lt;/tt&amp;gt;. These are the so-called MathObjects, and they lie at heart of WebWork&#039;s functioning. For instance, MathObjects know how to compute or simplify fairly complicated mathematical expressions, how display themselves in a sensible way in the text of the problem, and how to compare themselves to the student&#039;s answer . See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_MathObjects introduction to MathObjects] and follow its links to learn additional features as needed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$a = random(2, 9, 1);&lt;br /&gt;
$a1 = Real(&amp;quot;$a + 1&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_Contexts introduction to contexts] and a [http://webwork.maa.org/wiki/ContextList list] of other types of contexts, such as matrices or intervals.&lt;br /&gt;
&lt;br /&gt;
== Text ==&lt;br /&gt;
The text section gives the text that is shown to the student. It begins with a line containing &amp;lt;code&amp;gt;TEXT(beginproblem());&amp;lt;/code&amp;gt;. Everything between the &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt; lines (each of which must appear alone on a line) is shown to the student. These are usually accompanied with a &amp;lt;code&amp;gt;Context()-&amp;gt;texStrings&amp;lt;/code&amp;gt;, to tell MathObjects (such as &amp;lt;code&amp;gt;$a&amp;lt;/code&amp;gt; in the previous example) to display themselves using TeX formatting, and &amp;lt;code&amp;gt;Context()-&amp;gt;normalStrings&amp;lt;/code&amp;gt; to turn the default behaviour back on.&lt;br /&gt;
&lt;br /&gt;
The text can be formatted with a number of special characters and variables:&lt;br /&gt;
&lt;br /&gt;
- mathematical equations can be typeset with a LaTeX-like formatting macros within &amp;lt;code&amp;gt;\(&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\)&amp;lt;/code&amp;gt; delimiters (displayed inline with text) or &amp;lt;code&amp;gt;\[&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\]&amp;lt;/code&amp;gt; (displayed in their own block).&lt;br /&gt;
&lt;br /&gt;
- line breaks are denoted with &amp;lt;code&amp;gt;$BR&amp;lt;/code&amp;gt; and new paragraphs with &amp;lt;code&amp;gt;$PAR&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
- additional formatting is done using special variables to typeset text in bold (between &amp;lt;code&amp;gt;$BBOLD&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EBOLD&amp;lt;/code&amp;gt;) or italic (&amp;lt;code&amp;gt;$BITALIC&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EITALIC&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
- if you need to execute any code in the text section, enclose it with &amp;lt;code&amp;gt;\{&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\}&amp;lt;/code&amp;gt; delimiters. The resulting value is converted to text and inserted at that point in the section. There are quite a few built-in functions that are used in this manner to, for instance, show images or tables. More fundamentally, this method is used to insert a field for student&#039;s answer. In the following example, we use &amp;lt;code&amp;gt;ans_rule(6)&amp;lt;/code&amp;gt; to insert a blank text entry field six characters wide:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
What number is one greater than \( $a \)?&lt;br /&gt;
$PAR&lt;br /&gt;
\( $a + 1 = \) \{ ans_rule(35) \}&lt;br /&gt;
END_TEXT&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Answer and Solution ==&lt;br /&gt;
The answer and solution section specifies how the answer(s) to the problem is(are) marked for correctness. Optionally, it can also give a solution that is shown to the student after the problem set is complete.&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342568</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/PG Structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342568"/>
		<updated>2015-01-20T23:07:44Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Write the &amp;quot;Text&amp;quot; section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WebWork problems are stored in PG files. These files are typically structured in the following way:&lt;br /&gt;
&lt;br /&gt;
== Tagging and Description ==&lt;br /&gt;
The tagging and description section describes the problem for future users and authors. The purpose of the tagging information is to make the problem easier to find by searching or browsing. Each tag must appear on its own line, starting at the first character, and be in the following format: &amp;lt;code&amp;gt;## Tagname(tag value)&amp;lt;/code&amp;gt;. There are three required tags, &amp;lt;tt&amp;gt;DBsubject&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;DBchapter&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;DBsection&amp;lt;/tt&amp;gt;, placing the problem in the [[http://hobbes.la.asu.edu/Holt/chaps-and-secs.html|hierarchy]] that&#039;s exposed in the Library Browser. Problems should also a &amp;lt;tt&amp;gt;Level&amp;lt;/tt&amp;gt;, denoting its difficulty on a predefined [http://webwork.maa.org/wiki/Problem_Levels scale].&lt;br /&gt;
&lt;br /&gt;
Optional tags include &amp;lt;tt&amp;gt;Keywords&amp;lt;/tt&amp;gt;, for easier searching, as well as tags to indicate authorship (&amp;lt;tt&amp;gt;Author&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Institution&amp;lt;/tt&amp;gt;), and to link to a specific textbook (&amp;lt;tt&amp;gt;TitleText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EditionText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;AuthorText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Section1&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Problem1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
More information on tagging can be found on the [http://webwork.maa.org/wiki/Tagging_Problems WebWork MAA wiki].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## DBsubject(&#039;WeBWorK&#039;)&lt;br /&gt;
## DBchapter(&#039;Demos&#039;)&lt;br /&gt;
## DBsection(&#039;Problem&#039;)&lt;br /&gt;
## KEYWORDS(&#039;&#039;)&lt;br /&gt;
## TitleText1(&#039;&#039;)&lt;br /&gt;
## EditionText1(&#039;&#039;)&lt;br /&gt;
## AuthorText1(&#039;&#039;)&lt;br /&gt;
## Section1(&#039;&#039;)&lt;br /&gt;
## Problem1(&#039;&#039;)&lt;br /&gt;
## Author(&#039;Gavin LaRose&#039;)&lt;br /&gt;
## Institution(&#039;UMich&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
The initialization section loads required macros for the problem. It &#039;&#039;must&#039;&#039;&#039; begin with the &amp;lt;code&amp;gt;DOCUMENT();&amp;lt;/code&amp;gt; command, followed by the &amp;lt;code&amp;gt;loadMacros&amp;lt;/code&amp;gt; command that loads additional commands used by the problem. For basic problems, the following is sufficient — template files for specific problem types will tell you if any other macros should be loaded.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
loadMacros(&lt;br /&gt;
&amp;quot;PGstandard.pl&amp;quot;,&lt;br /&gt;
&amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem Set-up ==&lt;br /&gt;
In this section, define variables specific to the problem, for instance various parameters or the correct answer value. These variables are used in subsequent sections either in the text displayed to the student, or to check the answer. You should begin this section with &amp;lt;code&amp;gt;Context&amp;lt;/code&amp;gt;, to tell WebWork the type of variables that are used. In this example, we use &amp;lt;code&amp;gt;Context(&amp;quot;Numeric&amp;quot;)&amp;lt;/code&amp;gt; to indicate that the following commands work on scalar numbers.&lt;br /&gt;
&lt;br /&gt;
There are many ways to assign value to variables. The two we show here are by a random draw from a range of integers (&amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$a = random(2, 9, 1);&lt;br /&gt;
$a1 = Real(&amp;quot;$a + 1&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See MAA WebWork wiki for an [http://webwork.maa.org/wiki/Introduction_to_Contexts introduction to contexts] and a [http://webwork.maa.org/wiki/ContextList list] of other types of contexts, such as matrices or intervals.&lt;br /&gt;
&lt;br /&gt;
== Text ==&lt;br /&gt;
The text section gives the text that is shown to the student. It begins with a line containing &amp;lt;code&amp;gt;TEXT(beginproblem());&amp;lt;/code&amp;gt;. Everything between the &amp;lt;code&amp;gt;BEGIN_TEXT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;END_TEXT&amp;lt;/code&amp;gt; lines (each of which must appear alone on a line) is shown to the student. These are usually accompanied with a &amp;lt;code&amp;gt;Context()-&amp;gt;texStrings&amp;lt;/code&amp;gt;, to tell MathObjects (such as &amp;lt;code&amp;gt;$a&amp;lt;/code&amp;gt; in the previous example) to display themselves using TeX formatting, and &amp;lt;code&amp;gt;Context()-&amp;gt;normalStrings&amp;lt;/code&amp;gt; to turn the default behaviour back on.&lt;br /&gt;
&lt;br /&gt;
The text can be formatted with a number of special characters and variables:&lt;br /&gt;
&lt;br /&gt;
- mathematical equations can be typeset with a LaTeX-like formatting macros within &amp;lt;code&amp;gt;\(&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\)&amp;lt;/code&amp;gt; delimiters (displayed inline with text) or &amp;lt;code&amp;gt;\[&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\]&amp;lt;/code&amp;gt; (displayed in their own block).&lt;br /&gt;
&lt;br /&gt;
- line breaks are denoted with &amp;lt;code&amp;gt;$BR&amp;lt;/code&amp;gt; and new paragraphs with &amp;lt;code&amp;gt;$PAR&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
- additional formatting is done using special variables to typeset text in bold (between &amp;lt;code&amp;gt;$BBOLD&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EBOLD&amp;lt;/code&amp;gt;) or italic (&amp;lt;code&amp;gt;$BITALIC&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$EITALIC&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
- if you need to execute any code in the text section, enclose it with &amp;lt;code&amp;gt;\{&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;\}&amp;lt;/code&amp;gt; delimiters. The resulting value is converted to text and inserted at that point in the section. There are quite a few built-in functions that are used in this manner to, for instance, show images or tables. More fundamentally, this method is used to insert a field for student&#039;s answer. In the following example, we use &amp;lt;code&amp;gt;ans_rule(6)&amp;lt;/code&amp;gt; to insert a blank text entry field six characters wide:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
What number is one greater than \( $a \)?&lt;br /&gt;
$PAR&lt;br /&gt;
\( $a + 1 = \) \{ ans_rule(35) \}&lt;br /&gt;
END_TEXT&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Answer and Solution ==&lt;br /&gt;
The answer and solution section specifies how the answer(s) to the problem is(are) marked for correctness. Optionally, it can also give a solution that is shown to the student after the problem set is complete.&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342502</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/PG Structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342502"/>
		<updated>2015-01-20T19:05:47Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Initial outline of the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WebWork problems are stored in PG files. These files are typically structured in the following way:&lt;br /&gt;
&lt;br /&gt;
== Tagging and Description ==&lt;br /&gt;
The tagging and description section describes the problem for future users and authors. The purpose of the tagging information is to make the problem easier to find by searching or browsing. Each tag must appear on its own line, starting at the first character, and be in the following format: &amp;lt;code&amp;gt;## Tagname(tag value)&amp;lt;/code&amp;gt;. There are three required tags, &amp;lt;tt&amp;gt;DBsubject&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;DBchapter&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;DBsection&amp;lt;/tt&amp;gt;, placing the problem in the [[http://hobbes.la.asu.edu/Holt/chaps-and-secs.html|hierarchy]] that&#039;s exposed in the Library Browser. Problems should also a &amp;lt;tt&amp;gt;Level&amp;lt;/tt&amp;gt;, denoting its difficulty on a predefined [http://webwork.maa.org/wiki/Problem_Levels scale].&lt;br /&gt;
&lt;br /&gt;
Optional tags include &amp;lt;tt&amp;gt;Keywords&amp;lt;/tt&amp;gt;, for easier searching, as well as tags to indicate authorship (&amp;lt;tt&amp;gt;Author&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Institution&amp;lt;/tt&amp;gt;), and to link to a specific textbook (&amp;lt;tt&amp;gt;TitleText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EditionText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;AuthorText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Section1&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Problem1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
More information on tagging can be found on the [http://webwork.maa.org/wiki/Tagging_Problems WebWork MAA wiki].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## DBsubject(&#039;WeBWorK&#039;)&lt;br /&gt;
## DBchapter(&#039;Demos&#039;)&lt;br /&gt;
## DBsection(&#039;Problem&#039;)&lt;br /&gt;
## KEYWORDS(&#039;&#039;)&lt;br /&gt;
## TitleText1(&#039;&#039;)&lt;br /&gt;
## EditionText1(&#039;&#039;)&lt;br /&gt;
## AuthorText1(&#039;&#039;)&lt;br /&gt;
## Section1(&#039;&#039;)&lt;br /&gt;
## Problem1(&#039;&#039;)&lt;br /&gt;
## Author(&#039;Gavin LaRose&#039;)&lt;br /&gt;
## Institution(&#039;UMich&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
The initialization section loads required macros for the problem. It &#039;&#039;must&#039;&#039;&#039; begin with the &amp;lt;code&amp;gt;DOCUMENT();&amp;lt;/code&amp;gt; command, followed by the &amp;lt;code&amp;gt;loadMacros&amp;lt;/code&amp;gt; command that loads additional commands used by the problem. For basic problems, the following is sufficient — template files for specific problem types will tell you if any other macros should be loaded.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
loadMacros(&lt;br /&gt;
&amp;quot;PGstandard.pl&amp;quot;,&lt;br /&gt;
&amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem Set-up ==&lt;br /&gt;
In this section, define variables specific to the problem, for instance various parameters or the correct answer value. These variables are used in subsequent sections either in the text displayed to the student, or to check the answer. You should begin this section with &amp;lt;code&amp;gt;Context&amp;lt;/code&amp;gt;, to tell WebWork the type of variables that are used. In this example, we use &amp;lt;code&amp;gt;Context(&amp;quot;Numeric&amp;quot;)&amp;lt;/code&amp;gt; to indicate that the following commands work on scalar numbers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$a = random(2, 9, 1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See [http://webwork.maa.org/wiki/ContextList MAA WebWork wiki] for additional information on other types of contexts, such as matrices or intervals.&lt;br /&gt;
&lt;br /&gt;
== Text ==&lt;br /&gt;
The text section gives the text that is shown to the student.&lt;br /&gt;
&lt;br /&gt;
== Answer and Solution ==&lt;br /&gt;
The answer and solution section specifies how the answer(s) to the problem is(are) marked for correctness. Optionally, it can also give a solution that is shown to the student after the problem set is complete.&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342501</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates/PG Structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates/PG_Structure&amp;diff=342501"/>
		<updated>2015-01-20T19:04:31Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Initial outline of the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WebWork problems are stored in PG files. These files are typically structured in the following way:&lt;br /&gt;
&lt;br /&gt;
== Tagging and Description ==&lt;br /&gt;
The tagging and description section describes the problem for future users and authors. The purpose of the tagging information is to make the problem easier to find by searching or browsing. Each tag must appear on its own line, starting at the first character, and be in the following format: &amp;lt;code&amp;gt;## Tagname(tag value)&amp;lt;/code&amp;gt;. There are three required tags, &amp;lt;tt&amp;gt;DBsubject&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;DBchapter&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;DBsection&amp;lt;/tt&amp;gt;, placing the problem in the [[http://hobbes.la.asu.edu/Holt/chaps-and-secs.html|hierarchy]] that&#039;s exposed in the Library Browser. Problems should also a &amp;lt;tt&amp;gt;Level&amp;lt;/tt&amp;gt;, denoting its difficulty on a predefined [http://webwork.maa.org/wiki/Problem_Levels scale].&lt;br /&gt;
&lt;br /&gt;
Optional tags include &amp;lt;tt&amp;gt;Keywords&amp;lt;/tt&amp;gt;, for easier searching, as well as tags to indicate authorship (&amp;lt;tt&amp;gt;Author&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Institution&amp;lt;/tt&amp;gt;), and to link to a specific textbook (&amp;lt;tt&amp;gt;TitleText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;EditionText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;AuthorText1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;Section1&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Problem1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
More information on tagging can be found on the [http://webwork.maa.org/wiki/Tagging_Problems WebWork MAA wiki].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## DBsubject(&#039;WeBWorK&#039;)&lt;br /&gt;
## DBchapter(&#039;Demos&#039;)&lt;br /&gt;
## DBsection(&#039;Problem&#039;)&lt;br /&gt;
## KEYWORDS(&#039;&#039;)&lt;br /&gt;
## TitleText1(&#039;&#039;)&lt;br /&gt;
## EditionText1(&#039;&#039;)&lt;br /&gt;
## AuthorText1(&#039;&#039;)&lt;br /&gt;
## Section1(&#039;&#039;)&lt;br /&gt;
## Problem1(&#039;&#039;)&lt;br /&gt;
## Author(&#039;Gavin LaRose&#039;)&lt;br /&gt;
## Institution(&#039;UMich&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
The initialization section loads required macros for the problem. It &#039;&#039;must&#039;&#039;&#039; begin with the &amp;lt;code&amp;gt;DOCUMENT();&amp;lt;/code&amp;gt; command, followed by the &amp;lt;code&amp;gt;loadMacros&amp;lt;/code&amp;gt; command that loads additional commands used by the problem. For basic problems, the following is sufficient — template files for specific problem types will tell you if any other macros should be loaded.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
loadMacros(&lt;br /&gt;
&amp;quot;PGstandard.pl&amp;quot;,&lt;br /&gt;
&amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Problem Set-up ==&lt;br /&gt;
In this section, define variables specific to the problem, for instance various parameters or the correct answer value. These variables are used in subsequent sections either in the text displayed to the student, or to check the answer. You should begin this section with &amp;lt;code&amp;gt;Context&amp;lt;/code&amp;gt;, to tell WebWork the type of variables that are used. In this example, we use &amp;lt;code&amp;gt;Context(&amp;quot;Numeric&amp;quot;) to indicate that the following commands work on scalar numbers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$a = random(2, 9, 1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See [http://webwork.maa.org/wiki/ContextList MAA WebWork wiki] for additional information on other types of contexts, such as matrices or intervals.&lt;br /&gt;
&lt;br /&gt;
== Text ==&lt;br /&gt;
The text section gives the text that is shown to the student.&lt;br /&gt;
&lt;br /&gt;
== Answer and Solution ==&lt;br /&gt;
The answer and solution section specifies how the answer(s) to the problem is(are) marked for correctness. Optionally, it can also give a solution that is shown to the student after the problem set is complete.&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R&amp;diff=342018</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R&amp;diff=342018"/>
		<updated>2015-01-17T00:29:26Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add a listing of subpages&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Documentation:WeBWorK|WeBWorK]] is widely used in math courses&lt;br /&gt;
around the world, but its adoption in statistics has been limited. One&lt;br /&gt;
reason is that while WebWork implements a broad range of arithmetic&lt;br /&gt;
and calculus-type operations, it has little support for statistical&lt;br /&gt;
concepts such as probability distributions or statistical models.&lt;br /&gt;
&lt;br /&gt;
The WeBWorKiR (WeBWorK integrating R) project offers a solution in the&lt;br /&gt;
form of integration between WeBWorK and the&lt;br /&gt;
[http://www.r-project.org statistical computing software R]. The open&lt;br /&gt;
source software R is extremely popular in statistical research,&lt;br /&gt;
analysis, and education. It provides a huge range of operations for&lt;br /&gt;
statistical computation and graphics. The WeBWorKiR project has two&lt;br /&gt;
main goals: (i) to allow WeBWorK to communicate with R and (ii) the&lt;br /&gt;
creation of a large collection of homework questions for use in&lt;br /&gt;
undergraduate instruction in statistics. With the WeBWorKiR project,&lt;br /&gt;
instructors can use R code in their WebWorK problems to generate data,&lt;br /&gt;
perform analyses, and create figures.&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR has been developed in the Department of Statistics since&lt;br /&gt;
June 2012, with the funding from Teaching and Learning Improvement&lt;br /&gt;
Fund. It has been used in a number of second- and third-year&lt;br /&gt;
Statistics courses at UBC, reaching around 3000 students so far. The&lt;br /&gt;
aim is that problems created and tested on students through the&lt;br /&gt;
WeBWorKiR project are made available to all educators via WeBWorK&#039;s&lt;br /&gt;
Open Problem Library.&lt;br /&gt;
&lt;br /&gt;
If you are an instructor, please look at the [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide|authoring]] guide for&lt;br /&gt;
information on writing WebWork questions that make use of R. If you&lt;br /&gt;
are a WebWork system administrator, you can find setup information in&lt;br /&gt;
our [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide|installation guide]].&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;br /&gt;
&lt;br /&gt;
== Subpages ==&lt;br /&gt;
{{Special:PrefixIndex/Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/}}&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=342017</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=342017"/>
		<updated>2015-01-17T00:18:51Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Multiple choice:&lt;br /&gt;
# One correct answer, no responses anchored.&lt;br /&gt;
# One correct answer, one response anchored.&lt;br /&gt;
# More than one correct answer (anchoring would be as above, so extra template for anchoring not required).&lt;br /&gt;
# Answer selected from pull-down menu.&lt;br /&gt;
&lt;br /&gt;
Short answer:&lt;br /&gt;
# Numerical, only one response accepted.&lt;br /&gt;
# Numerical, response accepted within specified tolerance.&lt;br /&gt;
# Numerical, response accepted from list.&lt;br /&gt;
# String response&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=342016</id>
		<title>Sandbox:ARCHIVED: WeBWorK/Problem Authoring Templates</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/Problem_Authoring_Templates&amp;diff=342016"/>
		<updated>2015-01-17T00:17:24Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Created page with &amp;quot; Multiple choice: (i) One correct answer, no responses anchored. (ii) One correct answer, one response anchored. (iii) More than one correct answer (anchoring would be as abov...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Multiple choice:&lt;br /&gt;
(i) One correct answer, no responses anchored.&lt;br /&gt;
(ii) One correct answer, one response anchored.&lt;br /&gt;
(iii) More than one correct answer (anchoring would be as above, so extra template for anchoring not required).&lt;br /&gt;
(iv) Answer selected from pull-down menu.&lt;br /&gt;
&lt;br /&gt;
Short answer:&lt;br /&gt;
(i) Numerical, only one response accepted.&lt;br /&gt;
(ii) Numerical, response accepted within specified tolerance.&lt;br /&gt;
(iii) Numerical, response accepted from list.&lt;br /&gt;
(iv) String response&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide&amp;diff=341897</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Installation guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide&amp;diff=341897"/>
		<updated>2015-01-15T22:29:46Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add specifying Rserve host location in WebWork config file (required since S-R-IO 0.10)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== WeBWorKiR Installation Guide ==&lt;br /&gt;
&lt;br /&gt;
The audience for this guide are system administrators who want to set&lt;br /&gt;
up R integration in WeBWorK. We assume that you already have, or know&lt;br /&gt;
how to set up, a basic WeBWorK server. If not, please see the&lt;br /&gt;
[http://webwork.maa.org/wiki/Release_notes_for_WeBWorK_2.8 release notes] on the WeBWorK wiki and the [http://webwork.maa.org/wiki/Installation_Manual_for_2.8_on_Ubuntu_12.04 guide] to installing WeBWorK on an Ubuntu server. You may also find&lt;br /&gt;
Jason Aubrey&#039;s [https://github.com/aubreyja/ww_install/ ww_install] installation script useful.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
After you have a working WeBWorK server, there are three distinct steps that need to happen:&lt;br /&gt;
&lt;br /&gt;
# set up the R server&lt;br /&gt;
# install the Perl module for the Perl-R bridge&lt;br /&gt;
# configure WeBWorK to use this module in PG&lt;br /&gt;
&lt;br /&gt;
=== Set up the R server ===&lt;br /&gt;
&lt;br /&gt;
Your R server (which can be on the same server as WeBWorK, but in a real-world scenario will more likely run on its own hardware/VM), is quite easy to set up:&lt;br /&gt;
&lt;br /&gt;
# install R following OS-specific instructions on the project [http://www.r-project.org homepage].&lt;br /&gt;
# install the [http://www.rforge.net/Rserve/ Rserve] server, which allows remote clients to execute R code on the Rserve&#039;s server and returns the execution&#039;s result in response. The easiest way is to run (as an administrative user) &amp;lt;code&amp;gt;Rscript -e &#039;install.packages(&amp;quot;Rserve&amp;quot;, repo=&amp;quot;http://cran.rstudio.com&amp;quot;)&#039;&amp;lt;/code&amp;gt;. Note that this package includes C source that needs to be compiled, so you have to have the basic developer tools present on the server.&lt;br /&gt;
# run the Rserve service as appropriate to your system. The command you need to run is &amp;quot;R CMD Rserve&amp;quot;. This will start the Rserve daemon which will listen on port 6311. The daemon only accepts connections from the localhost; if you run WebWork and Rserve on separate servers, read the final section of this page for additional configuration steps for your system.&lt;br /&gt;
&lt;br /&gt;
=== Install the Perl-R bridge ===&lt;br /&gt;
&lt;br /&gt;
Perl module [http://search.cpan.org/perldoc?Statistics::R::IO Statistics::R::IO] implements Rserve&#039;s communication protocol in Perl and provides translation from R data structures to Perl&#039;s. It is available on CPAN and can be installed in the standard manner for Perl modules, e.g., by running (as an admin user) &amp;lt;code&amp;gt;cpan Statistics::R::IO&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Configure Webwork to use the Perl-R bridge in PG ===&lt;br /&gt;
&lt;br /&gt;
Once the Perl module RserveClient is installed, you can make its functionality available in webwork problems by installing the RserveClient.pl macro and adding the module to the list of modules preloaded by WeBWorK. We use use &amp;quot;${WW_PREFIX}&amp;quot; to indicate the directory where WeBWorK is installed. (This directory will, for instance, contain subdirectories &amp;quot;webwork2&amp;quot; and &amp;quot;pg&amp;quot;; a typical choice is &amp;quot;/opt/webwork&amp;quot;, but a different one may be used on your system.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;install RserveClient.pl macro into &amp;quot;$WW_PREFIX/pg/macros&amp;quot;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget -q -O ${WW_PREFIX}/pg/macros/RserveClient.pl \&lt;br /&gt;
https://raw.githubusercontent.com/cubranic/Statistics-R-IO/release/extras/WebWork/RserveClient.pl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;perhaps a better solution, but depending on having the Perl module File::ShareDir, ensures that the RserveClient.pl macro matches the version of Statistics::R::IO that you have installed:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cp &amp;quot;`perl -MFile::ShareDir -e &#039;print File::ShareDir::dist_file(\&amp;quot;Statistics-R-IO\&amp;quot;, \&amp;quot;WebWork/RserveClient.pl\&amp;quot;)&#039;`&amp;quot; \&lt;br /&gt;
   ${WW_PREFIX}/pg/macros/RserveClient.pl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;add the RserveClient module(s) to the list of modules preloaded by&lt;br /&gt;
WeBWorK, so that it is available to the RserveClient.pl macro. You can&lt;br /&gt;
do this by modifying &amp;quot;${WW_PREFIX}/webwork2/conf/defaults.conf&amp;quot;,&lt;br /&gt;
but since it&#039;s a local configuration, you should put it in&lt;br /&gt;
localOverrides.conf:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;gt;&amp;gt; ${WW_PREFIX}/webwork2/conf/localOverrides.conf &amp;lt;&amp;lt;&#039;EOF&#039;&lt;br /&gt;
push @{$pg{modules}},&lt;br /&gt;
   [qw( Statistics::R::IO::Rserve )],&lt;br /&gt;
   [qw( Statistics::R::IO::ParserState )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Character )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Double )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Environment )],&lt;br /&gt;
   [qw( Statistics::R::REXP::GlobalEnvironment )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Integer )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Language )],&lt;br /&gt;
   [qw( Statistics::R::REXP::List )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Logical )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Null )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Raw )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Symbol )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Unknown )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Vector )],&lt;br /&gt;
   [qw( Statistics::R::REXP )],&lt;br /&gt;
   [qw( IO::File )],&lt;br /&gt;
   [qw( IO::Handle )],&lt;br /&gt;
   [qw( Moose )],&lt;br /&gt;
   [qw( Class::MOP )];&lt;br /&gt;
$pg{specialPGEnvironmentVars}{Rserve} = {host =&amp;gt; &amp;quot;localhost&amp;quot;};&lt;br /&gt;
&lt;br /&gt;
1;&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional configuration when WeBWorK and R are on separate hosts ===&lt;br /&gt;
&lt;br /&gt;
If you run WeBWorK and R on separate hosts, you can either set up a tunnel to forward port 6311 from WeBWorK to R&#039;s host, or do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;set up Rserve to listen on all network interfaces, not just localhost by adding a line &amp;quot;remote enable&amp;quot; to file &amp;quot;/etc/Rserv.conf&amp;quot;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cat &amp;lt;&#039;EOF&#039; &amp;gt;&amp;gt; /etc/Rserv.conf&lt;br /&gt;
remote enable&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;use the correct host name (instead of &amp;quot;localhost&amp;quot;) in the &amp;quot;Rserve host&amp;quot; line of &amp;quot;localOverrides.conf&amp;quot;. For example:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$pg{specialPGEnvironmentVars}{Rserve} = {host =&amp;gt; &amp;quot;www.example.com&amp;quot;};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in this case you will also want to set up the Rserve host&#039;s firewall to only allow connections from the WeBWorK host(s), or otherwise it will happily execute arbitrary code from any Rserve client anywhere on the internet!&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=315408</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=315408"/>
		<updated>2014-08-28T17:59:31Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add an example for &amp;#039;rserve_get_file&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== WeBWorKiR User Guide ==&lt;br /&gt;
&lt;br /&gt;
The audience for this guide are problem authors who want to use R&#039;s&lt;br /&gt;
facilities in their WeBWorK questions. We assume that you already know&lt;br /&gt;
how to create problems with the PG language (which itself is a subset&lt;br /&gt;
of Perl) and are familiar with the concepts of macros in PG. We also&lt;br /&gt;
assume that your WeBWorKiR environment has been set up as described in&lt;br /&gt;
the [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide|installation guide]].&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR is a system that involves two separate servers: WeBWorK and&lt;br /&gt;
R. In a normal operation, when a student accesses WeBWorK via a web&lt;br /&gt;
browser to work on homework problems, WeBWorK runs the PG code&lt;br /&gt;
defining the problem to compute:&lt;br /&gt;
&lt;br /&gt;
a) values used in the question, for example a random vector of five integers&lt;br /&gt;
&lt;br /&gt;
b) the text of the question, typically given in format resembling LaTeX and optionally displaying values computed in (a)&lt;br /&gt;
&lt;br /&gt;
c) values of the correct answer, for example, the mean of the vector calculated in (a)&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR adds to this the ability to run arbitrary computations in R&lt;br /&gt;
and make their results available to the rest of the PG code as if they&lt;br /&gt;
were constructed using the standard PG functions. (In our running&lt;br /&gt;
example, we could construct the random vector in R with `sample`,&lt;br /&gt;
and/or calculate its mean with `mean`.) The reason why one might want&lt;br /&gt;
to do this is R&#039;s rich library of high-quality statistical functions&lt;br /&gt;
as well as its graphical abilities. While in theory these could be&lt;br /&gt;
both replicated with PG, it would take a huge effort that can be&lt;br /&gt;
better spent by simply using the functionality already available in R.&lt;br /&gt;
&lt;br /&gt;
The way this works is that WeBWorK uses a Perl module that can talk to&lt;br /&gt;
a server running the [[http://www.rforge.net/Rserve/|Rserve]] software,&lt;br /&gt;
which allows remote clients to execute R code on the Rserve&#039;s server&lt;br /&gt;
and returns the execution&#039;s result in response. The Perl module&lt;br /&gt;
converts this response from R&#039;s native values (e.g., a generic vector,&lt;br /&gt;
aka &amp;quot;list&amp;quot;) to those understandable to Perl (e.g., an array), making&lt;br /&gt;
them available to the rest of the PG code.&lt;br /&gt;
&lt;br /&gt;
== Loading the macros ==&lt;br /&gt;
&lt;br /&gt;
To use R code in a problem, include &amp;quot;RserveClient.pl&amp;quot; in the&lt;br /&gt;
&amp;quot;loadMacros&amp;quot; call at the start of the question. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
loadMacros(&lt;br /&gt;
  &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
  &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
  &amp;quot;RserveClient.pl&amp;quot;    # &amp;lt;--- R integration&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Rserve macros ==&lt;br /&gt;
&lt;br /&gt;
The Rserve software creates an R session for each remote client. This&lt;br /&gt;
means that clients&#039; interactions with R are kept separate from each&lt;br /&gt;
other, just as if you started R twice on your local computer. A&lt;br /&gt;
session persists as long as the client is connected, so that multiple&lt;br /&gt;
calls from the client using the same session see the objects created&lt;br /&gt;
in previous calls. (This behaviour mirrors what happens in a local&lt;br /&gt;
session, where each R command you execute at the console after&lt;br /&gt;
pressing ENTER sees the results of earlier commands.) When a sessions&lt;br /&gt;
is *closed*, its contents are wiped off without a trace, just like&lt;br /&gt;
quitting the R application run locally.&lt;br /&gt;
&lt;br /&gt;
The RserveClient offers macros to start and finish a session, and&lt;br /&gt;
execute R commands in the current session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_eval(&amp;quot;some R code&amp;quot;)&amp;lt;/code&amp;gt;: this function sends the R code given&lt;br /&gt;
as its string argument to Rserve for execution. It returns *an&lt;br /&gt;
array* representation of the R code&#039;s result. (This means that the&lt;br /&gt;
value of &amp;lt;code&amp;gt;rserve_eval(&amp;quot;pi&amp;quot;)&amp;lt;/code&amp;gt; is an array with a single element&lt;br /&gt;
3.14159265358979. If you want to keep this value and use it in the&lt;br /&gt;
rest of the problem, assign it to an array variable. For example:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;@pi = rserve_eval(&amp;quot;pi&amp;quot;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; Multiple calls within the same problem share the R session and the object workspace, so you can break up your R code in as many &amp;lt;tt&amp;gt;rserve_eval&amp;lt;/tt&amp;gt; statements as you&#039;d like.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_start()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rserve_finish()&amp;lt;/code&amp;gt;: Start up and close the current connection to the Rserve server. In&lt;br /&gt;
normal use, these functions are completely optional because the first&lt;br /&gt;
call to &amp;lt;code&amp;gt;rserve_eval&amp;lt;/code&amp;gt; will call start the Rserve session if one is not&lt;br /&gt;
already open. Similarly, the current session will be automatically closed at the end of the problem.&lt;br /&gt;
Other than backward compatibility, the only reason for using these&lt;br /&gt;
functions is to start a new clean session within a single problem,&lt;br /&gt;
which shouldn&#039;t be a common occurrence.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== A note on Perl quoting rules ===&lt;br /&gt;
&lt;br /&gt;
Beware of Perl&#039;s quoting rules when writing R code. The text in double&lt;br /&gt;
quotes gets interpreted for escape sequences (e.g., &amp;lt;code&amp;gt;&amp;quot;\n&amp;quot;&amp;lt;/code&amp;gt; represents a&lt;br /&gt;
newline) and variables (e.g., &amp;lt;code&amp;gt;&amp;quot;The value of pi is $pi[0]&amp;quot;&amp;lt;/code&amp;gt; will be&lt;br /&gt;
interpolated into &amp;lt;code&amp;gt;&amp;quot;The value of pi is 3.14159265358979&amp;quot;&amp;lt;/code&amp;gt;, given the&lt;br /&gt;
code above). This is a problem if you&#039;re trying to extract an element&lt;br /&gt;
of a list by name using the &amp;lt;code&amp;gt;&amp;quot;$&amp;quot;&amp;lt;/code&amp;gt; operator in R because the text&lt;br /&gt;
following it will be interpreted as a variable. For instance, running&lt;br /&gt;
&amp;lt;code&amp;gt;rserve_eval(&amp;quot;cars$speed&amp;quot;)&amp;lt;/code&amp;gt; will not return the &amp;quot;speed&amp;quot; column of the&lt;br /&gt;
standard &amp;quot;cars&amp;quot; dataset, because &amp;quot;$speed&amp;quot; in the string will be&lt;br /&gt;
replaced by the value of the PG variable &amp;lt;code&amp;gt;$speed&amp;lt;/code&amp;gt;, which if not yet&lt;br /&gt;
defined will be empty string, so that the R code that actually gets&lt;br /&gt;
executed is simply &amp;quot;cars&amp;quot;. Instead, using single quotes, which prevent&lt;br /&gt;
variable and escape sequence interpolation and instead keep the string&lt;br /&gt;
exactly as entered: &amp;lt;code&amp;gt;rserve_eval(&#039;cars$speed&#039;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
On the other hand, some time you actually might want variable&lt;br /&gt;
interpolation to be done, for instance to construct the R code that&lt;br /&gt;
uses values of variables constructed with PG functions. For instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$pi = Real(&amp;quot;pi&amp;quot;);&lt;br /&gt;
@difference = rserve_eval(&amp;quot;pi - $pi&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will calculate the difference between the value between R and PG&#039;s&lt;br /&gt;
values of &amp;quot;pi&amp;quot; and put the result in the &amp;lt;tt&amp;gt;@difference&amp;lt;/tt&amp;gt; array. Note that&lt;br /&gt;
the same R code can be constructed using Perl&#039;s string concatenation&lt;br /&gt;
operator dot (&amp;quot;.&amp;quot;): &amp;lt;tt&amp;gt;rserve_eval(&#039;pi - &#039; . $pi)&amp;lt;/tt&amp;gt;. Personally, I&lt;br /&gt;
recommend sticking with single quotes to prevent unwanted surprises,&lt;br /&gt;
and using the dot operator if needing to include the value of a PG&lt;br /&gt;
variable.&lt;br /&gt;
&lt;br /&gt;
== Displaying R graphics ==&lt;br /&gt;
&lt;br /&gt;
R has excellent facilities for creating production-quality statistical&lt;br /&gt;
graphics, from simple scatterplots to complex spatial visualizatons&lt;br /&gt;
overlaid on geographical maps. These graphics can be produced in a&lt;br /&gt;
variety of formats (in R parlance, devices), from the user&#039;s monitor&lt;br /&gt;
to PDF or JPG files. The RserveClient allows the author to present&lt;br /&gt;
these graphics in the question by bracketing the R graphing code with&lt;br /&gt;
macros &amp;lt;tt&amp;gt;rserve_start_plot&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;rserve_finish_plot&amp;lt;/tt&amp;gt;, and then showing&lt;br /&gt;
the produced image in the question with PG&#039;s macro &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; (see the&lt;br /&gt;
WeBWorK [http://webwork.maa.org/wiki/Image documentation]).&lt;br /&gt;
&lt;br /&gt;
The following code is a complete example&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
&lt;br /&gt;
loadMacros(&lt;br /&gt;
   &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
   &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
   &amp;quot;RserveClient.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Print problem number and point value (weight) for the problem&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
&lt;br /&gt;
#  Setup&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$mean = random(-2, 2, .5);&lt;br /&gt;
&lt;br /&gt;
$img = rserve_start_plot(&#039;png&#039;);&lt;br /&gt;
rserve_eval(&#039;curve(dnorm(x, mean=&#039; . $mean . &#039;), xlim=c(-4, 4)); 0&#039;);&lt;br /&gt;
$image_path = rserve_finish_plot($img);&lt;br /&gt;
&lt;br /&gt;
#  Text&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
&lt;br /&gt;
What is the mean of the normal distribution shown in the figure below:&lt;br /&gt;
\{ ans_rule(5) \}&lt;br /&gt;
&lt;br /&gt;
$PAR&lt;br /&gt;
&lt;br /&gt;
\{ image($image_path, width=&amp;gt;300, height=&amp;gt;300) \}:&lt;br /&gt;
END_TEXT&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
#  Answers&lt;br /&gt;
ANS(Real($mean)-&amp;gt;cmp);&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The four key lines are as follow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;$img = rserve_start_plot(&#039;png&#039;)&amp;lt;/code&amp;gt;: sets up R to plot to a &#039;PNG&#039;&lt;br /&gt;
file and returns a unique plot identifier to be used later.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_eval(&#039;curve(...)&#039;)&amp;lt;/code&amp;gt;: runs plotting commands on the R server&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;$image_path = rserve_finish_plot($img)&amp;lt;/code&amp;gt;: completes the plotting&lt;br /&gt;
to the PNG file and transfers it to a location on the WebWork&lt;br /&gt;
server. Returns the path of the file, which is stored in Perl variable &amp;lt;code&amp;gt;$image_path&amp;lt;/code&amp;gt;&lt;br /&gt;
and later used as the first argument to the &amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt; macro.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;\{ image($image_path, width=&amp;gt;300, height=&amp;gt;300) \}&amp;lt;/code&amp;gt;: inserts the&lt;br /&gt;
image into the web page.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Transferring files from the R server ==&lt;br /&gt;
&lt;br /&gt;
Sometimes it may be convenient to make a file from R server available to the student via a link in Webwork. (For instance, using R to generate a (potentially randomized) data file that the student can download to work on the problem offline.) The macro &amp;lt;code&amp;gt;rserve_get_file REMOTE_NAME [, LOCAL_NAME]&amp;lt;/code&amp;gt; can be used to transfer the file &#039;&#039;REMOTE_NAME&#039;&#039; from the R server to WebWork&#039;s temporary&lt;br /&gt;
file area, and returns the name of the local file that can then be&lt;br /&gt;
used by the &amp;lt;code&amp;gt;htmlLink&amp;lt;/code&amp;gt; macro. Specifying &#039;&#039;LOCAL_NAME&#039;&#039; is optional; if it is not specified, the&lt;br /&gt;
filename portion of the &#039;&#039;REMOTE_NAME&#039;&#039; is used.&lt;br /&gt;
&lt;br /&gt;
The following code is a complete example&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
&lt;br /&gt;
loadMacros(&lt;br /&gt;
   &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
   &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
   &amp;quot;RserveClient.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Print problem number and point value (weight) for the problem&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
&lt;br /&gt;
#  Setup&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
my ($intercept, $slope) = rserve_eval(&#039;coef(lm(log(dist)~log(speed), data = cars))&#039;);&lt;br /&gt;
&lt;br /&gt;
my ($remote_file) = rserve_eval(&#039;filename &amp;lt;- tempfile(fileext=&amp;quot;.csv&amp;quot;); write.csv(cars, filename); filename&#039;);&lt;br /&gt;
my $local_file = rserve_get_file($remote_file);&lt;br /&gt;
&lt;br /&gt;
($local_url = $local_file) =~ s|$tempDirectory|$tempURL|;&lt;br /&gt;
&lt;br /&gt;
#  Text&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
&lt;br /&gt;
What is the slope of the linear regression of log-transformed stopping distance vs. car speed in the dataset linked below:&lt;br /&gt;
\{ ans_rule(5) \}&lt;br /&gt;
&lt;br /&gt;
$PAR&lt;br /&gt;
&lt;br /&gt;
\{ htmlLink($local_url, &amp;quot;Download&amp;quot;) \} the problem data (CSV file).&lt;br /&gt;
&lt;br /&gt;
END_TEXT&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
#  Answers&lt;br /&gt;
ANS(Real($slope)-&amp;gt;cmp);&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The four key lines are as follow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;my ($remote_file) = rserve_eval(&#039;filename &amp;lt;- tempfile(fileext=&amp;quot;.csv&amp;quot;); write.csv(cars, filename); filename&#039;)&amp;lt;/code&amp;gt;: stores the desired dataset into a temporary CSV file on the R server and returns its path, which is stored in Perl variable &amp;lt;code&amp;gt;$remote_file&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;my $local_file = rserve_get_file($remote_file)&amp;lt;/code&amp;gt;: transfers the file from the R server to WeBWorK&#039;s temporary file area and returns its path, which is stored in Perl variable &amp;lt;code&amp;gt;$local_file&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;($local_url = $local_file) =~ s|$tempDirectory|$tempURL|&amp;lt;/code&amp;gt;: converts the local file path into a URL that can be used as an argument to the &amp;lt;code&amp;gt;htmlLink&amp;lt;/code&amp;gt; macro, saving it in Perl variable &amp;lt;code&amp;gt;$local_url&amp;lt;/code&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;\{ htmlLink($local_url, &amp;quot;Download&amp;quot;) \}&amp;lt;/code&amp;gt;: inserts the&lt;br /&gt;
link to the downloaded file into the web page.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=315406</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Authoring guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide&amp;diff=315406"/>
		<updated>2014-08-28T17:16:26Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Fix page markup for better lists and code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== WeBWorKiR User Guide ==&lt;br /&gt;
&lt;br /&gt;
The audience for this guide are problem authors who want to use R&#039;s&lt;br /&gt;
facilities in their WeBWorK questions. We assume that you already know&lt;br /&gt;
how to create problems with the PG language (which itself is a subset&lt;br /&gt;
of Perl) and are familiar with the concepts of macros in PG. We also&lt;br /&gt;
assume that your WeBWorKiR environment has been set up as described in&lt;br /&gt;
the [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide|installation guide]].&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR is a system that involves two separate servers: WeBWorK and&lt;br /&gt;
R. In a normal operation, when a student accesses WeBWorK via a web&lt;br /&gt;
browser to work on homework problems, WeBWorK runs the PG code&lt;br /&gt;
defining the problem to compute:&lt;br /&gt;
&lt;br /&gt;
a) values used in the question, for example a random vector of five integers&lt;br /&gt;
&lt;br /&gt;
b) the text of the question, typically given in format resembling LaTeX and optionally displaying values computed in (a)&lt;br /&gt;
&lt;br /&gt;
c) values of the correct answer, for example, the mean of the vector calculated in (a)&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR adds to this the ability to run arbitrary computations in R&lt;br /&gt;
and make their results available to the rest of the PG code as if they&lt;br /&gt;
were constructed using the standard PG functions. (In our running&lt;br /&gt;
example, we could construct the random vector in R with `sample`,&lt;br /&gt;
and/or calculate its mean with `mean`.) The reason why one might want&lt;br /&gt;
to do this is R&#039;s rich library of high-quality statistical functions&lt;br /&gt;
as well as its graphical abilities. While in theory these could be&lt;br /&gt;
both replicated with PG, it would take a huge effort that can be&lt;br /&gt;
better spent by simply using the functionality already available in R.&lt;br /&gt;
&lt;br /&gt;
The way this works is that WeBWorK uses a Perl module that can talk to&lt;br /&gt;
a server running the [[http://www.rforge.net/Rserve/|Rserve]] software,&lt;br /&gt;
which allows remote clients to execute R code on the Rserve&#039;s server&lt;br /&gt;
and returns the execution&#039;s result in response. The Perl module&lt;br /&gt;
converts this response from R&#039;s native values (e.g., a generic vector,&lt;br /&gt;
aka &amp;quot;list&amp;quot;) to those understandable to Perl (e.g., an array), making&lt;br /&gt;
them available to the rest of the PG code.&lt;br /&gt;
&lt;br /&gt;
== Loading the macros ==&lt;br /&gt;
&lt;br /&gt;
To use R code in a problem, include &amp;quot;RserveClient.pl&amp;quot; in the&lt;br /&gt;
&amp;quot;loadMacros&amp;quot; call at the start of the question. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
loadMacros(&lt;br /&gt;
  &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
  &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
  &amp;quot;RserveClient.pl&amp;quot;    # &amp;lt;--- R integration&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Rserve macros ==&lt;br /&gt;
&lt;br /&gt;
The Rserve software creates an R session for each remote client. This&lt;br /&gt;
means that clients&#039; interactions with R are kept separate from each&lt;br /&gt;
other, just as if you started R twice on your local computer. A&lt;br /&gt;
session persists as long as the client is connected, so that multiple&lt;br /&gt;
calls from the client using the same session see the objects created&lt;br /&gt;
in previous calls. (This behaviour mirrors what happens in a local&lt;br /&gt;
session, where each R command you execute at the console after&lt;br /&gt;
pressing ENTER sees the results of earlier commands.) When a sessions&lt;br /&gt;
is *closed*, its contents are wiped off without a trace, just like&lt;br /&gt;
quitting the R application run locally.&lt;br /&gt;
&lt;br /&gt;
The RserveClient offers macros to start and finish a session, and&lt;br /&gt;
execute R commands in the current session:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_eval(&amp;quot;some R code&amp;quot;)&amp;lt;/code&amp;gt;: this function sends the R code given&lt;br /&gt;
as its string argument to Rserve for execution. It returns *an&lt;br /&gt;
array* representation of the R code&#039;s result. (This means that the&lt;br /&gt;
value of &amp;lt;code&amp;gt;rserve_eval(&amp;quot;pi&amp;quot;)&amp;lt;/code&amp;gt; is an array with a single element&lt;br /&gt;
3.14159265358979. If you want to keep this value and use it in the&lt;br /&gt;
rest of the problem, assign it to an array variable. For example:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;@pi = rserve_eval(&amp;quot;pi&amp;quot;);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; Multiple calls within the same problem share the R session and the object workspace, so you can break up your R code in as many &amp;lt;tt&amp;gt;rserve_eval&amp;lt;/tt&amp;gt; statements as you&#039;d like.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_start()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;rserve_finish()&amp;lt;/code&amp;gt;: Start up and close the current connection to the Rserve server. In&lt;br /&gt;
normal use, these functions are completely optional because the first&lt;br /&gt;
call to &amp;lt;code&amp;gt;rserve_eval&amp;lt;/code&amp;gt; will call start the Rserve session if one is not&lt;br /&gt;
already open. Similarly, the current session will be automatically closed at the end of the problem.&lt;br /&gt;
Other than backward compatibility, the only reason for using these&lt;br /&gt;
functions is to start a new clean session within a single problem,&lt;br /&gt;
which shouldn&#039;t be a common occurrence.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== A note on Perl quoting rules ===&lt;br /&gt;
&lt;br /&gt;
Beware of Perl&#039;s quoting rules when writing R code. The text in double&lt;br /&gt;
quotes gets interpreted for escape sequences (e.g., &amp;lt;code&amp;gt;&amp;quot;\n&amp;quot;&amp;lt;/code&amp;gt; represents a&lt;br /&gt;
newline) and variables (e.g., &amp;lt;code&amp;gt;&amp;quot;The value of pi is $pi[0]&amp;quot;&amp;lt;/code&amp;gt; will be&lt;br /&gt;
interpolated into &amp;lt;code&amp;gt;&amp;quot;The value of pi is 3.14159265358979&amp;quot;&amp;lt;/code&amp;gt;, given the&lt;br /&gt;
code above). This is a problem if you&#039;re trying to extract an element&lt;br /&gt;
of a list by name using the &amp;lt;code&amp;gt;&amp;quot;$&amp;quot;&amp;lt;/code&amp;gt; operator in R because the text&lt;br /&gt;
following it will be interpreted as a variable. For instance, running&lt;br /&gt;
&amp;lt;code&amp;gt;rserve_eval(&amp;quot;cars$speed&amp;quot;)&amp;lt;/code&amp;gt; will not return the &amp;quot;speed&amp;quot; column of the&lt;br /&gt;
standard &amp;quot;cars&amp;quot; dataset, because &amp;quot;$speed&amp;quot; in the string will be&lt;br /&gt;
replaced by the value of the PG variable &amp;lt;code&amp;gt;$speed&amp;lt;/code&amp;gt;, which if not yet&lt;br /&gt;
defined will be empty string, so that the R code that actually gets&lt;br /&gt;
executed is simply &amp;quot;cars&amp;quot;. Instead, using single quotes, which prevent&lt;br /&gt;
variable and escape sequence interpolation and instead keep the string&lt;br /&gt;
exactly as entered: &amp;lt;code&amp;gt;rserve_eval(&#039;cars$speed&#039;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
On the other hand, some time you actually might want variable&lt;br /&gt;
interpolation to be done, for instance to construct the R code that&lt;br /&gt;
uses values of variables constructed with PG functions. For instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$pi = Real(&amp;quot;pi&amp;quot;);&lt;br /&gt;
@difference = rserve_eval(&amp;quot;pi - $pi&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will calculate the difference between the value between R and PG&#039;s&lt;br /&gt;
values of &amp;quot;pi&amp;quot; and put the result in the &amp;lt;tt&amp;gt;@difference&amp;lt;/tt&amp;gt; array. Note that&lt;br /&gt;
the same R code can be constructed using Perl&#039;s string concatenation&lt;br /&gt;
operator dot (&amp;quot;.&amp;quot;): &amp;lt;tt&amp;gt;rserve_eval(&#039;pi - &#039; . $pi)&amp;lt;/tt&amp;gt;. Personally, I&lt;br /&gt;
recommend sticking with single quotes to prevent unwanted surprises,&lt;br /&gt;
and using the dot operator if needing to include the value of a PG&lt;br /&gt;
variable.&lt;br /&gt;
&lt;br /&gt;
== Displaying R graphics ==&lt;br /&gt;
&lt;br /&gt;
R has excellent facilities for creating production-quality statistical&lt;br /&gt;
graphics, from simple scatterplots to complex spatial visualizatons&lt;br /&gt;
overlaid on geographical maps. These graphics can be produced in a&lt;br /&gt;
variety of formats (in R parlance, devices), from the user&#039;s monitor&lt;br /&gt;
to PDF or JPG files. The RserveClient allows the author to present&lt;br /&gt;
these graphics in the question by bracketing the R graphing code with&lt;br /&gt;
macros &amp;lt;tt&amp;gt;rserve_start_plot&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;rserve_finish_plot&amp;lt;/tt&amp;gt;, and then showing&lt;br /&gt;
the produced image in the question with PG&#039;s macro &amp;lt;tt&amp;gt;image&amp;lt;/tt&amp;gt; (see the&lt;br /&gt;
WeBWorK [http://webwork.maa.org/wiki/Image documentation]).&lt;br /&gt;
&lt;br /&gt;
The following code is a complete example&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DOCUMENT();&lt;br /&gt;
&lt;br /&gt;
loadMacros(&lt;br /&gt;
   &amp;quot;PGstandard.pl&amp;quot;,     # Standard macros for PG language&lt;br /&gt;
   &amp;quot;MathObjects.pl&amp;quot;,&lt;br /&gt;
   &amp;quot;RserveClient.pl&amp;quot;,&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Print problem number and point value (weight) for the problem&lt;br /&gt;
TEXT(beginproblem());&lt;br /&gt;
&lt;br /&gt;
#  Setup&lt;br /&gt;
Context(&amp;quot;Numeric&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$mean = random(-2, 2, .5);&lt;br /&gt;
&lt;br /&gt;
$img = rserve_start_plot(&#039;png&#039;);&lt;br /&gt;
rserve_eval(&#039;curve(dnorm(x, mean=&#039; . $mean . &#039;), xlim=c(-4, 4)); 0&#039;);&lt;br /&gt;
$image_path = rserve_finish_plot($img);&lt;br /&gt;
&lt;br /&gt;
#  Text&lt;br /&gt;
Context()-&amp;gt;texStrings;&lt;br /&gt;
BEGIN_TEXT&lt;br /&gt;
&lt;br /&gt;
What is the mean of the normal distribution shown in the figure below:&lt;br /&gt;
\{ ans_rule(5) \}&lt;br /&gt;
&lt;br /&gt;
$PAR&lt;br /&gt;
&lt;br /&gt;
\{ image($image_path, width=&amp;gt;300, height=&amp;gt;300) \}:&lt;br /&gt;
END_TEXT&lt;br /&gt;
&lt;br /&gt;
Context()-&amp;gt;normalStrings;&lt;br /&gt;
&lt;br /&gt;
#  Answers&lt;br /&gt;
ANS(Real($mean)-&amp;gt;cmp);&lt;br /&gt;
&lt;br /&gt;
ENDDOCUMENT();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The four key lines are as follow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;$img = rserve_start_plot(&#039;png&#039;)&amp;lt;/code&amp;gt;: sets up R to plot to a &#039;PNG&#039;&lt;br /&gt;
file and returns a unique plot identifier to be used later.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;rserve_eval(&#039;curve(...)&#039;)&amp;lt;/code&amp;gt;: runs plotting commands on the R server&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;$image_path = rserve_finish_plot($img)&amp;lt;/code&amp;gt;: completes the plotting&lt;br /&gt;
to the PNG file and transfers it to a location on the WebWork&lt;br /&gt;
server. Returns the path of the file, which is stored in Perl variable &amp;lt;code&amp;gt;$image_path&amp;lt;/code&amp;gt;&lt;br /&gt;
and later used as the first argument to the &amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt; macro.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;&amp;lt;code&amp;gt;\{ image($image_path, width=&amp;gt;300, height=&amp;gt;300) \}&amp;lt;/code&amp;gt;: inserts the&lt;br /&gt;
image into the web page.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Transferring files from the R server ==&lt;br /&gt;
&lt;br /&gt;
Sometimes it may be convenient to make a file from R server available to the student via a link in Webwork. (For instance, using R to generate a (potentially randomized) data file that the student can download to work on the problem offline.) The macro &amp;lt;code&amp;gt;rserve_get_file REMOTE_NAME [, LOCAL_NAME]&amp;lt;/code&amp;gt; can be used to transfer the file &#039;&#039;REMOTE_NAME&#039;&#039; from the R server to WebWork&#039;s temporary&lt;br /&gt;
file area, and returns the name of the local file that can then be&lt;br /&gt;
used by the &amp;lt;code&amp;gt;htmlLink&amp;lt;/code&amp;gt; macro. Specifying &#039;&#039;LOCAL_NAME&#039;&#039; is optional; if it is not specified, the&lt;br /&gt;
filename portion of the &#039;&#039;REMOTE_NAME&#039;&#039; is used.&lt;br /&gt;
&lt;br /&gt;
[[Category:WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide&amp;diff=315401</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R/Installation guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide&amp;diff=315401"/>
		<updated>2014-08-28T17:07:55Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add category WeBWorK&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== WeBWorKiR Installation Guide ==&lt;br /&gt;
&lt;br /&gt;
The audience for this guide are system administrators who want to set&lt;br /&gt;
up R integration in WeBWorK. We assume that you already have, or know&lt;br /&gt;
how to set up, a basic WeBWorK server. If not, please see the&lt;br /&gt;
[http://webwork.maa.org/wiki/Release_notes_for_WeBWorK_2.8 release notes] on the WeBWorK wiki and the [http://webwork.maa.org/wiki/Installation_Manual_for_2.8_on_Ubuntu_12.04 guide] to installing WeBWorK on an Ubuntu server. You may also find&lt;br /&gt;
Jason Aubrey&#039;s [https://github.com/aubreyja/ww_install/ ww_install] installation script useful.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
After you have a working WeBWorK server, there are three distinct steps that need to happen:&lt;br /&gt;
&lt;br /&gt;
# set up the R server&lt;br /&gt;
# install the Perl module for the Perl-R bridge&lt;br /&gt;
# configure WeBWorK to use this module in PG&lt;br /&gt;
&lt;br /&gt;
=== Set up the R server ===&lt;br /&gt;
&lt;br /&gt;
Your R server (which can be on the same server as WeBWorK, but in a real-world scenario will more likely run on its own hardware/VM), is quite easy to set up:&lt;br /&gt;
&lt;br /&gt;
# install R following OS-specific instructions on the project [http://www.r-project.org homepage].&lt;br /&gt;
# install the [http://www.rforge.net/Rserve/ Rserve] server, which allows remote clients to execute R code on the Rserve&#039;s server and returns the execution&#039;s result in response. The easiest way is to run (as an administrative user) &amp;lt;code&amp;gt;Rscript -e &#039;install.packages(&amp;quot;Rserve&amp;quot;, repo=&amp;quot;http://cran.rstudio.com&amp;quot;)&#039;&amp;lt;/code&amp;gt;. Note that this package includes C source that needs to be compiled, so you have to have the basic developer tools present on the server.&lt;br /&gt;
# run the Rserve service as appropriate to your system. The command you need to run is &amp;quot;R CMD Rserve&amp;quot;. This will start the Rserve daemon which will listen on port 6311. The daemon only accepts connections from the localhost; if you run WebWork and Rserve on separate servers, read the final section of this page for additional configuration steps for your system.&lt;br /&gt;
&lt;br /&gt;
=== Install the Perl-R bridge ===&lt;br /&gt;
&lt;br /&gt;
Perl module [http://search.cpan.org/perldoc?Statistics::R::IO Statistics::R::IO] implements Rserve&#039;s communication protocol in Perl and provides translation from R data structures to Perl&#039;s. It is available on CPAN and can be installed in the standard manner for Perl modules, e.g., by running (as an admin user) &amp;lt;code&amp;gt;cpan Statistics::R::IO&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Configure Webwork to use the Perl-R bridge in PG ===&lt;br /&gt;
&lt;br /&gt;
Once the Perl module RserveClient is installed, you can make its functionality available in webwork problems by installing the RserveClient.pl macro and adding the module to the list of modules preloaded by WeBWorK. We use use &amp;quot;${WW_PREFIX}&amp;quot; to indicate the directory where WeBWorK is installed. (This directory will, for instance, contain subdirectories &amp;quot;webwork2&amp;quot; and &amp;quot;pg&amp;quot;; a typical choice is &amp;quot;/opt/webwork&amp;quot;, but a different one may be used on your system.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;install RserveClient.pl macro into &amp;quot;$WW_PREFIX/pg/macros&amp;quot;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget -q -O ${WW_PREFIX}/pg/macros/RserveClient.pl \&lt;br /&gt;
https://raw.githubusercontent.com/cubranic/Statistics-R-IO/release/extras/WebWork/RserveClient.pl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;perhaps a better solution, but depending on having the Perl module File::ShareDir, ensures that the RserveClient.pl macro matches the version of Statistics::R::IO that you have installed:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cp &amp;quot;`perl -MFile::ShareDir -e &#039;print File::ShareDir::dist_file(\&amp;quot;Statistics-R-IO\&amp;quot;, \&amp;quot;WebWork/RserveClient.pl\&amp;quot;)&#039;`&amp;quot; \&lt;br /&gt;
   ${WW_PREFIX}/pg/macros/RserveClient.pl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;add the RserveClient module(s) to the list of modules preloaded by&lt;br /&gt;
WeBWorK, so that it is available to the RserveClient.pl macro. You can&lt;br /&gt;
do this by modifying &amp;quot;${WW_PREFIX}/webwork2/conf/defaults.conf&amp;quot;,&lt;br /&gt;
but since it&#039;s a local configuration, you should put it in&lt;br /&gt;
localOverrides.conf:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat &amp;gt;&amp;gt; ${WW_PREFIX}/webwork2/conf/localOverrides.conf &amp;lt;&amp;lt;&#039;EOF&#039;&lt;br /&gt;
push @{$pg{modules}},&lt;br /&gt;
   [qw( Statistics::R::IO::Rserve )],&lt;br /&gt;
   [qw( Statistics::R::IO::ParserState )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Character )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Double )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Environment )],&lt;br /&gt;
   [qw( Statistics::R::REXP::GlobalEnvironment )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Integer )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Language )],&lt;br /&gt;
   [qw( Statistics::R::REXP::List )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Logical )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Null )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Raw )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Symbol )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Unknown )],&lt;br /&gt;
   [qw( Statistics::R::REXP::Vector )],&lt;br /&gt;
   [qw( Statistics::R::REXP )],&lt;br /&gt;
   [qw( IO::File )],&lt;br /&gt;
   [qw( IO::Handle )],&lt;br /&gt;
   [qw( Moose )],&lt;br /&gt;
   [qw( Class::MOP )];&lt;br /&gt;
1;&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional configuration when WeBWorK and R are on separate hosts ===&lt;br /&gt;
&lt;br /&gt;
If you run WeBWorK and R on separate hosts, you can either set up a tunnel to forward port 6311 from WeBWorK to R&#039;s host, or do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;set up Rserve to listen on all network interfaces, not just localhost by adding a line &amp;quot;remote enable&amp;quot; to file &amp;quot;/etc/Rserv.conf&amp;quot;:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cat &amp;lt;&#039;EOF&#039; &amp;gt;&amp;gt; /etc/Rserv.conf&lt;br /&gt;
remote enable&lt;br /&gt;
EOF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;modify RserveClient.pl with the correct Rserve&#039;s hostname in line &amp;lt;code&amp;gt;$Rserve_server = &#039;localhost&#039;;&amp;lt;/code&amp;gt; (line 98 in the current version).&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in this case you will also want to set up the Rserve host&#039;s firewall to only allow connections from the WeBWorK host(s), or otherwise it will happily execute arbitrary code from any Rserve client anywhere on the internet!&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
	<entry>
		<id>https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R&amp;diff=315400</id>
		<title>Sandbox:ARCHIVED: WeBWorK/The WeBWorKiR Project: Integrating WeBWorK with R</title>
		<link rel="alternate" type="text/html" href="https://wiki.ubc.ca/index.php?title=Sandbox:ARCHIVED:_WeBWorK/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R&amp;diff=315400"/>
		<updated>2014-08-28T17:07:20Z</updated>

		<summary type="html">&lt;p&gt;DavorCubranic: Add category WeBWorK&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Documentation:WeBWorK|WeBWorK]] is widely used in math courses&lt;br /&gt;
around the world, but its adoption in statistics has been limited. One&lt;br /&gt;
reason is that while WebWork implements a broad range of arithmetic&lt;br /&gt;
and calculus-type operations, it has little support for statistical&lt;br /&gt;
concepts such as probability distributions or statistical models.&lt;br /&gt;
&lt;br /&gt;
The WeBWorKiR (WeBWorK integrating R) project offers a solution in the&lt;br /&gt;
form of integration between WeBWorK and the&lt;br /&gt;
[http://www.r-project.org statistical computing software R]. The open&lt;br /&gt;
source software R is extremely popular in statistical research,&lt;br /&gt;
analysis, and education. It provides a huge range of operations for&lt;br /&gt;
statistical computation and graphics. The WeBWorKiR project has two&lt;br /&gt;
main goals: (i) to allow WeBWorK to communicate with R and (ii) the&lt;br /&gt;
creation of a large collection of homework questions for use in&lt;br /&gt;
undergraduate instruction in statistics. With the WeBWorKiR project,&lt;br /&gt;
instructors can use R code in their WebWorK problems to generate data,&lt;br /&gt;
perform analyses, and create figures.&lt;br /&gt;
&lt;br /&gt;
WeBWorKiR has been developed in the Department of Statistics since&lt;br /&gt;
June 2012, with the funding from Teaching and Learning Improvement&lt;br /&gt;
Fund. It has been used in a number of second- and third-year&lt;br /&gt;
Statistics courses at UBC, reaching around 3000 students so far. The&lt;br /&gt;
aim is that problems created and tested on students through the&lt;br /&gt;
WeBWorKiR project are made available to all educators via WeBWorK&#039;s&lt;br /&gt;
Open Problem Library.&lt;br /&gt;
&lt;br /&gt;
If you are an instructor, please look at the [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Authoring_guide|authoring]] guide for&lt;br /&gt;
information on writing WebWork questions that make use of R. If you&lt;br /&gt;
are a WebWork system administrator, you can find setup information in&lt;br /&gt;
our [[Documentation:WeBWork/The_WeBWorKiR_Project:_Integrating_WeBWorK_with_R/Installation_guide|installation guide]].&lt;br /&gt;
&lt;br /&gt;
[[Category: WeBWorK]]&lt;/div&gt;</summary>
		<author><name>DavorCubranic</name></author>
	</entry>
</feed>