Log Message:
-----------
Added a final_period=>1 flag for PiecewiseFunction objects so that the
final condition will include a period (so that you can put a piecewise
function as the last thing in a sentence).
Modified Files:
--------------
pg/macros:
contextPiecewiseFunction.pl
Revision Data
-------------
Index: contextPiecewiseFunction.pl
===================================================================
RCS file: /webwork/cvs/system/pg/macros/contextPiecewiseFunction.pl,v
retrieving revision 1.9
retrieving revision 1.10
diff -Lmacros/contextPiecewiseFunction.pl -Lmacros/contextPiecewiseFunction.pl -u -r1.9 -r1.10
--- macros/contextPiecewiseFunction.pl
+++ macros/contextPiecewiseFunction.pl
@@ -64,12 +64,25 @@
Context()->texStrings;
BEGIN_TEXT
- Suppose \(f(x)=$f\). Then \(f($a)\) = \{ans_rule(20)\}.
+ If \[f(x)=$f\] then \(f($a)\) = \{ans_rule(20)\}.
END_TEXT
Context()->normalStrings;
ANS($f->eval(x=>$a)->cmp);
+Normally when you use a piecewise function at the end of a sentence,
+the period is placed at the end of the last case. Since
+
+ \[ f(x) = $f \].
+
+would put the period centered at the right-hand side of the function,
+this is not what is desired. To get a period at the end of the last
+case, use
+
+ \[ f(x) = \{$f->with(final_period=>1)\} \]
+
+instead.
+
=cut
loadMacros("MathObjects.pl");
@@ -741,12 +754,13 @@
#
sub string {
my $self = shift; my @cases = ();
+ my $period = ($self->{final_period} ? "." : "");
foreach my $If (@{$self->{data}}) {
my ($I,$f) = @{$If};
push(@cases,$f->string." if ".$I->string);
}
push(@cases,$self->{otherwise}->string) if defined $self->{otherwise};
- join(" else\n",@cases);
+ join(" else\n",@cases) . $period;
}
#
@@ -754,13 +768,14 @@
#
sub TeX {
my $self = shift; my @cases = ();
+ my $period = ($self->{final_period} ? "." : "");
foreach my $If (@{$self->{data}}) {
my ($I,$f) = @{$If};
push(@cases,'\displaystyle{'.$f->TeX."}&\\text{if}\\ ".$I->TeX);
}
if (scalar(@cases)) {
push(@cases,'\displaystyle{'.$self->{otherwise}->TeX.'}&\text{otherwise}') if defined $self->{otherwise};
- return '\begin{cases}'.join('\cr'."\n",@cases).'\end{cases}';
+ return '\begin{cases}'.join('\cr'."\n",@cases).$period.'\end{cases}';
} else {
return $self->{otherwise}->TeX;
}
|