diff --git a/MANIFEST b/MANIFEST index 75f864ffb..7468ff73e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -831,6 +831,7 @@ t/55_theorem.t t/56_ams.t t/65_graphics.t t/66_pgf.tt +t/661_pgfmathparse.t t/67_tikz.tt t/70_parse.t t/80_complex.t @@ -1638,6 +1639,9 @@ t/pgf/stress_pgfmath.xml t/pgf/stress_pgfplots.pdf t/pgf/stress_pgfplots.tex t/pgf/stress_pgfplots.xml +t/pgfmathparse/pgfmathparse.pdf +t/pgfmathparse/pgfmathparse.tex +t/pgfmathparse/pgfmathparse.xml t/post/hyperref-post.xml t/post/hyperref.xml t/post/simplemath-post.xml diff --git a/t/661_pgfmathparse.t b/t/661_pgfmathparse.t new file mode 100644 index 000000000..5e5db1068 --- /dev/null +++ b/t/661_pgfmathparse.t @@ -0,0 +1,10 @@ +# -*- CPERL -*- +#********************************************************************** +# Test cases for LaTeXML +#********************************************************************** +use LaTeXML::Util::Test; + +latexml_tests("t/pgfmathparse", + requires=>{ + pgfmathparse=>{ + packages=>'pgf.sty'} }); diff --git a/t/pgfmathparse/pgfmathparse.pdf b/t/pgfmathparse/pgfmathparse.pdf new file mode 100644 index 000000000..16c47ac45 Binary files /dev/null and b/t/pgfmathparse/pgfmathparse.pdf differ diff --git a/t/pgfmathparse/pgfmathparse.tex b/t/pgfmathparse/pgfmathparse.tex new file mode 100644 index 000000000..b8b772596 --- /dev/null +++ b/t/pgfmathparse/pgfmathparse.tex @@ -0,0 +1,172 @@ +\documentclass{article} +\usepackage{pgf} +% ifthenelse will force LaTeXML to use the grammar instead of eval, because it is blacklisted +\makeatletter +\def\test{\begingroup\pgfmath@catcodes\@ifnextchar[\test@\test@@} +\def\test@[#1]#2{\texttt{#1 = \pgfmathprint{#2} = \pgfmathprint{ifthenelse(1,#2,"never")}}\endgroup\par} +\def\test@@#1{\test@[#1]{#1}} +\makeatother +\begin{document} + +\section{94.1.1 Commands} +\test{2pt+3.5pt} +\test{sin(.5*pi r)*60} +\test{1.234e+4} +\test{010} +\test{0xA} +\test{0XB} +\test{0b10} +\test{0B101} +% partially implemented: quotes + +\section{92.2 Operators} +\test{1+2} +\test{1-2} +\test{-2} +\test{1*2} +\test{1/2} +% correct, but generates 'Script ^ can only appear in math mode' error +\test[2\^3]{2^3} +\test{4!} +\test{1r} +\test{pi r} +\test{1 ? 2 : 3} +\test{2 == 2} +\test{2 == 1} +\test{(1+2)*3} +\test{sin(30*10)} +\test{mod(72,3)} +\test{sin 30} +\test{sin(30)} +\test{sin 30*10} +\test{sin(30)*10} +% unimplemented: array operator {X} +% unimplemented: array access operator [X] +5 is {\pgfmathprint{ifthenelse(5 > 7,"\noexpand\Large Bigger","\noexpand\tiny smaller")} than 7.} + +5 is {\pgfmathprint{5 > 7 ? "\noexpand\Large Bigger" : "\noexpand\tiny smaller"} than 7.} + +7 is {\pgfmathprint{ifthenelse(7 > 5,"\noexpand\Large Bigger","\noexpand\tiny smaller")} than 5.} + +7 is {\pgfmathprint{7 > 5 ? "\noexpand\Large Bigger" : "\noexpand\tiny smaller"} than 5} + +\section{92.3 Functions} + +\subsection{92.3.1 Basic arithmetic functions} +\test{add(75,6)} +\test{subtract(75,6)} +\test{neg(50)} +\test{multiply(75,6)} +\test{divide(75,6)} +\test{div(75,9)} +\test{factorial(5)} +\test{sqrt(10)} +\test{sqrt(8765.432)} +\test{pow(2,7)} +\test[e\^2 - e\^-2]{(e^2 - e^-2)/2} +\test{exp(1)} +\test{exp(2.34)} +\test{ln(10)} +\test{ln(exp(5))} +\test{log10(100)} +\test{log2(128)} +\test{abs(-5)} +\test{-abs(4*-3)} +\test{mod(20,6)} +\test{mod(-100,30)} +\test{Mod(-100,30)} +\test{sign(-5)} +\test{sign(0)} +\test{sign(5)} + +\subsection{94.3.2 Rounding functions} +\test{round(32.5/17)} +\test{round(398/12)} +\test{floor(32.5/17)} +\test{floor(398/12)} +\test{floor(-398/12)} +\test{ceil(32.5/17)} +\test{ceil(398/12)} +\test{ceil(-398/12)} +\test{int(32.5/17)} +\test{frac(32.5/17)} +\test{int(-32.5/17)} % added in LaTeXML to check behavior on negative numbers +\test{frac(-32.5/17)} % added in LaTeXML to check behavior on negative numbers +\test{real(4)} + +\subsection{94.3.3 Integer arithmetic functions} +% FAILS \test{gcd(42,56)} +\test{isodd(2)} +\test{isodd(3)} +\test{iseven(2)} +\test{iseven(3)} +\test{isprime(1)} +\test{isprime(2)} +\test{isprime(31)} +\test{isprime(64)} + +\subsection{94.3.4 Trigonometric functions} +\test{pi} +\test{pi r} +\test{rad(90)} +\test{deg(3*pi/2)} +\test{sin(60)} +% WRONG \test{sin(pi/3 r)} +\test{cos(60)} +% WRONG \test{cos(pi/3 r)} +\test{tan(45)} +% WRONG \test{tan(2*pi/8 r)} +\test{sec(45)} +\test{cosec(30)} +\test{cot(15)} + +\subsection{94.3.5 Comparison and logical functions} +% infix versions added by LaTeXML to check parsing +\test{equal(20,20)} +\test{20 == 20} +\test{greater(20,25)} +\test{20 > 25} +\test{less(20,25)} +\test{20 < 25} +\test{notequal(20,25)} +\test{20 != 25} +\test{notgreater(20,25)} +\test{20 <= 25} +\test{notless(20,25)} +\test{20 >= 25} +\test{and(5>4,6>7)} +\test{5>4 && 6>7} +\test{or(5>4,6>7)} +\test{5>4 || 6>7} +\test{not(true)} +\test{! true} +\test{not(false)} % added in LaTeXML to check parsing +\test{! false} % added in LaTeXML to check parsing +\test{ifthenelse(5==4,"yes","no")} +\test{5==4 ? "yes" : "no"} +\test{true ? "yes" : "no"} +\test{false ? "yes" : "no"} + +\subsection{94.3.6 Pseudo-random functions} +% unimplemented: determinism (yet) + +\subsection{94.3.7 Base conversion functions} +\test{hex(65535)} +\test{Hex(65535)} +\test{oct(63)} +% perl thinks this is a number and yields an overflow error +% FAILS \test{bin(185)} + +\subsection{94.3.8 Miscellaneous functions} +\test{min(3,4,-2,250,-8,100)} +\test{max(3,4,-2,250,-8,100)} +\test{veclen(12,5)} +% unimplemented: arrays +\test{sinh(0.5)} +\test{cosh(0.5)} +\test{tanh(0.5)} +\test{width("Some Lovely Text")} +\test{height("Some Lovely Text")} +\test{depth("Some Lovely Text")} + +\end{document} diff --git a/t/pgfmathparse/pgfmathparse.xml b/t/pgfmathparse/pgfmathparse.xml new file mode 100644 index 000000000..2015bcf5e --- /dev/null +++ b/t/pgfmathparse/pgfmathparse.xml @@ -0,0 +1,465 @@ + + + + + + + +
+ + 1 + 1 + §1 + + <tag close=" ">1</tag>94.1.1 Commands + +

2pt+3.5pt = 5.5 = 5.5

+
+ +

sin(.5*pi r)*60 = 60.0 = 60.0

+
+ +

1.234e+4 = 12340.0 = 12340.0

+
+ +

010 = 010 = 8.0

+
+ +

0xA = 10.0 = 10.0

+
+ +

0XB = 11.0 = 11.0

+
+ +

0b10 = 2.0 = 2.0

+
+ +

0B101 = 5.0 = 5.0

+
+
+
+ + 2 + 2 + §2 + + <tag close=" ">2</tag>92.2 Operators + +

1+2 = 3.0 = 3.0

+
+ +

1-2 = -1.0 = -1.0

+
+ +

-2 = -2.0 = -2.0

+
+ +

1*2 = 2.0 = 2.0

+
+ +

1/2 = 0.5 = 0.5

+
+ +

2^3 = 8.0 = 8.0

+
+ +

4! = 24.0 = 24.0

+
+ +

1r = 57.29578 = 57.29578

+
+ +

pi r = 180.0 = 180.0

+
+ +

1 ? 2 : 3 = 2.0 = 2.0

+
+ +

2 == 2 = 1.0 = 1.0

+
+ +

2 == 1 = 0.0 = 0.0

+
+ +

(1+2)*3 = 9.0 = 9.0

+
+ +

sin(30*10) = -0.86603 = -0.86603

+
+ +

mod(72,3) = 0.0 = 0.0

+
+ +

sin 30 = 0.5 = 0.5

+
+ +

sin(30) = 0.5 = 0.5

+
+ +

sin 30*10 = 5 = 5

+
+ +

sin(30)*10 = 5 = 5

+
+ +

5 is smaller than 7.

+
+ +

5 is smaller than 7.

+
+ +

7 is Bigger than 5.

+
+ +

7 is Bigger than 5

+
+
+
+ + 3 + 3 + §3 + + <tag close=" ">3</tag>92.3 Functions + + + 3.1 + 3.1 + §3.1 + + <tag close=" ">3.1</tag>92.3.1 Basic arithmetic functions + +

add(75,6) = 81.0 = 81.0

+
+ +

subtract(75,6) = 69.0 = 69.0

+
+ +

neg(50) = -50.0 = -50.0

+
+ +

multiply(75,6) = 450.0 = 450.0

+
+ +

divide(75,6) = 12.5 = 12.5

+
+ +

div(75,9) = 8.0 = 8.0

+
+ +

factorial(5) = 120.0 = 120.0

+
+ +

sqrt(10) = 3.16228 = 3.16228

+
+ +

sqrt(8765.432) = 93.62389 = 93.62389

+
+ +

pow(2,7) = 128.0 = 128.0

+
+ +

e^2 - e^-2 = 3.62686 = 3.62686

+
+ +

exp(1) = 2.71828 = 2.71828

+
+ +

exp(2.34) = 10.38124 = 10.38124

+
+ +

ln(10) = 2.30259 = 2.30259

+
+ +

ln(exp(5)) = 5.0 = 5.0

+
+ +

log10(100) = 2.0 = 2.0

+
+ +

log2(128) = 7.0 = 7.0

+
+ +

abs(-5) = 5.0 = 5.0

+
+ +

-abs(4*-3) = -12.0 = -12.0

+
+ +

mod(20,6) = 2.0 = 2.0

+
+ +

mod(-100,30) = -10.0 = -10.0

+
+ +

Mod(-100,30) = 20.0 = 20.0

+
+ +

sign(-5) = -1.0 = -1.0

+
+ +

sign(0) = 0.0 = 0.0

+
+ +

sign(5) = 1.0 = 1.0

+
+
+ + + 3.2 + 3.2 + §3.2 + + <tag close=" ">3.2</tag>94.3.2 Rounding functions + +

round(32.5/17) = 2.0 = 2.0

+
+ +

round(398/12) = 33.0 = 33.0

+
+ +

floor(32.5/17) = 1.0 = 1.0

+
+ +

floor(398/12) = 33.0 = 33.0

+
+ +

floor(-398/12) = -34.0 = -34.0

+
+ +

ceil(32.5/17) = 2.0 = 2.0

+
+ +

ceil(398/12) = 34.0 = 34.0

+
+ +

ceil(-398/12) = -33.0 = -33.0

+
+ +

int(32.5/17) = 1 = 1.0

+
+ +

frac(32.5/17) = 0.91176 = 0.91176

+
+ +

int(-32.5/17) = -1 = -1.0

+
+ +

frac(-32.5/17) = 0.91176 = 0.91176

+
+ +

real(4) = 4.0 = 4.0

+
+
+ + + 3.3 + 3.3 + §3.3 + + <tag close=" ">3.3</tag>94.3.3 Integer arithmetic functions + +

isodd(2) = 0.0 = 0.0

+
+ +

isodd(3) = 1.0 = 1.0

+
+ +

iseven(2) = 1.0 = 1.0

+
+ +

iseven(3) = 0.0 = 0.0

+
+ +

isprime(1) = 0.0 = 0.0

+
+ +

isprime(2) = 1.0 = 1.0

+
+ +

isprime(31) = 1.0 = 1.0

+
+ +

isprime(64) = 0.0 = 0.0

+
+
+ + + 3.4 + 3.4 + §3.4 + + <tag close=" ">3.4</tag>94.3.4 Trigonometric functions + +

pi = 3.14159 = 3.14159

+
+ +

pi r = 180.0 = 180.0

+
+ +

rad(90) = 1.5708 = 1.5708

+
+ +

deg(3*pi/2) = 270.0 = 270.0

+
+ +

sin(60) = 0.86603 = 0.86603

+
+ +

cos(60) = 0.5 = 0.5

+
+ +

tan(45) = 1 = 1

+
+ +

sec(45) = 1.41421 = 1.41421

+
+ +

cosec(30) = 2 = 2

+
+ +

cot(15) = 3.73205 = 3.73205

+
+
+ + + 3.5 + 3.5 + §3.5 + + <tag close=" ">3.5</tag>94.3.5 Comparison and logical functions + +

equal(20,20) = 1.0 = 1.0

+
+ +

20 == 20 = 1.0 = 1.0

+
+ +

greater(20,25) = 0.0 = 0.0

+
+ +

20 > 25 = 0.0 = 0.0

+
+ +

less(20,25) = 1.0 = 1.0

+
+ +

20 < 25 = 1.0 = 1.0

+
+ +

notequal(20,25) = 1.0 = 1.0

+
+ +

20 != 25 = 1.0 = 1.0

+
+ +

notgreater(20,25) = 1.0 = 1.0

+
+ +

20 <= 25 = 1.0 = 1.0

+
+ +

notless(20,25) = 0.0 = 0.0

+
+ +

20 >= 25 = 0.0 = 0.0

+
+ +

and(5>4,6>7) = 0.0 = 0.0

+
+ +

5>4 && 6>7 = 0.0 = 0.0

+
+ +

or(5>4,6>7) = 1.0 = 1.0

+
+ +

5>4 || 6>7 = 1.0 = 1.0

+
+ +

not(true) = 0.0 = 0.0

+
+ +

! true = 0.0 = 0.0

+
+ +

not(false) = 1.0 = 1.0

+
+ +

! false = 1.0 = 1.0

+
+ +

ifthenelse(5==4,"yes","no") = no = no

+
+ +

5==4 ? "yes" : "no" = no = no

+
+ +

true ? "yes" : "no" = yes = yes

+
+ +

false ? "yes" : "no" = no = no

+
+
+ + + 3.6 + 3.6 + §3.6 + + <tag close=" ">3.6</tag>94.3.6 Pseudo-random functions + + + + 3.7 + 3.7 + §3.7 + + <tag close=" ">3.7</tag>94.3.7 Base conversion functions + +

hex(65535) = ffff = ffff

+
+ +

Hex(65535) = FFFF = FFFF

+
+ +

oct(63) = 77.0 = 77.0

+
+
+ + + 3.8 + 3.8 + §3.8 + + <tag close=" ">3.8</tag>94.3.8 Miscellaneous functions + +

min(3,4,-2,250,-8,100) = -8.0 = -8.0

+
+ +

max(3,4,-2,250,-8,100) = 250.0 = 250.0

+
+ +

veclen(12,5) = 13.0 = 13.0

+
+ +

sinh(0.5) = 0.5211 = 0.5211

+
+ +

cosh(0.5) = 1.12763 = 1.12763

+
+ +

tanh(0.5) = 0.46212 = 0.46212

+
+ +

width("Some Lovely Text") = 78.47 = 78.47

+
+ +

height("Some Lovely Text") = 6.94 = 6.94

+
+ +

depth("Some Lovely Text") = 1.94 = 1.94

+
+
+
+