Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add showInStatic option to radio buttons #1084

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 41 additions & 28 deletions macros/parsers/parserCheckboxList.pl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ =head1 DESCRIPTION
index into the choice array or not. If set to 1, then the number is treated as
the literal correct answer, not an index to it. Default: 0

=item C<S<< showInStatic => 0 or 1 >>>
In static output, such as PDF or PTX, this controls whether or not
the list of answer options is displayed. (The text preceding the list
of answer options might make printing the answer option list
unnecessary in a static output format.) Default: 1

=back

To insert the checkboxes into the problem text use
Expand Down Expand Up @@ -244,6 +250,7 @@ sub new {
noindex => 0,
checkedI => [],
localLabels => 0,
showInStatic => 1,
@inputs
);
$options{originalLabels} = $options{labels};
Expand Down Expand Up @@ -570,37 +577,43 @@ sub CHECKS {
}

if ($main::displayMode eq 'TeX') {
$checks[0] = "\n\\begin{itemize}\n" . $checks[0];
$checks[-1] .= "\n\\end{itemize}\n";
if ($self->{showInStatic}) {
$checks[0] = "\n\\begin{itemize}\n" . $checks[0];
$checks[-1] .= "\n\\end{itemize}\n";
} else {
@checks = ();
}
} elsif ($main::displayMode eq 'PTX') {
if ($self->{showInStatic}) {
# Do we want an ol, ul, or dl?
my $list_type = 'ul';
my $subtype = '';
my $originalLabels = $self->{originalLabels};
if ($originalLabels =~ m/^(123|abc|roman)$/i) {
my $marker = '';
$marker = "1" if $originalLabels eq '123';
$marker = "a" if $originalLabels eq 'abc';
$marker = "A" if uc($originalLabels) eq 'ABC' && $originalLabels ne 'abc';
$marker = "i" if $originalLabels eq 'roman';
$marker = "I" if uc($originalLabels) eq 'ROMAN' && $originalLabels ne 'roman';

$list_type = 'ol';
$subtype = qq( marker="$marker");
} elsif ($self->{localLabels} || ref $originalLabels eq 'ARRAY') {
$list_type = 'dl';
$subtype = ' width = "narrow"';
my %checks_to_labels = map { $checks[$_] => $self->{labels}[$_] } (0 .. $#{ $self->{orderedChoices} });
map { $_ =~ s/^(<li.*?>)/$1<title>$checks_to_labels{$_}<\/title>/gr } @checks;
}
$checks[0] = qq{<$list_type$subtype name="$name">\n$checks[0]};
$checks[-1] .= "</$list_type>";

# Do we want an ol, ul, or dl?
my $list_type = 'ul';
my $subtype = '';
my $originalLabels = $self->{originalLabels};
if ($originalLabels =~ m/^(123|abc|roman)$/i) {
my $marker = '';
$marker = "1" if $originalLabels eq '123';
$marker = "a" if $originalLabels eq 'abc';
$marker = "A" if uc($originalLabels) eq 'ABC' && $originalLabels ne 'abc';
$marker = "i" if $originalLabels eq 'roman';
$marker = "I" if uc($originalLabels) eq 'ROMAN' && $originalLabels ne 'roman';

$list_type = 'ol';
$subtype = qq( marker="$marker");
$close_list = 'ol';
} elsif ($self->{localLabels} || ref $originalLabels eq 'ARRAY') {
$list_type = 'dl';
$subtype = ' width = "narrow"';
my %checks_to_labels = map { $checks[$_] => $self->{labels}[$_] } (0 .. $#{ $self->{orderedChoices} });
map { $_ =~ s/^(<li.*?>)/$1<title>$checks_to_labels{$_}<\/title>/gr } @checks;
# Change math delimiters
@checks = map { $_ =~ s/\\\(/<m>/gr } @checks;
@checks = map { $_ =~ s/\\\)/<\/m>/gr } @checks;
} else {
@checks = ();
}
$checks[0] = qq{<$list_type$subtype name="$name">\n$checks[0]};
$checks[-1] .= "</$list_type>";

# Change math delimiters
@checks = map { $_ =~ s/\\\(/<m>/gr } @checks;
@checks = map { $_ =~ s/\\\)/<\/m>/gr } @checks;
} else {
$checks[0] =
qq{<div class="checkboxes-container" }
Expand Down
30 changes: 23 additions & 7 deletions macros/parsers/parserRadioButtons.pl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ =head1 DESCRIPTION
then the number is treated as the literal correct answer, not an index
to it. Default: 0

=item C<S<< showInStatic => 0 or 1 >>>

In static output, such as PDF or PTX, this controls whether or not
the list of answer options is displayed. (The text preceding the list
of answer options might make printing the answer option list
unnecessary in a static output format.) Default: 1

=back

The following options are deprecated, but are available for backward
Expand Down Expand Up @@ -294,6 +301,7 @@ sub new {
last => undef,
order => undef,
noindex => 0,
showInStatic => 1,
@_,
checkedI => -1,
);
Expand Down Expand Up @@ -663,14 +671,22 @@ sub BUTTONS {
# It is wrong to have \item in the radio buttons and to add itemize here,
# but that is the way PGbasicmacros.pl does it.
if ($main::displayMode eq 'TeX') {
$radio[0] = "\n\\begin{itemize}\n" . $radio[0];
$radio[-1] .= "\n\\end{itemize}\n";
if ($self->{showInStatic}) {
$radio[0] = "\n\\begin{itemize}\n" . $radio[0];
$radio[-1] .= "\n\\end{itemize}\n";
} else {
@radio = ();
}
} elsif ($main::displayMode eq 'PTX') {
$radio[0] = qq(<ul name="$name">) . "\n" . $radio[0];
$radio[-1] .= '</ul>';
#turn any math delimiters
@radio = map { $_ =~ s/\\\(/<m>/g; $_ } (@radio);
@radio = map { $_ =~ s/\\\)/<\/m>/g; $_ } (@radio);
if ($self->{showInStatic}) {
$radio[0] = qq(<ul name="$name">) . "\n" . $radio[0];
$radio[-1] .= '</ul>';
#turn any math delimiters
@radio = map { $_ =~ s/\\\(/<m>/g; $_ } (@radio);
@radio = map { $_ =~ s/\\\)/<\/m>/g; $_ } (@radio);
} else {
@radio = ();
}
} else {
$radio[0] =
qq{<div class="radio-buttons-container" }
Expand Down