Skip to content

Commit 753bf3e

Browse files
authored
Merge pull request #1359 from Alex-Jordan/rma-ptx
PTX stuff for parserRadioMultiAnswer
2 parents 6a0f76d + 08d2057 commit 753bf3e

1 file changed

Lines changed: 44 additions & 5 deletions

File tree

macros/parsers/parserRadioMultiAnswer.pl

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ =head1 DESCRIPTION
1616
$rma = RadioMultiAnswer([
1717
['The unique solution is \(x=\) %s and \(y=\) %s.', 5, 6],
1818
['There are an infinite number of solutions parameterized by '
19-
. '\(x=\) %s and \(y=\) %s.', '23-3t', 't']
19+
. '\(x=\) %s and \(y=\) %s.', '23-3x', 'x'],
2020
['There are no solutions.']
2121
], 0);
2222
@@ -233,6 +233,14 @@ =head1 OPTIONS
233233
234234
=back
235235
236+
=item showInStatic (Default: showInStatic => 1)
237+
238+
In static output, such as PDF or PTX, this controls whether or not the list of answer options is
239+
displayed. (The text preceding the list of answer options might make printing the answer option
240+
list unnecessary in a static output format.)
241+
242+
=back
243+
236244
=cut
237245

238246
BEGIN { strict->import }
@@ -288,6 +296,7 @@ sub new {
288296
size => undef,
289297
checked => undef,
290298
uncheckable => 0,
299+
showInStatic => 1,
291300
@inputs
292301
);
293302

@@ -593,6 +602,7 @@ sub ANS_NAME {
593602
# Produce the label for a part of the radio answer.
594603
sub label {
595604
my ($self, $i) = @_;
605+
$self->{originalLabels} //= $self->{labels};
596606
return $self->{labels}[$i] if ref($self->{labels}) eq 'ARRAY' && $#{ $self->{labels} } >= $i;
597607

598608
$self->{labels} = [ @main::ALPHABET[ 0 .. $#{ $self->{data} } ] ] if uc($self->{labels}) eq 'ABC';
@@ -638,6 +648,7 @@ sub generate_aria_label {
638648
# Produce the answer rule.
639649
sub ans_rule {
640650
my ($self, $size, @options) = @_;
651+
641652
$size ||= 20;
642653
my @data = @{ $self->{data} };
643654
my @rules;
@@ -705,18 +716,44 @@ sub ans_rule {
705716
push(@rules, $rule);
706717
}
707718

719+
return '' if !$self->{showInStatic} && ($main::displayMode eq 'TeX' || $main::displayMode eq 'PTX');
720+
721+
my $ptx_list_type = 'ul';
722+
my $ptx_sub_type = ' form="buttons"';
723+
if ($main::displayMode eq 'PTX') {
724+
# Do we want an ol, ul, or dl?
725+
if ($self->{displayLabels}) {
726+
my $originalLabels = $self->{originalLabels};
727+
if (ref $originalLabels eq 'ARRAY') {
728+
$ptx_list_type = 'dl';
729+
$ptx_sub_type = ' width = "narrow"';
730+
} elsif ($originalLabels =~ m/^(123|abc)$/i) {
731+
my $marker = '';
732+
$marker = '1' if $originalLabels eq '123';
733+
$marker = 'a' if $originalLabels eq 'abc';
734+
$marker = 'A' if uc($originalLabels) eq 'ABC' && $originalLabels ne 'abc';
735+
$ptx_list_type = 'ol';
736+
$ptx_sub_type = qq( marker="$marker");
737+
}
738+
}
739+
}
740+
708741
return main::MODES(
709742
TeX => '\\begin{itemize}',
710-
HTML => '<div class="radio-multianswer-container">'
743+
HTML => '<div class="radio-multianswer-container">',
744+
PTX => qq(<${ptx_list_type}${ptx_sub_type} name="$radio_name">)
711745
)
712-
. join(main::MODES(TeX => '\vskip\baselineskip', HTML => main::tag('div', style => 'margin-top:1rem')), @rules)
713-
. main::MODES(TeX => '\\end{itemize}', HTML => '</div>');
746+
. join(
747+
main::MODES(TeX => '\vskip\baselineskip', HTML => main::tag('div', style => 'margin-top:1rem'), PTX => ''),
748+
@rules
749+
) . main::MODES(TeX => '\\end{itemize}', HTML => '</div>', PTX => "</$ptx_list_type>");
714750
}
715751

716752
# Format a label.
717753
sub label_format {
718754
my ($self, $label) = @_;
719755
return '' unless $self->{displayLabels} && defined $label && $label ne '';
756+
return '<title>' . $self->quoteXML($label) . '</title>' if $main::displayMode eq 'PTX';
720757
return sprintf($self->{labelFormat}, main::MODES(TeX => $self->quoteTeX($label), HTML => $self->quoteHTML($label)));
721758
}
722759

@@ -734,6 +771,8 @@ sub begin_radio {
734771
if ($extend) { main::EXTEND_RESPONSE($name, $name, $value, $checked) }
735772
else { $name = main::RECORD_ANS_NAME($name, { $value => $checked }) }
736773

774+
return '' if !$self->{showInStatic} && ($main::displayMode eq 'TeX' || $main::displayMode eq 'PTX');
775+
737776
my $idSuffix = $extend ? "_$value" : '';
738777

739778
return main::MODES(
@@ -754,7 +793,7 @@ sub begin_radio {
754793
$checked ? (checked => undef) : ()
755794
)
756795
. main::tag('label', for => "$name$idSuffix", $tag),
757-
PTX => "<li>$tag",
796+
PTX => ref $self->{originalLabels} eq 'ARRAY' ? "<li>$tag" : '<li>',
758797
);
759798
}
760799

0 commit comments

Comments
 (0)