Skip to content

Commit cd372e5

Browse files
committed
force comparison operators to return integers in PGF math parser
1 parent 5ca9109 commit cd372e5

File tree

1 file changed

+59
-59
lines changed

1 file changed

+59
-59
lines changed

lib/LaTeXML/Package/pgfmath.code.tex.ltxml

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -558,53 +558,58 @@ sub pgfmath_checkuserfunction {
558558

559559
BEGIN {
560560
$PGFMathFunctions = {
561-
'==' => sub { $_[0] == $_[1]; },
562-
equal => sub { $_[0] == $_[1]; },
563-
'>' => sub { $_[0] > $_[1]; },
564-
greater => sub { $_[0] > $_[1]; },
565-
'<' => sub { $_[0] < $_[1]; },
566-
less => sub { $_[0] < $_[1]; },
567-
'!=' => sub { $_[0] != $_[1]; },
568-
notequal => sub { $_[0] != $_[1]; },
569-
'>=' => sub { $_[0] >= $_[1]; },
570-
notless => sub { $_[0] >= $_[1]; },
571-
'<=' => sub { $_[0] <= $_[1]; },
572-
notgreater => sub { $_[0] <= $_[1]; },
573-
'&&' => sub { $_[0] && $_[1]; },
574-
'and' => sub { $_[0] && $_[1]; },
575-
'||' => sub { $_[0] || $_[1]; },
576-
or => sub { $_[0] || $_[1]; },
577-
'+' => sub { (defined $_[1] ? $_[0] + $_[1] : $_[0]); },
578-
'add' => sub { (defined $_[1] ? $_[0] + $_[1] : $_[0]); },
579-
'-' => sub { (defined $_[1] ? $_[0] - $_[1] : -$_[0]); }, # prefix or infix
580-
neg => sub { -$_[0]; },
581-
'*' => sub { $_[0] * $_[1]; },
582-
multiply => sub { $_[0] * $_[1]; },
583-
'/' => sub { $_[0] / pgfmath_divisor($_[1]); },
584-
divide => sub { $_[0] / pgfmath_divisor($_[1]); },
585-
div => sub { int($_[0] / pgfmath_divisor($_[1])); },
586-
'!' => sub { pgfmathfactorial($_[0]); },
587-
'r' => sub { rad2deg($_[0]); },
588-
e => sub { $E; },
589-
pi => sub { $PI; },
590-
abs => sub { abs($_[0]); },
591-
acos => sub { acos($_[0]); },
592-
array => sub { },
593-
asin => sub { rad2deg(asin($_[0])); },
594-
atan => sub { rad2deg(atan($_[0])); },
595-
atan2 => sub { rad2deg(atan2($_[0], $_[1])); },
596-
angle => sub { rad2deg(atan2($_[0], $_[1])); }, # Assume same? Where's documentation?
597-
bin => sub { sprintf("%b", $_[0]); },
598-
ceil => sub { ceil($_[0]); },
599-
cos => sub { cos(pgfmathargradians($_[0])); },
600-
cosec => sub { cosec(pgfmathargradians($_[0])); },
601-
cosh => sub { cosh($_[0]); },
602-
cot => sub { cot(pgfmathargradians($_[0])); },
603-
deg => sub { rad2deg($_[0]); },
561+
not => sub { int(!$_[0]) },
562+
'==' => sub { int($_[0] == $_[1]) },
563+
equal => sub { int($_[0] == $_[1]) },
564+
'>' => sub { int($_[0] > $_[1]) },
565+
greater => sub { int($_[0] > $_[1]) },
566+
'<' => sub { int($_[0] < $_[1]) },
567+
less => sub { int($_[0] < $_[1]) },
568+
'!=' => sub { int($_[0] != $_[1]) },
569+
notequal => sub { int($_[0] != $_[1]) },
570+
'>=' => sub { int($_[0] >= $_[1]) },
571+
notless => sub { int($_[0] >= $_[1]) },
572+
'<=' => sub { int($_[0] <= $_[1]) },
573+
notgreater => sub { int($_[0] <= $_[1]) },
574+
'&&' => sub { int($_[0] && $_[1]) },
575+
'and' => sub { int($_[0] && $_[1]) },
576+
'||' => sub { int($_[0] || $_[1]) },
577+
or => sub { int($_[0] || $_[1]) },
578+
iseven => sub { int((int($_[0]) % 2) == 0) },
579+
isodd => sub { int((int($_[0]) % 2) == 1) },
580+
# isprime => sub { },
581+
false => sub { 0; },
582+
true => sub { 1; },
583+
'+' => sub { (defined $_[1] ? $_[0] + $_[1] : $_[0]); },
584+
'add' => sub { (defined $_[1] ? $_[0] + $_[1] : $_[0]); },
585+
'-' => sub { (defined $_[1] ? $_[0] - $_[1] : -$_[0]); }, # prefix or infix
586+
neg => sub { -$_[0]; },
587+
'*' => sub { $_[0] * $_[1]; },
588+
multiply => sub { $_[0] * $_[1]; },
589+
'/' => sub { $_[0] / pgfmath_divisor($_[1]); },
590+
divide => sub { $_[0] / pgfmath_divisor($_[1]); },
591+
div => sub { int($_[0] / pgfmath_divisor($_[1])); },
592+
'!' => sub { pgfmathfactorial($_[0]); },
593+
'r' => sub { rad2deg($_[0]); },
594+
e => sub { $E; },
595+
pi => sub { $PI; },
596+
abs => sub { abs($_[0]); },
597+
acos => sub { acos($_[0]); },
598+
array => sub { },
599+
asin => sub { rad2deg(asin($_[0])); },
600+
atan => sub { rad2deg(atan($_[0])); },
601+
atan2 => sub { rad2deg(atan2($_[0], $_[1])); },
602+
angle => sub { rad2deg(atan2($_[0], $_[1])); }, # Assume same? Where's documentation?
603+
bin => sub { sprintf("%b", $_[0]); },
604+
ceil => sub { ceil($_[0]); },
605+
cos => sub { cos(pgfmathargradians($_[0])); },
606+
cosec => sub { cosec(pgfmathargradians($_[0])); },
607+
cosh => sub { cosh($_[0]); },
608+
cot => sub { cot(pgfmathargradians($_[0])); },
609+
deg => sub { rad2deg($_[0]); },
604610
# depth => sub { },
605611
exp => sub { exp($_[0]); },
606612
factorial => sub { pgfmathfactorial($_[0]); },
607-
false => sub { 0; },
608613
floor => sub { floor($_[0]); },
609614
frac => sub { $_[0] < 0 ? ceil($_[0]) - $_[0] : $_[0] - floor($_[0]); },
610615
# gcd => sub { },
@@ -613,20 +618,16 @@ BEGIN {
613618
Hex => sub { sprintf("%X", $_[0]); },
614619
int => sub { $_[0] < 0 ? ceil($_[0]) : floor($_[0]); },
615620
ifthenelse => sub { ($_[0] ? $_[1] : $_[2]); },
616-
iseven => sub { (int($_[0]) % 2) == 0 },
617-
isodd => sub { (int($_[0]) % 2) == 1 },
618-
# isprime => sub { },
619-
ln => sub { log($_[0]); },
620-
log10 => sub { log($_[0]) / $LOG10; },
621-
log2 => sub { log($_[0]) / $LOG2; },
622-
max => sub { max(@_); },
623-
min => sub { min(@_); },
624-
mod => sub { pgfmath_mod_trunc($_[0], $_[1]); },
625-
Mod => sub { pgfmath_mod_floor($_[0], $_[1]); },
626-
not => sub { !$_[0]; },
627-
oct => sub { sprintf("%o", $_[0]); },
628-
pow => sub { $_[0]**$_[1]; },
629-
rad => sub { deg2rad($_[0]); },
621+
ln => sub { log($_[0]); },
622+
log10 => sub { log($_[0]) / $LOG10; },
623+
log2 => sub { log($_[0]) / $LOG2; },
624+
max => sub { max(@_); },
625+
min => sub { min(@_); },
626+
mod => sub { pgfmath_mod_trunc($_[0], $_[1]); },
627+
Mod => sub { pgfmath_mod_floor($_[0], $_[1]); },
628+
oct => sub { sprintf("%o", $_[0]); },
629+
pow => sub { $_[0]**$_[1]; },
630+
rad => sub { deg2rad($_[0]); },
630631
# rand => sub { },
631632
# random => sub { },
632633
real => sub { $_[0] + 0.0; },
@@ -641,7 +642,6 @@ BEGIN {
641642
subtract => sub { $_[0] - $_[1]; },
642643
tan => sub { tan(pgfmathargradians($_[0])); },
643644
tanh => sub { tanh($_[0]); },
644-
true => sub { 1; },
645645
veclen => sub { sqrt($_[0] * $_[0] + $_[1] * $_[1]); },
646646
# width => sub { },
647647
# Additional functions from tikz-cd; these need to get parameters from the current math font!

0 commit comments

Comments
 (0)