blib/lib/Math/Symbolic/Custom/LaTeXDumper.pm

filter: Statementstmt 74.0% 94 / 127 Branchbran 53.2% 33 / 62 Conditioncond 52.7% 29 / 55 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 50.0% 18 / 36 Podpod 100% 1 / 1 totaltotal 57.1% 175 / 306 CC 52 SCAR 27.8
CC
52
Cov
64%
__ANON__
40.7
__ANON__
20.0
to_latex
16.4
CRAP 16.1
↑ Summary
1  
2 =encoding utf8
3  
4 =head1 NAME
5  
6 Math::Symbolic::Custom::LaTeXDumper - Math::Symbolic LaTeX output
7  
8 =head1 SYNOPSIS
9  
10 use Math::Symbolic qw/parse_from_string/;
11 use Math::Symbolic::Custom::LaTeXDumper;
12 $term = parse_from_string(...);
13 print $term->to_latex(...);
14  
15 =head1 DESCRIPTION
16  
17 This class provides the C<to_latex()> method for all L<Math::Symbolic>
18 trees. It is a rewrite of the C<to_latex()> method that was supplied by
19 C<Math::Symbolic> prior to version 0.201.
20  
21 For details on how the custom method delegation model works, please have
22 a look at the C<Math::Symbolic::Custom> and C<Math::Symbolic::Custom::Base>
23 classes.
24  
25 =head2 EXPORT
26  
27 Please see the docs for C<Math::Symbolic::Custom::Base> for details, but
28 you should not try to use the standard Exporter semantics with this
29 class.
30  
31 =head1 SUBROUTINES
32  
33 =cut
34  
35 package Math::Symbolic::Custom::LaTeXDumper;
36  
37 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 2 our $VERSION = '0.208';
43  
44 2 ▶use Math::Symbolic::Custom::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 2 ▶BEGIN { *import = \&Math::Symbolic::Custom::Base::aggregate_import }
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 2 ▶use Math::Symbolic::ExportConstants qw/:all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 # Class Data: Special variable required by Math::Symbolic::Custom
52 # importing/exporting functionality.
53 # All subroutines that are to be exported to the Math::Symbolic::Custom
54 # namespace should be listed here.
55  
56 2 our $Aggregate_Export = [
57 qw/
58 to_latex
59 /
60 ];
61  
62 =head2 to_latex
63  
64 It returns a LaTeX representation of the Math::Symbolic tree
65 it is called on. The LaTeX is meant to be included in a LaTeX
66 source document. It does not include an enclosing math environment.
67  
68 The method uses named parameter passing style. Valid parameters are:
69  
70 =over 4
71  
72 =item implicit_multiplication
73  
74 Used to turn on the '.' (C<\cdot>) operators for all multiplications.
75 Defaults to true, that is, the multiplication operators are not present.
76  
77 =item no_fractions
78  
79 Use '/' division operator instead of fractions.
80 Defaults to false, that is, use fractions. See also:
81 C<max_fractions> parameter.
82  
83 =item max_fractions
84  
85 Setting this parameter to a positive integer results in a limitation
86 of the number of nested fractions. It defaults to C<2>. Setting this to
87 C<0> results in arbitrarily nested fractions. To disable fractions
88 altogether, set the C<no_fraction> parameter.
89  
90 =item exclude_signature
91  
92 By default, the method includes all variables' signatures in parenthesis
93 if present. Set this to true to omit variable signatures.
94  
95 =item replace_default_greek
96  
97 By default, all variable names are outputted as LaTeX in a way that
98 makes them show up exactly as they did in your code. If you set
99 this option to true, Math::Symbolic will try to replace as many
100 greek character names with the appropriates symbols as possible.
101  
102 Valid LaTeX symbols that are matched are:
103  
104 Lower case letters:
105 alpha, beta, gamma, delta, epsilon, zeta, eta, theta,
106 iota, kappa, lambda, mu, nu, xi, pi, rho, sigma,
107 tau, upsilon, phi, chi, psi, omega
108
109 Variant forms of small letters:
110 varepsilon, vartheta, varpi, varrho, varsigma, varphi
111
112 Upper case letters:
113 Gamma, Delta, Theta, Lambda, Xi, Pi, Sigma, Upsilon, Phi,
114 Psi, Omega
115  
116 =item variable_mappings
117  
118 Because not all variable names come out as you might want them to,
119 you may use the 'variable_mappings' option to replace variable names
120 in the output LaTeX stream with custom LaTeX. For example, the
121 variable x_i should probably indicate an 'x' with a subscripted i.
122 The argument to variable_mappings needs to be a hash reference which
123 contains variable name / LaTeX mapping pairs.
124  
125 If a variable is replaced in the above fashion, other options that
126 modify the outcome of the conversion of variable names to LaTeX are
127 ignored.
128  
129 =item subscript
130  
131 Set this option to a true value to have all underscores in variable names
132 interpreted as subscripts. Once an underscore is encountered, the rest of the
133 variable name is treated as subscripted. If multiple underscores are found, this
134 mechanism works recursively.
135  
136 Defaults to C<true>. Set to a false value to turn this off. This is automatically
137 turned off for variables that are mapped to custom LaTeX by the C<variable_mappings>
138 parameter.
139  
140 =item no_sqrt
141  
142 By default, the dumper tries to convert exponents of 1/2 (or 0.5) or anything
143 numeric that ends up being 1/2 to a square root. If this gives inconvenient results,
144 set this option to a true value to turn the heuristics off.
145  
146 =back
147  
148 =cut
149  
150 2 ▶sub to_latex {
Subroutine to_latex: called CC=10 SCAR=28.0
Pod documented
151 2 my $self = shift;
152 2 my %config = @_;
153 $config{implicit_multiplication} = 1
154 2 ▶ unless defined $config{implicit_multiplication};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config{"implicit_multiplication"} 2 0 2
155 2 ▶ $config{no_fractions} = 0 unless defined $config{no_fractions};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config{"no_fractions"} 2 0 2
156 2 ▶ $config{max_fractions} = 2 if not exists $config{max_fractions};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $config{"max_fractions"} 2 0 2
157 2 ▶ $config{exclude_signature} = 0 unless defined $config{exclude_signature};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config{"exclude_signature"} 2 0 2
158 2 ▶ $config{no_sqrt} = 0 unless defined $config{no_sqrt};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config{"no_sqrt"} 2 0 2
159 $config{replace_default_greek} = 0
160 2 ▶ unless defined $config{replace_default_greek};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config{"replace_default_greek"} 2 0 2
161  
162 2 ▶ $config{subscript} = 1 if not exists $config{subscript};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $config{"subscript"} 2 0 2
163  
164 $config{variable_mappings} = {}
165 if not exists $config{variable_mappings}
166 2 ▶ or not ref( $config{variable_mappings} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless exists $config{"variable_mappings"} and ref $config{"variable_mappings"} eq "HASH" 2 0 2
Condition33%1/3
exists $config{"variable_mappings"} and ref $config{"variable_mappings"} eq "HASH"
!ll&&!rl&&r
200
MC/DC0%0/2
exists $config{"variable_mappings"} and ref $config{"variable_mappings"} eq "HASH"
exists $config{"variable_mappings"} ref $config{"variable_mappings"} eq "HASH"
Truth table33%1/3
A and B
A= exists $config{"variable_mappings"}B= ref $config{"variable_mappings"} eq "HASH"
ABresult
0X0
100
111
167  
168 2 my $default_greek = qr/(?<![a-zA-Z])
169 alpha|beta|gamma|delta|epsilon|zeta|eta|theta
170 |iota|kappa|lambda|mu|nu|xi|pi|rho|sigma|tau|upsilon
171 |phi|chi|psi|omega
172 |varepsilon|vartheta|varpi|varrho|varsigma|varphi
173 |Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega
174 (?![a-zA-Z])
175 /x;
176  
177 1 ▶ my $greekify = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
178 1 my $s = $_[0];
179 1 ▶ $s =~ s/($default_greek)/\\$1/g if $config{replace_default_greek};
Branch: 1 branch
BranchTrueFalseTotal
if $config{"replace_default_greek"} 0 1 1
180 1 return $s;
181 2 };
182
183 2 my $subscriptify;
184 1 ▶ $subscriptify = sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
185 1 my $s = $_[0];
186 1 ▶ $s = '' if not defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 1 1
187 0 ▶ $s =~ s{_(.*)$}/length($1) == 1 ? "_$1" : '_{'.$subscriptify->($1).'}'/e if $config{subscript};
Branch: 2 branches
BranchTrueFalseTotal
if $config{"subscript"} 1 0 1
length $1 == 1 ? : 0 0 0
188 1 return $s;
189 2 };
190
191 2 my $precedence = [
192 1, # B_SUM
193 1, # B_DIFFERENCE
194 5, # B_PRODUCT
195 5, # B_DIVISION
196 15, # U_MINUS
197 20, # U_P_DERIVATIVE
198 20, # U_T_DERIVATIVE
199 25, # B_EXP
200 50, # B_LOG
201 50, # U_SINE
202 50, # U_COSINE
203 50, # U_TANGENT
204 50, # U_COTANGENT
205 50, # U_ARCSINE
206 50, # U_ARCCOSINE
207 50, # U_ARCTANGENT
208 50, # U_ARCCOTANGENT
209 50, # U_SINE_H
210 50, # U_COSINE_H
211 50, # U_AREASINE_H
212 50, # U_AREACOSINE_H
213 50, # B_ARCTANGENT_TWO
214 ];
215  
216 my $op_to_tex = [
217  
218 # B_SUM
219 1 ▶ sub { "$_[0] + $_[1]" },
Subroutine __ANON__: called CC=1 SCAR=0.0
220  
221 # B_DIFFERENCE
222 0 ▶ sub { "$_[0] - $_[1]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
223  
224 # B_PRODUCT
225 1 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
226 $config{implicit_multiplication}
227 1 ▶ ? "$_[0] $_[1]"
Branch: 1 branch
BranchTrueFalseTotal
$config{'implicit_multiplication'} ? : 1 0 1
228 : "$_[0] \\cdot $_[1]";
229 },
230  
231 # B_DIVISION
232 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
233 0 ▶ if ( $config{no_fractions} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($config{'no_fractions'}) { } 0 0 0
elsif (not $config{'max_fractions'} or $config{'max_fractions'} > $_[2]) { } 0 0 0
234 0 "$_[0] / $_[1]"
235 }
236 ▶ elsif (!$config{max_fractions} or $config{max_fractions} > $_[2]) {
Condition0%0/3
not $config{"max_fractions"} or $config{"max_fractions"} > $_[2]
l!l&&r!l&&!r
000
MC/DC0%0/2
not $config{"max_fractions"} or $config{"max_fractions"} > $_[2]
not $config{"max_fractions"} $config{"max_fractions"} > $_[2]
Truth table0%0/3
not(A) or B
A= not $config{"max_fractions"}B= $config{"max_fractions"} > $_[2]
ABresult
1X1
011
000
237 0 "\\frac{$_[0]}{$_[1]}"
238 }
239 else {
240 0 "$_[0] / $_[1]"
241 }
242 },
243  
244 # U_MINUS
245 1 ▶ sub { "-$_[0]" },
Subroutine __ANON__: called CC=1 SCAR=0.0
246  
247 # U_P_DERIVATIVE
248 0 ▶ sub { "\\frac{\\partial $_[0]}{\\partial $_[1]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
249  
250 # U_T_DERIVATIVE
251 0 ▶ sub { "\\frac{d $_[0]}{d $_[1]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
252  
253 # B_EXP
254 1 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=25.2
255 1 ▶ if (!$config{no_sqrt} and length($_[1]) > 2 and $_[1] !~ /\{|\}|\^|_|\-|\\|[A-DF-Za-df-z]/ and $_[1] - 0.5 < 1e-28) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $config{"no_sqrt"} and length $_[1] > 2 and not $_[1] =~ /\{|\}|\^|_|\-|\\|[A-DF-Za-df-z]/ and $_[1] - "0.5" < "1e-28") 0 1 1
Condition33%3/9
not $config{"no_sqrt"} and length $_[1] > 2 and not $_[1] =~ /\{|\}|\^|_|\-|\\|[A-DF-Za-df-z]/ and $_[1] - "0.5" < "1e-28"
!ll&&!rl&&r
100
not $config{"no_sqrt"} and length $_[1] > 2 and not $_[1] =~ /\{|\}|\^|_|\-|\\|[A-DF-Za-df-z]/
!ll&&!rl&&r
100
not $config{"no_sqrt"} and length $_[1] > 2
!ll&&!rl&&r
010
MC/DC0%0/4
not $config{"no_sqrt"} and length $_[1] > 2 and not $_[1] =~ /\{|\}|\^|_|\-|\\|[A-DF-Za-df-z]/ and $_[1] - "0.5" < "1e-28"
not $config{"no_sqrt"} length $_[1] > 2 not $_[1] =~ /\{|\}|\^|_|\-|\\|[A-DF-Za-df-z]/ $_[1] - "0.5" < "1e-28"
Truth table20%1/5
not(A) and B and not(C) and D
A= not $config{"no_sqrt"}B= length $_[1] > 2C= not $_[1] =~ /\{|\}|\^|_|\-|\\|[A-DF-Za-df-z]/D= $_[1] - "0.5" < "1e-28"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
256 0 return "\\sqrt{$_[0]}";
257 }
258 1 ▶ length($_[1]) == 1 ? "$_[0]^$_[1]" : "$_[0]^{$_[1]}"
Branch: 1 branch
BranchTrueFalseTotal
length $_[1] == 1 ? : 1 0 1
259 },
260  
261 # B_LOG
262 0 ▶ sub { "\\log_{$_[0]}$_[1]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
263  
264 # U_SINE
265 0 ▶ sub { "\\sin{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
266  
267 # U_COSINE
268 0 ▶ sub { "\\cos{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
269  
270 # U_TANGENT
271 0 ▶ sub { "\\tan{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
272  
273 # U_COTANGENT
274 0 ▶ sub { "\\cot{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
275  
276 # U_ARCSINE
277 0 ▶ sub { "\\arcsin{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
278  
279 # U_ARCCOSINE
280 0 ▶ sub { "\\arccos{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
281  
282 # U_ARCTANGENT
283 0 ▶ sub { "\\arctan{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
284  
285 # U_ARCCOTANGENT
286 0 ▶ sub { "\\mathrm{cosec}{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
287  
288 # U_SINE_H
289 0 ▶ sub { "\\sinh{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
290  
291 # U_COSINE_H
292 0 ▶ sub { "\\cosh{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
293  
294 # U_AREASINE_H
295 0 ▶ sub { "\\mathrm{arsinh}{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
296  
297 # U_AREACOSINE_H
298 0 ▶ sub { "\\mathrm{arcosh}{$_[0]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
299  
300 # B_ARCTANGENT_TWO
301 0 ▶ sub { "\\mathrm{atan2}{$_[0], $_[1]}" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
302 2 ];
303  
304 my $tex = $self->descend(
305 in_place => 0,
306 4 ▶ operand_finder => sub { $_[0]->descending_operands('all') },
Subroutine __ANON__: called CC=1 SCAR=0.0
307 9 ▶ before => sub {
Subroutine __ANON__: called CC=8 SCAR=21.3
308 $_[0]->{__precedences} = [
309 map {
310 7 my $ttype = $_->term_type();
311 7 ▶ if ( $ttype == T_OPERATOR ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ttype == 0) { } 3 4 7
elsif ($ttype == 2) { } 1 3 4
elsif ($ttype == 1) { } 3 0 3
312 3 $precedence->[ $_->type() ];
313 }
314 elsif ( $ttype == T_VARIABLE ) {
315 1 100;
316 }
317 elsif ( $ttype == T_CONSTANT ) {
318 3 100;
319 }
320 0 else { die "Should not be reached"; }
321 9 } @{ $_[0]->{operands} }
322 ];
323 9 ▶ my $fraction_depth = $_[0]->{__fract_depth} || 0;
Condition50%1/2
$_[0]{'__fract_depth'} || 0
l!l
09
MC/DC0%0/1
$_[0]{'__fract_depth'} || 0
$_[0]{'__fract_depth'}
Truth table50%1/2
A
A= $_[0]{'__fract_depth'}
Aresult
11
00
324 9 ▶ $fraction_depth++ if $_[0]->term_type() == T_OPERATOR and $_[0]->type() == B_DIVISION;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->term_type == 0 and $_[0]->type == 3 0 9 9
Condition66%2/3
$_[0]->term_type == 0 and $_[0]->type == 3
!ll&&!rl&&r
540
MC/DC0%0/2
$_[0]->term_type == 0 and $_[0]->type == 3
$_[0]->term_type == 0 $_[0]->type == 3
Truth table66%2/3
A and B
A= $_[0]->term_type == 0B= $_[0]->type == 3
ABresult
0X0
100
111
325 9 for (@{ $_[0]->{operands} }) {
326 7 $_->{__fract_depth} = $fraction_depth;
327 }
328 9 return ();
329 },
330 9 ▶ after => sub {
Subroutine __ANON__: called CC=23 SCAR=37.1
331 9 my $self = $_[0];
332 9 my $ttype = $self->term_type();
333 9 ▶ if ( $ttype == T_CONSTANT ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ttype == 1) { } 4 5 9
elsif ($ttype == 2) { } 1 4 5
elsif ($ttype == 0) { } 4 0 4
334 4 $self->{text} = $self->value();
335 }
336 elsif ( $ttype == T_VARIABLE ) {
337 1 my $name = $self->name();
338 1 my $edited_name = $name;
339 1 ▶ if ( exists $config{variable_mappings}{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config{'variable_mappings'}{$name}) { } 0 1 1
340 0 $edited_name = $config{variable_mappings}{$name};
341 }
342 else {
343 1 $edited_name = $greekify->($name);
344 1 $edited_name = $subscriptify->($edited_name);
345 }
346 1 ▶ unless ( $config{exclude_signature} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config{'exclude_signature'}) { } 0 1 1
347 my @sig =
348 map {
349 0 ▶ if ( exists $config{variable_mappings}{$_} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config{'variable_mappings'}{$_}) { } 0 0 0
350 {
351 0 $config{variable_mappings}{$_};
352 }
353 else {
354 0 $_ = $subscriptify->($_);
355 0 s/_/\_/g;
356 0 $greekify->($_);
357 }
358 }
359 grep $_ ne $name, $self->signature();
360 1 ▶ if (@sig) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sig) { } 0 1 1
361 0 $self->{text} = "$edited_name(" . join( ', ', @sig ) . ')';
362 }
363 else {
364 1 $self->{text} = $edited_name;
365 }
366 }
367 else {
368 0 $self->{text} = $edited_name;
369 }
370 }
371 elsif ( $ttype == T_OPERATOR ) {
372 4 my $type = $self->type();
373 4 my $prec = $precedence->[$type];
374 4 my $precs = $self->{__precedences};
375 4 my @ops = @{ $self->{operands} };
376 4 ▶ unless ( $type == B_DIVISION and !$config{no_fractions} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type == 3 and not $config{"no_fractions"}) 4 0 4
Condition33%1/3
$type == 3 and not $config{"no_fractions"}
!ll&&!rl&&r
400
MC/DC0%0/2
$type == 3 and not $config{"no_fractions"}
$type == 3 not $config{"no_fractions"}
Truth table33%1/3
A and not(B)
A= $type == 3B= not $config{"no_fractions"}
ABresult
0X0
100
111
377 4 ▶ for ( my $i = 0 ; $i < @ops ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @ops) 7 4 11
378 7 my $obj = $ops[$i];
379 7 ▶ if ( $precs->[$i] < $prec
Branch: 1 branch
BranchTrueFalseTotal
if ($precs->[$i] < $prec or $precs->[$i] == $prec and $prec == 50 or ($i == 1 and $type == 2 || $type == 0 || $type == 1 and ($obj->term_type == 1 and $obj->value < 0) or $obj->term_type == 0 and $obj->type == 4)) 1 6 7
Condition66%20/30
$precs->[$i] < $prec or $precs->[$i] == $prec and $prec == 50 or ($i == 1 and $type == 2 || $type == 0 || $type == 1 and ($obj->term_type == 1 and $obj->value < 0) or $obj->term_type == 0 and $obj->type == 4)
l!l&&r!l&&!r
016
$precs->[$i] < $prec or $precs->[$i] == $prec and $prec == 50
l!l&&r!l&&!r
007
$precs->[$i] == $prec and $prec == 50
!ll&&!rl&&r
700
$i == 1 and $type == 2 || $type == 0 || $type == 1 and ($obj->term_type == 1 and $obj->value < 0) or $obj->term_type == 0 and $obj->type == 4
l!l&&r!l&&!r
016
$i == 1 and $type == 2 || $type == 0 || $type == 1 and ($obj->term_type == 1 and $obj->value < 0)
!ll&&!rl&&r
520
$i == 1 and $type == 2 || $type == 0 || $type == 1
!ll&&!rl&&r
412
$type == 2 or $type == 0 or $type == 1
l!l&&r!l&&!r
201
$type == 2 or $type == 0
l!l&&r!l&&!r
111
$obj->term_type == 1 and $obj->value < 0
!ll&&!rl&&r
200
$obj->term_type == 0 and $obj->type == 4
!ll&&!rl&&r
421
MC/DC0%0/11
$precs->[$i] < $prec or $precs->[$i] == $prec and $prec == 50 or ($i == 1 and $type == 2 || $type == 0 || $type == 1 and ($obj->term_type == 1 and $obj->value < 0) or $obj->term_type == 0 and $obj->type == 4)
$precs->[$i] < $prec $precs->[$i] == $prec $prec == 50 $i == 1 $type == 2 $type == 0 $type == 1 $obj->term_type == 1 $obj->value < 0 $obj->term_type == 0 $obj->type == 4
Truth table8%5/56
A or B and C or D and E or F or G and H and I or J and K
A= $precs->[$i] < $precB= $precs->[$i] == $precC= $prec == 50D= $i == 1E= $type == 2F= $type == 0G= $type == 1H= $obj->term_type == 1I= $obj->value < 0J= $obj->term_type == 0K= $obj->type == 4
ABCDEFGHIJKresult
1XXXXXXXXXX1
011XXXXXXXX1
00X11XX11XX1
00X101X11XX1
00X100111XX1
00X0XXXXX111
00X1000XX111
00X11XX0X111
00X11XX10111
00X101X0X111
00X101X10111
00X10010X111
00X100110111
01011XX11XX1
010101X11XX1
010100111XX1
0100XXXXX111
0101000XX111
01011XX0X111
01011XX10111
010101X0X111
010101X10111
01010010X111
010100110111
00X0XXXXX0X0
00X0XXXXX100
00X1000XX0X0
00X1000XX100
00X11XX0X0X0
00X11XX0X100
00X11XX100X0
00X11XX10100
00X101X0X0X0
00X101X0X100
00X101X100X0
00X101X10100
00X10010X0X0
00X10010X100
00X1001100X0
00X100110100
0100XXXXX0X0
0100XXXXX100
0101000XX0X0
0101000XX100
01011XX0X0X0
01011XX0X100
01011XX100X0
01011XX10100
010101X0X0X0
010101X0X100
010101X100X0
010101X10100
01010010X0X0
01010010X100
0101001100X0
010100110100
380 or $precs->[$i] == $prec && $prec == 50 # prec == 50 is a function call
381 or $i == 1 # second operand
382 && ($type == B_PRODUCT||$type == B_SUM||$type==B_DIFFERENCE)
383 && ($obj->term_type == T_CONSTANT && $obj->value < 0)
384 || ($obj->term_type == T_OPERATOR && $obj->type == U_MINUS) )
385 {
386 1 $ops[$i]->{text} = '\\left(' . $ops[$i]->{text} . '\\right)'
387 }
388 }
389 }
390 4 ▶ my $fraction_depth = $self->{__fract_depth}||0;
Condition50%1/2
$self->{'__fract_depth'} || 0
l!l
04
MC/DC0%0/1
$self->{'__fract_depth'} || 0
$self->{'__fract_depth'}
Truth table50%1/2
A
A= $self->{'__fract_depth'}
Aresult
11
00
391 4 my $text = $op_to_tex->[$type]->((map $_->{text}, @ops), $fraction_depth);
392 4 $self->{text} = $text;
393 }
394 else {
395 0 die "Should never be reached";
396 }
397 },
398 2 );
399  
400 2 return $tex->{text};
401 }
402  
403 2 1;
404 __END__
↑ Summary