Skip to content

Commit c7754ab

Browse files
Alex-Jordandrgrice1
authored andcommitted
add showInStatic option to radio buttons and checkbox list
1 parent f7a8aed commit c7754ab

File tree

2 files changed

+64
-35
lines changed

2 files changed

+64
-35
lines changed

macros/parsers/parserCheckboxList.pl

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ =head1 DESCRIPTION
170170
index into the choice array or not. If set to 1, then the number is treated as
171171
the literal correct answer, not an index to it. Default: 0
172172
173+
=item C<S<< showInStatic => 0 or 1 >>>
174+
In static output, such as PDF or PTX, this controls whether or not
175+
the list of answer options is displayed. (The text preceding the list
176+
of answer options might make printing the answer option list
177+
unnecessary in a static output format.) Default: 1
178+
173179
=back
174180
175181
To insert the checkboxes into the problem text use
@@ -244,6 +250,7 @@ sub new {
244250
noindex => 0,
245251
checkedI => [],
246252
localLabels => 0,
253+
showInStatic => 1,
247254
@inputs
248255
);
249256
$options{originalLabels} = $options{labels};
@@ -570,37 +577,43 @@ sub CHECKS {
570577
}
571578

572579
if ($main::displayMode eq 'TeX') {
573-
$checks[0] = "\n\\begin{itemize}\n" . $checks[0];
574-
$checks[-1] .= "\n\\end{itemize}\n";
580+
if ($self->{showInStatic}) {
581+
$checks[0] = "\n\\begin{itemize}\n" . $checks[0];
582+
$checks[-1] .= "\n\\end{itemize}\n";
583+
} else {
584+
@checks = ();
585+
}
575586
} elsif ($main::displayMode eq 'PTX') {
587+
if ($self->{showInStatic}) {
588+
# Do we want an ol, ul, or dl?
589+
my $list_type = 'ul';
590+
my $subtype = '';
591+
my $originalLabels = $self->{originalLabels};
592+
if ($originalLabels =~ m/^(123|abc|roman)$/i) {
593+
my $marker = '';
594+
$marker = "1" if $originalLabels eq '123';
595+
$marker = "a" if $originalLabels eq 'abc';
596+
$marker = "A" if uc($originalLabels) eq 'ABC' && $originalLabels ne 'abc';
597+
$marker = "i" if $originalLabels eq 'roman';
598+
$marker = "I" if uc($originalLabels) eq 'ROMAN' && $originalLabels ne 'roman';
599+
600+
$list_type = 'ol';
601+
$subtype = qq( marker="$marker");
602+
} elsif ($self->{localLabels} || ref $originalLabels eq 'ARRAY') {
603+
$list_type = 'dl';
604+
$subtype = ' width = "narrow"';
605+
my %checks_to_labels = map { $checks[$_] => $self->{labels}[$_] } (0 .. $#{ $self->{orderedChoices} });
606+
map { $_ =~ s/^(<li.*?>)/$1<title>$checks_to_labels{$_}<\/title>/gr } @checks;
607+
}
608+
$checks[0] = qq{<$list_type$subtype name="$name">\n$checks[0]};
609+
$checks[-1] .= "</$list_type>";
576610

577-
# Do we want an ol, ul, or dl?
578-
my $list_type = 'ul';
579-
my $subtype = '';
580-
my $originalLabels = $self->{originalLabels};
581-
if ($originalLabels =~ m/^(123|abc|roman)$/i) {
582-
my $marker = '';
583-
$marker = "1" if $originalLabels eq '123';
584-
$marker = "a" if $originalLabels eq 'abc';
585-
$marker = "A" if uc($originalLabels) eq 'ABC' && $originalLabels ne 'abc';
586-
$marker = "i" if $originalLabels eq 'roman';
587-
$marker = "I" if uc($originalLabels) eq 'ROMAN' && $originalLabels ne 'roman';
588-
589-
$list_type = 'ol';
590-
$subtype = qq( marker="$marker");
591-
$close_list = 'ol';
592-
} elsif ($self->{localLabels} || ref $originalLabels eq 'ARRAY') {
593-
$list_type = 'dl';
594-
$subtype = ' width = "narrow"';
595-
my %checks_to_labels = map { $checks[$_] => $self->{labels}[$_] } (0 .. $#{ $self->{orderedChoices} });
596-
map { $_ =~ s/^(<li.*?>)/$1<title>$checks_to_labels{$_}<\/title>/gr } @checks;
611+
# Change math delimiters
612+
@checks = map { $_ =~ s/\\\(/<m>/gr } @checks;
613+
@checks = map { $_ =~ s/\\\)/<\/m>/gr } @checks;
614+
} else {
615+
@checks = ();
597616
}
598-
$checks[0] = qq{<$list_type$subtype name="$name">\n$checks[0]};
599-
$checks[-1] .= "</$list_type>";
600-
601-
# Change math delimiters
602-
@checks = map { $_ =~ s/\\\(/<m>/gr } @checks;
603-
@checks = map { $_ =~ s/\\\)/<\/m>/gr } @checks;
604617
} else {
605618
$checks[0] =
606619
qq{<div class="checkboxes-container" }

macros/parsers/parserRadioButtons.pl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ =head1 DESCRIPTION
180180
then the number is treated as the literal correct answer, not an index
181181
to it. Default: 0
182182
183+
=item C<S<< showInStatic => 0 or 1 >>>
184+
185+
In static output, such as PDF or PTX, this controls whether or not
186+
the list of answer options is displayed. (The text preceding the list
187+
of answer options might make printing the answer option list
188+
unnecessary in a static output format.) Default: 1
189+
183190
=back
184191
185192
The following options are deprecated, but are available for backward
@@ -294,6 +301,7 @@ sub new {
294301
last => undef,
295302
order => undef,
296303
noindex => 0,
304+
showInStatic => 1,
297305
@_,
298306
checkedI => -1,
299307
);
@@ -663,14 +671,22 @@ sub BUTTONS {
663671
# It is wrong to have \item in the radio buttons and to add itemize here,
664672
# but that is the way PGbasicmacros.pl does it.
665673
if ($main::displayMode eq 'TeX') {
666-
$radio[0] = "\n\\begin{itemize}\n" . $radio[0];
667-
$radio[-1] .= "\n\\end{itemize}\n";
674+
if ($self->{showInStatic}) {
675+
$radio[0] = "\n\\begin{itemize}\n" . $radio[0];
676+
$radio[-1] .= "\n\\end{itemize}\n";
677+
} else {
678+
@radio = ();
679+
}
668680
} elsif ($main::displayMode eq 'PTX') {
669-
$radio[0] = qq(<ul name="$name">) . "\n" . $radio[0];
670-
$radio[-1] .= '</ul>';
671-
#turn any math delimiters
672-
@radio = map { $_ =~ s/\\\(/<m>/g; $_ } (@radio);
673-
@radio = map { $_ =~ s/\\\)/<\/m>/g; $_ } (@radio);
681+
if ($self->{showInStatic}) {
682+
$radio[0] = qq(<ul name="$name">) . "\n" . $radio[0];
683+
$radio[-1] .= '</ul>';
684+
#turn any math delimiters
685+
@radio = map { $_ =~ s/\\\(/<m>/g; $_ } (@radio);
686+
@radio = map { $_ =~ s/\\\)/<\/m>/g; $_ } (@radio);
687+
} else {
688+
@radio = ();
689+
}
674690
} else {
675691
$radio[0] =
676692
qq{<div class="radio-buttons-container" }

0 commit comments

Comments
 (0)