Commit 828f3239 authored by Jojo Boulix's avatar Jojo Boulix
Browse files

New option for AMCnumericChoices: ignoreblank

parent a4536d38
......@@ -388,7 +388,11 @@ sub evaluate {
for my $vv ( keys %{ $self->{variables} } ) {
my $value = $self->get_variable($vv);
if ( defined($value) ) {
$string =~ s/\b$vv\b/$value/g;
if ( $value eq "" ) {
$string =~ s/\b$vv\b/''/g;
} else {
$string =~ s/\b$vv\b/$value/g;
}
} else {
$string =~ s/\b$vv\b/undef/g;
}
......
......@@ -1019,6 +1019,12 @@ Three digits and two letters:\insertgroup{mixed}.
% answer to be said \emph{approximative} and be rewarded to
% |scoreapprox| points (defaults to 0).
% \item[|scorewrong=|\meta{num}] gives the score for a wrong answer (defaults to 0).
% \item[|ignoreblank|] can be used (only with number base 10) to
% ignore digits for which no box has been ticked. This way,
% ticking 5 for the first digit, no box for the second and 3 for
% the third digit will code the number 53, while this would have
% coded 503 without the |ignoreblank| option (because the default
% value for the second digit is 0).
% \item[|keepas=|\meta{name}] keeps the value entered by the student
% in variable \marg{name}, for future use with \emph{alsocorrect}
% in another question.
......@@ -3863,6 +3869,9 @@ Three digits and two letters:\insertgroup{mixed}.
scoring .bool_set:N = \amc_num_scoring_bool,
scoring .initial:n = { true },
scoring .default:n = { true },
ignoreblank .bool_set:N = \amc_num_ignoreblank_bool,
ignoreblank .initial:n = { false },
ignoreblank .default:n = { true },
vertical .bool_set:N = \amc_num_vertical_bool,
vertical .initial:n = { false },
vertical .default:n = { true },
......@@ -3901,6 +3910,14 @@ Three digits and two letters:\insertgroup{mixed}.
\keys_set:nn { amcnumeric } { #1 }
}
\cs_new_nopar:Nn \amc_num_check_score_opts: {
\bool_if:NTF \amc_num_ignoreblank_bool {
\int_compare:nNnTF \amc_num_base_int = { 10 } { } {
\message{^^J!~Error:~ignoreblank~can~only~be~used~with~number~base~10^^J}
}
} {}
}
\cs_new_eq:NN \AMCnumericOpts \amc_num_setopts
% \end{macrocode}
......@@ -4132,6 +4149,7 @@ Three digits and two letters:\insertgroup{mixed}.
% \begin{macrocode}
\cs_new:Npn \amc_num_build_integer_scoring:Nnnn #1 #2 #3 #4 {
\amc_num_check_score_opts:
\tl_clear:N #1
\int_set_eq:NN \amc_num_digit_int { #4 }
\int_while_do:nNnn \amc_num_digit_int > 0 {
......@@ -4140,18 +4158,31 @@ Three digits and two letters:\insertgroup{mixed}.
\int_to_Alph:n \amc_num_digit_int = 1]^^J}
} {
\AMC@amclog{AUTOQCM[B=default. #3
\int_to_Alph:n \amc_num_digit_int = 0]^^J}
\int_to_Alph:n \amc_num_digit_int =
\bool_if:NTF \amc_num_ignoreblank_bool { } { 0 }
]^^J}
}
\int_compare:nNnTF \amc_num_digit_int = #4 { } {
\tl_put_left:Nn #1 { ( }
\tl_put_right:Nx #1 { ) *
\int_use:N \amc_num_base_int + }
\bool_if:NTF \amc_num_ignoreblank_bool {
\tl_put_right:Nx #1 { ~.~ }
\int_compare:nNnTF \amc_num_decd_int = \amc_num_digit_int {
\tl_put_right:Nx #1 { "." ~.~ }
} { }
} {
\tl_put_left:Nn #1 { ( }
\tl_put_right:Nx #1 { ) *
\int_use:N \amc_num_base_int + }
}
}
\tl_put_right:Nx #1
{ #3 \int_to_Alph:n \amc_num_digit_int }
\int_decr:N \amc_num_digit_int
}
\tl_put_left:Nn #1 { ( }
\bool_if:NTF \amc_num_ignoreblank_bool {
\tl_put_left:Nn #1 { 0 + ( }
\tl_put_right:Nn #1 { ) }
} { }
\tl_put_right:Nn #1 { ) }
\bool_if:NTF { #2 } {
\bool_if:NTF \amc_num_strict_bool {
......@@ -4282,10 +4313,18 @@ Three digits and two letters:\insertgroup{mixed}.
}{
\AMC@amclog{AUTOQCM[B= set.intX = intXX]^^J}
}
\int_compare:nNnTF \amc_num_expo_int > 0 {
\AMC@amclog{AUTOQCM[B= set.valueX = intXX * \int_use:N\amc_num_base_int ** (intE - \int_use:N\amc_num_decd_int)]^^J}
}{
\AMC@amclog{AUTOQCM[B= set.valueX = intXX * \int_use:N\amc_num_base_int ** (- \int_use:N\amc_num_decd_int) ]^^J}
\bool_if:NTF \amc_num_ignoreblank_bool {
\int_compare:nNnTF \amc_num_expo_int > 0 {
\AMC@amclog{AUTOQCM[B= set.valueX = intXX * \int_use:N\amc_num_base_int ** (intE)]^^J}
}{
\AMC@amclog{AUTOQCM[B= set.valueX = intXX]^^J}
}
} {
\int_compare:nNnTF \amc_num_expo_int > 0 {
\AMC@amclog{AUTOQCM[B= set.valueX = intXX * \int_use:N\amc_num_base_int ** (intE - \int_use:N\amc_num_decd_int)]^^J}
}{
\AMC@amclog{AUTOQCM[B= set.valueX = intXX * \int_use:N\amc_num_base_int ** (- \int_use:N\amc_num_decd_int) ]^^J}
}
}
\ifx\@empty\AMC@numeric@keepas\@empty\else
\AMC@amclog{AUTOQCM[B= setglobal.\AMC@numeric@keepas = valueX ]^^J}
......
......@@ -113,6 +113,7 @@ my $defaults = {
password_key => 'password',
setup => 1,
exitonerror => 1,
postinstall => '',
};
sub new {
......@@ -268,6 +269,10 @@ sub install {
print DB "Test\n";
close(DB);
if ( $self->{postinstall} ) {
&{ $self->{postinstall} }($self);
}
return $self;
}
......
\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[box,insidebox]{automultiplechoice}
\usepackage{multicol}
\begin{document}
\AMCnumericOpts{ignoreblank=true}
\onecopy{10}{
\noindent{\bf AMC \hfill TEST}
\vspace*{.5cm}
\begin{minipage}{.4\linewidth}
\centering\large\bf Test\\ ignoreblank\end{minipage}
\namefield{\fbox{
\begin{minipage}{.5\linewidth}
Name:
\vspace*{.5cm}\namefielddots
\vspace*{1mm}
\end{minipage}
}}
\vspace{1ex}
\begin{multicols}{2}
\begin{questionmultx}{integer}
Code 12
\AMCnumericChoices{12}{digits=3,sign=false}
\end{questionmultx}
\begin{questionmultx}{sign}
Code significant digits for 0.01022
\AMCnumericChoices{0.01022}{significant=true,digits=2}
\end{questionmultx}
\begin{questionmultx}{decimal}
Code 12.34
\AMCnumericChoices{12.34}{digits=8,decimals=4,sign=false}
\end{questionmultx}
\end{multicols}
\begin{questionmultx}{e}
Code -0.00123
\AMCnumericChoices{-0.00123}{digits=5,decimals=4,sign=true,exponent=2}
\end{questionmultx}
}
\end{document}
#! /usr/bin/env perl
#
# Copyright (C) 2021 Alexis Bienvenüe <paamc@passoire.fr>
#
# This file is part of Auto-Multiple-Choice
#
# Auto-Multiple-Choice is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# Auto-Multiple-Choice is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Auto-Multiple-Choice. If not, see
# <http://www.gnu.org/licenses/>.
require "./AMC/Test.pm";
my @args=@ARGV;
AMC::Test->new(
dir => __FILE__,
src => 'simple.tex',
tex_engine => 'pdflatex',
check_marks => { 1 => 20, 2 => 20 }
)->default_process;
@ARGV=@args;
AMC::Test->new(
dir => __FILE__,
src => 'simple.tex',
tex_engine => 'pdflatex',
postinstall => sub {
my ($self) = @_;
system( "env", "perl", "-pi", "-e", 's/.AMCnumericOpts/%/',
"$self->{temp_dir}/simple.tex" );
},
check_marks => { 1 => 5, 2 => 5 },
export_full_csv => [
{ -copy => 1, -question => 'sign', -score => 2 },
{ -copy => 2, -question => 'sign', -score => 2 }
],
)->default_process;
Supports Markdown
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