-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathlatextabular_test.jl
111 lines (97 loc) · 2.75 KB
/
latextabular_test.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using DataFrames: DataFrame
using Latexify
using Test
d = DataFrame(A = 11:13, B = [:X, :Y, :Z])
@test latexify(d; env=:table, side=1:3, latex=false) == replace(
raw"\begin{tabular}{ccc}
& A & B\\
1 & 11 & X\\
2 & 12 & Y\\
3 & 13 & Z\\
\end{tabular}
", "\r\n"=>"\n")
# Latexify.@generate_test latexify([1.]; env=:table)
@test latexify([1.0]; env = :table) == replace(
raw"\begin{tabular}{c}
$1.0$\\
\end{tabular}
", "\r\n"=>"\n")
arr = ["x/(y-1)", 1.0, 3//2, :(x-y), :symb]
M = vcat(reduce(hcat, arr), reduce(hcat, arr))
head = ["col$i" for i in 1:size(M, 2)]
side = ["row$i" for i in 1:size(M, 1)]
@test latexify(M; env=:table, head=1:2, adjustment=:l, latex=false, transpose=true) == replace(
raw"\begin{tabular}{ll}
1 & 2\\
x/(y-1) & x/(y-1)\\
1.0 & 1.0\\
3//2 & 3//2\\
x - y & x - y\\
symb & symb\\
\end{tabular}
", "\r\n"=>"\n")
@test latexify(M; env=:table, head=1:2, adjustment=[:c, :r], latex=false, transpose=true) == replace(
raw"\begin{tabular}{cr}
1 & 2\\
x/(y-1) & x/(y-1)\\
1.0 & 1.0\\
3//2 & 3//2\\
x - y & x - y\\
symb & symb\\
\end{tabular}
", "\r\n"=>"\n")
@test latexify(M; env=:table, head=1:2, adjustment=:l, transpose=true) == replace(
raw"\begin{tabular}{ll}
$1$ & $2$\\
$\frac{x}{y - 1}$ & $\frac{x}{y - 1}$\\
$1.0$ & $1.0$\\
$\frac{3}{2}$ & $\frac{3}{2}$\\
$x - y$ & $x - y$\\
$symb$ & $symb$\\
\end{tabular}
", "\r\n"=>"\n")
@test latexify(M; env=:table, head=1:5) == replace(
raw"\begin{tabular}{ccccc}
$1$ & $2$ & $3$ & $4$ & $5$\\
$\frac{x}{y - 1}$ & $1.0$ & $\frac{3}{2}$ & $x - y$ & $symb$\\
$\frac{x}{y - 1}$ & $1.0$ & $\frac{3}{2}$ & $x - y$ & $symb$\\
\end{tabular}
", "\r\n"=>"\n")
@test latexify(M; env=:table, side=[1, 2]) == replace(
raw"\begin{tabular}{cccccc}
$1$ & $\frac{x}{y - 1}$ & $1.0$ & $\frac{3}{2}$ & $x - y$ & $symb$\\
$2$ & $\frac{x}{y - 1}$ & $1.0$ & $\frac{3}{2}$ & $x - y$ & $symb$\\
\end{tabular}
", "\r\n"=>"\n")
@test latexify(M; env=:table, booktabs=true) == replace(
raw"\begin{tabular}{ccccc}
\toprule
$\frac{x}{y - 1}$ & $1.0$ & $\frac{3}{2}$ & $x - y$ & $symb$\\
$\frac{x}{y - 1}$ & $1.0$ & $\frac{3}{2}$ & $x - y$ & $symb$\\
\bottomrule
\end{tabular}
", "\r\n"=>"\n")
@test latexify(M; env=:table, head=1:5, booktabs=true) == replace(
raw"\begin{tabular}{ccccc}
\toprule
$1$ & $2$ & $3$ & $4$ & $5$\\
\midrule
$\frac{x}{y - 1}$ & $1.0$ & $\frac{3}{2}$ & $x - y$ & $symb$\\
$\frac{x}{y - 1}$ & $1.0$ & $\frac{3}{2}$ & $x - y$ & $symb$\\
\bottomrule
\end{tabular}
", "\r\n"=>"\n")
D = Dict(:a=>"x/(k+x)", :b=>"x - y")
@test latexify(D; env=:tabular) == replace(
raw"\begin{tabular}{cc}
$a$ & $\frac{x}{k + x}$\\
$b$ & $x - y$\\
\end{tabular}
", "\r\n"=>"\n")
@test latexify(D; env=:tabular, head=["Keys", "Values"]) == replace(
raw"\begin{tabular}{cc}
$Keys$ & $Values$\\
$a$ & $\frac{x}{k + x}$\\
$b$ & $x - y$\\
\end{tabular}
", "\r\n"=>"\n")