Commit 8742ba76 by ichuang

improved latex problem template; hls codemirror box autosizes height;

capa responsetypes can now include "inline='1'" for their span to be inline
parent 12869ece
...@@ -45,6 +45,9 @@ ...@@ -45,6 +45,9 @@
refresh_hls(el); refresh_hls(el);
$(this).dequeue(); $(this).dequeue();
}); });
// resize the codemirror box
h = el.height();
el.find('.CodeMirror-scroll').height(h-100);
} }
// compile & save button // compile & save button
......
...@@ -63,7 +63,7 @@ class StudentInputError(Exception): ...@@ -63,7 +63,7 @@ class StudentInputError(Exception):
class LoncapaResponse(object): class LoncapaResponse(object):
''' """
Base class for CAPA responsetypes. Each response type (ie a capa question, Base class for CAPA responsetypes. Each response type (ie a capa question,
which is part of a capa problem) is represented as a subclass, which is part of a capa problem) is represented as a subclass,
which should provide the following methods: which should provide the following methods:
...@@ -89,7 +89,7 @@ class LoncapaResponse(object): ...@@ -89,7 +89,7 @@ class LoncapaResponse(object):
- required_attributes : list of required attributes (each a string) on the main response XML stanza - required_attributes : list of required attributes (each a string) on the main response XML stanza
- hint_tag : xhtml tag identifying hint associated with this response inside hintgroup - hint_tag : xhtml tag identifying hint associated with this response inside hintgroup
''' """
__metaclass__ = abc.ABCMeta # abc = Abstract Base Class __metaclass__ = abc.ABCMeta # abc = Abstract Base Class
response_tag = None response_tag = None
...@@ -164,6 +164,8 @@ class LoncapaResponse(object): ...@@ -164,6 +164,8 @@ class LoncapaResponse(object):
- renderer : procedure which produces HTML given an ElementTree - renderer : procedure which produces HTML given an ElementTree
''' '''
tree = etree.Element('span') # render ourself as a <span> + our content tree = etree.Element('span') # render ourself as a <span> + our content
if self.xml.get('inline',''): # problem author can make this span display:inline
tree.set('class','inline')
for item in self.xml: for item in self.xml:
item_xhtml = renderer(item) # call provided procedure to do the rendering item_xhtml = renderer(item) # call provided procedure to do the rendering
if item_xhtml is not None: tree.append(item_xhtml) if item_xhtml is not None: tree.append(item_xhtml)
......
...@@ -3,25 +3,146 @@ metadata: ...@@ -3,25 +3,146 @@ metadata:
display_name: Problem Written in LaTeX display_name: Problem Written in LaTeX
source_processor_url: https://qisx.mit.edu:5443/latex2edx source_processor_url: https://qisx.mit.edu:5443/latex2edx
source_code: | source_code: |
\subsection{Example: Option Response Problem in Latex} % Nearly any kind of edX problem can be authored using Latex as
% the source language. Write latex as usual, including equations. The
% key new feature is the \edXabox{} macro, which specifies an "Answer
% Box" that queries students for a response, and specifies what the
% epxected (correct) answer is.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Example "option" problem}
Where is the earth? Where is the earth?
\edXabox{options='up','down' expect='down'} \edXabox{options='up','down' expect='down'}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Example "symbolic" problem}
What is Einstein's equation for the energy equivalent of a mass $m$?
\edXabox{type='symbolic' size='90' expect='m*c^2' }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Example "numerical" problem}
Estimate the energy savings (in J/y) if all the people
($3\times 10^8$) in the U.~S. switched from U.~S. code to low flow
shower heads.
\edXinline{Energy saved = }\edXabox{expect="0.52" type="numerical" tolerance='0.02' inline='1' } %
\edXinline{~EJ/year}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Example "multiple choice" problem}
What color is a bannana?
\edXabox{ type="multichoice" expect="Yellow" options="Red","Green","Yellow","Blue" }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Example "string response" problem}
In what U.S. state is Detroit located?
\edXabox{ type="string" expect="Michigan" options="ci" }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Example "custom response" problem}
This problem demonstrates the use of a custom python script used for
checking the answer.
\begin{edXscript}
def sumtest(expect,ans):
(a1,a2) = map(float,eval(ans))
return (a1+a2)==10
\end{edXscript}
Enter a python list of two numbers which sum to 10, eg [9,1]:
\edXabox{expect="[1,9]" type="custom" cfn="sumtest"}
data: | data: |
<problem> <?xml version="1.0"?>
<text> <problem>
<h2>Example: Option Response Problem</h2> <text>
<p> <p>
An option response problem presents option boxes for students to select from. Correctness of input is evaluated based <h4>Example "option" problem</h4>
on which option is defined as correct in the optioninput statement. </p>
</p> <p>
<p>Select the correct options:</p> Where is the earth? </p>
<optionresponse direction="vertical" randomize="yes"> <p>
<p><text class="inline">The location of the sky is: </text><optioninput inline="1" options="('Up','Down')" correct="Up"></optioninput></p> <optionresponse>
<p><text>The location of the earth is: </text><optioninput options="('Up','Down')" correct="Down"></optioninput></p> <optioninput options="('up','down')" correct="down"/>
</optionresponse> </optionresponse>
</text> </p>
</problem> <p>
<h4>Example "symbolic" problem</h4>
</p>
<p>
What is Einstein's equation for the energy equivalent of a mass [mathjaxinline]m[/mathjaxinline]? </p>
<p>
<symbolicresponse expect="m*c^2">
<textline size="90" correct_answer="m*c^2" math="1"/>
</symbolicresponse>
</p>
<p>
<h4>Example "numerical" problem</h4>
</p>
<p>
Estimate the energy savings (in J/y) if all the people ([mathjaxinline]3\times 10^8[/mathjaxinline]) in the U.&#xA0;S. switched from U.&#xA0;S. code to low flow shower heads. </p>
<p>
<p style="display:inline">Energy saved = </p>
<numericalresponse answer="0.52">
<textline inline="1">
<responseparam description="Numerical Tolerance" type="tolerance" default="0.02" name="tol"/>
</textline>
</numericalresponse>
<p style="display:inline">&#xA0;EJ/year</p>
</p>
<p>
<h4>Example "multiple choice" problem</h4>
</p>
<p>
What color is a bannana? </p>
<p>
<multiplechoiceresponse>
<choicegroup direction="vertical">
<choice correct="false" name="1">&lt;span&gt; Red&lt;/span&gt;</choice>
<choice correct="false" name="2">&lt;span&gt; Green&lt;/span&gt;</choice>
<choice correct="true" name="3">&lt;span&gt; Yellow&lt;/span&gt;</choice>
<choice correct="false" name="4">&lt;span&gt; Blue&lt;/span&gt;</choice>
</choicegroup>
</multiplechoiceresponse>
</p>
<p>
<h4>Example "string response" problem</h4>
</p>
<p>
In what U.S. state is Detroit located? </p>
<p>
<stringresponse answer="Michigan">
<textline/>
</stringresponse>
</p>
<p>
<h4>Example "custom response" problem</h4>
</p>
<p>
This problem demonstrates the use of a custom python script used for checking the answer. </p>
<script type="text/python" system_path="python_lib">
def sumtest(expect,ans):
(a1,a2) = map(float,eval(ans))
return (a1+a2)==10
</script>
<p>
Enter a python list of two numbers which sum to 10, eg [9,1]: </p>
<p>
<customresponse cfn="sumtest" expect="[1,9]">
<textline correct_answer="[1,9]"/>
</customresponse>
</p>
</text>
</problem>
children: [] children: []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment