From: dpvc v. a. <we...@ma...> - 2007-09-19 12:05:05
|
Log Message: ----------- Handle TeX special characters better when used as the currency symbol. (Quote them when displayMode is TeX.) Modified Files: -------------- pg/macros: contextCurrency.pl Revision Data ------------- Index: contextCurrency.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextCurrency.pl,v retrieving revision 1.6 retrieving revision 1.7 diff -Lmacros/contextCurrency.pl -Lmacros/contextCurrency.pl -u -r1.6 -r1.7 --- macros/contextCurrency.pl +++ macros/contextCurrency.pl @@ -198,11 +198,6 @@ $context->{_currency}{symbol} = $symbol; $context->{parser}{Number} = "Currency::Number"; $context->{value}{Currency} = "Currency::Currency"; - $context->operators->remove($symbol) if $context->operators->get($symbol); - $context->operators->add( - $symbol => {precedence => 10, associativity => $associativity, type => "unary", string => $symbol, - TeX => Currency::quoteTeX($symbol), class => 'Currency::UOP::currency'}, - ); $context->flags->set( tolerance => .005, tolType => "absolute", @@ -293,7 +288,8 @@ $operators->add( $symbol => { %{$def}, associativity => $associativity, - string => $string, TeX => Currency::quoteTeX($string), + string => ($main::qisplayMode eq 'TeX' ? Currency::quoteTeX($string) : $string), + TeX => Currency::quoteTeX($string), } ); } @@ -329,7 +325,8 @@ my $string = ($data->{symbol} =~ m/[^a-z]/i ? $data->{symbol} : " $data->{symbol} "); $context->operators->set($data->{symbol}=>{ associativity => $data->{associativity}, - string => $string, tex => Currency::quoteTeX($string), + string => ($main::displayMode eq 'TeX' ? Currency::quoteTeX($string) : $string), + TeX => Currency::quoteTeX($string), }); $context->update; } @@ -449,11 +446,11 @@ # on the correct end for the associativity and remove leading # and trailing spaces. # -sub string { - my $self = shift; +sub format { + my $self = shift; my $type = shift; my $currency = ($self->{currency} || $self->context->{currency}); my ($symbol,$comma,$decimal) = ($currency->{symbol},$currency->{comma},$currency->{decimal}); - $symbol = $self->context->operators->get($symbol)->{string} || $symbol; + $symbol = $self->context->operators->get($symbol)->{$type} || $symbol; my $s = main::prfmt($self->value,"%.2f"); $s =~ s/\./$decimal/; while ($s =~ s/(\d)(\d\d\d\D)/$1$comma$2/) {} @@ -462,13 +459,10 @@ return $s; } -# -# Just use the string and escape any TeX specials -# -sub TeX { - my $self = shift; - return Currency::quoteTeX($self->string(@_)); -} +sub string {(shift)->format("string")} +sub TeX {(shift)->format("TeX")} + + # # Override the class name to get better error messages |