[LON-CAPA-cvs] cvs: loncom /homework matchresponse.pm optionresponse.pm
foxr
lon-capa-cvs-allow@mail.lon-capa.org
Thu, 05 Apr 2007 10:29:59 -0000
foxr Thu Apr 5 06:29:59 2007 EDT
Modified files:
/loncom/homework matchresponse.pm optionresponse.pm
Log:
bgz4657 - Make the bubble layout a bit more compact
so that if the user has chosen a left/right
positioning of the foil (2 columns) in 2 col printout
in exam mode for matchresponse, nothing will spill over
into the column gutter etc.
Index: loncom/homework/matchresponse.pm
diff -u loncom/homework/matchresponse.pm:1.61 loncom/homework/matchresponse.pm:1.62
--- loncom/homework/matchresponse.pm:1.61 Tue Mar 27 15:20:49 2007
+++ loncom/homework/matchresponse.pm Thu Apr 5 06:29:58 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Full matching style response
#
-# $Id: matchresponse.pm,v 1.61 2007/03/27 19:20:49 albertel Exp $
+# $Id: matchresponse.pm,v 1.62 2007/04/05 10:29:58 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -428,6 +428,8 @@
}
sub displayfoils {
my ($target,$max,$randomize)=@_;
+ my ($tabsize, $lefttabsize, $righttabsize);
+
my $result;
my $question;
my (@whichfoils)=&Apache::response::whichorder(&getfoilcounts($max),
@@ -493,6 +495,25 @@
$optionlist."</select>\n";
}
my $text=$Apache::response::foilgroup{$name.'.text'};
+ #
+ # Factor out the tex computations of the left/right 1/2 minipage
+ # widths for left or right positioning. This allows us
+ # to, if necessary constrain the bubble widths:
+ #
+ if ($target eq 'tex' &&
+ (&itemdisplay('left') || &itemdisplay('right'))) {
+ $tabsize=&Apache::londefdef::recalc($env{'form.textwidth'});
+ ($lefttabsize,$righttabsize)=(0,0);
+ if ($Apache::matchresponse::TeXitemgroupwidth ne '') {
+ $Apache::matchresponse::TeXitemgroupwidth=~/(\d*.?\d*)/;
+ $lefttabsize=$tabsize*$1/100;
+ $righttabsize=0.95*($tabsize-$lefttabsize);
+ } else {
+ $tabsize=~/(\d+\.?\d*)/;
+ $lefttabsize=$1/2.1;
+ $righttabsize=0.95*($1-$lefttabsize);
+ }
+ }
if ($target ne 'tex') {
if ($Apache::lonhomework::type ne 'exam') {
$question.="<br />\n".$optionlist.$text;
@@ -504,11 +525,24 @@
$question.=&Apache::optionresponse::webbubbles(\@used_letters,\@blank,$temp,$last_letter);
}
} else {
+ # Note that if left or right positioned, we must
+ # confine the bubbles to righttabsize:
+ #
if ($Apache::lonhomework::type eq 'exam') {
$question.=' '.$optionlist.$text."\n";
my @emptyItems = ();
for (my $i=0;$i<=$#used_letters;$i++) {push @emptyItems, ' ';}
- $question.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]'.&Apache::optionresponse::bubbles(\@used_letters,\@emptyItems).'\end{enumerate} \vskip -8 mm \strut ';
+ $question.='\vskip -1 mm\noindent\begin{list}{}{\setlength{\listparindent}{0mm}\setlength{\leftmargin}{2mm}}'
+ .'\item \hskip -3mm \textbf{'.$internal_counter.'}';
+ if (&itemdisplay('left') || &itemdisplay('right')) {
+ &Apache::lonnet::logthis("Constraining bubbles to $righttabsize - 10");
+ $question .= &Apache::optionresponse::bubbles(\@used_letters,\@emptyItems, "", $righttabsize);
+ }
+ else {
+ &Apache::lonnet::logthis("Not constraining bubbles");
+ $question .= &Apache::optionresponse::bubbles(\@used_letters,\@emptyItems);
+ }
+ $question .= '\end{list} \vskip -8 mm \strut ';
$internal_counter++;
} else {
$question.=' '.$optionlist.$text.'\strut\\\\\strut '."\n";
@@ -528,17 +562,6 @@
$result='<table><tr><td valign="top">'.$question.
'</td><td valign="top">'.$result.'</td></tr></table>';
} else {
- my $tabsize=&Apache::londefdef::recalc($env{'form.textwidth'});
- my ($lefttabsize,$righttabsize)=(0,0);
- if ($Apache::matchresponse::TeXitemgroupwidth ne '') {
- $Apache::matchresponse::TeXitemgroupwidth=~/(\d*.?\d*)/;
- $lefttabsize=$tabsize*$1/100;
- $righttabsize=0.95*($tabsize-$lefttabsize);
- } else {
- $tabsize=~/(\d+\.?\d*)/;
- $lefttabsize=$1/2.1;
- $righttabsize=0.95*($1-$lefttabsize);
- }
$lefttabsize.=' mm ';
$righttabsize.=' mm ';
$result='\setlength{\tabcolsep}{1 mm}\begin{tabular}{p{'.$righttabsize.'}p{'.$lefttabsize.'}}\begin{minipage}{'.$righttabsize.'}'.$question.'\end{minipage}&\begin{minipage}{'.$lefttabsize.'}'.$result.'\end{minipage}\end{tabular}';
@@ -550,17 +573,6 @@
$result='<table><tr><td valign="top">'.$result.
'</td><td valign="top">'.$question.'</td></tr></table>';
} else {
- my $tabsize=&Apache::londefdef::recalc($env{'form.textwidth'});
- my ($lefttabsize,$righttabsize)=(0,0);
- if ($Apache::matchresponse::TeXitemgroupwidth ne '') {
- $Apache::matchresponse::TeXitemgroupwidth=~/(\d*.?\d*)/;
- $lefttabsize=$tabsize*$1/100;
- $righttabsize=0.95*($tabsize-$lefttabsize);
- } else {
- $tabsize=~/(\d+\.?\d*)/;
- $lefttabsize=$1/2.1;
- $righttabsize=0.95*($1-$lefttabsize);
- }
$lefttabsize.=' mm ';
$righttabsize.=' mm ';
$result='\setlength{\tabcolsep}{1 mm}\begin{tabular}{p{'.$lefttabsize.'}p{'.$righttabsize.'}}\begin{minipage}{'.$lefttabsize.'}'.$result.'\end{minipage}&\begin{minipage}{'.$righttabsize.'}'.$question.'\end{minipage}\end{tabular}';
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.139 loncom/homework/optionresponse.pm:1.140
--- loncom/homework/optionresponse.pm:1.139 Tue Mar 27 15:20:49 2007
+++ loncom/homework/optionresponse.pm Thu Apr 5 06:29:58 2007
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: optionresponse.pm,v 1.139 2007/03/27 19:20:49 albertel Exp $
+# $Id: optionresponse.pm,v 1.140 2007/04/05 10:29:58 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -560,25 +560,33 @@
sub bubbles {
- my ($ralphabet,$ropt,$response) = @_;
+ my ($ralphabet,$ropt,$response, $max_width) = @_;
my @alphabet = @$ralphabet;
my @opt = @$ropt;
my ($result,$head,$line) =('','','');
my $number_of_bubbles = $#opt + 1;
my $current_length = 0;
my $textwidth;
- if ($env{'form.textwidth'} ne '') {
+ if ($max_width) {
+ $textwidth=$max_width;
+ &Apache::lonnet::logthis("Max width passed in: $max_width");
+ }
+ elsif ($env{'form.textwidth'} ne '') {
$env{'form.textwidth'}=~/(\d+)/;
$textwidth=$1;
+ &Apache::lonnet::logthis("Max width from form: $textwidth");
} else {
$env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
$textwidth=$1.'.'.$2;
+ &Apache::lonnet::logthis("Max width defaults? $textwidth");
}
+ &Apache::lonnet::logthis("Final maxwidth: $textwidth");
for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
my $leftmargin;
$opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
if ($response eq 'rankresponse') {$opt[$ind]='Rank '.$opt[$ind];}
if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
+
$current_length += (length($opt[$ind])+length($alphabet[$ind])+4)*2;
if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
$line.='\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';