Skip to content

Commit a6702d7

Browse files
committed
add usage docs
1 parent 398cf1b commit a6702d7

File tree

2 files changed

+143
-6
lines changed

2 files changed

+143
-6
lines changed

docs/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ end-before: <!-- github-only -->
66

77
[license]: license
88
[contributor guide]: contributing
9-
[command-line reference]: usage
9+
10+
<!-- [command-line reference]: usage -->
1011

1112
```{toctree}
1213
---
1314
hidden:
1415
maxdepth: 1
1516
---
1617
17-
<!-- usage -->
18+
usage
1819
reference
1920
contributing
2021
Code of Conduct <codeofconduct>

docs/usage.md

Lines changed: 140 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,143 @@
11
# Usage
22

3-
```{eval-rst}
4-
.. click:: arraytex.__main__:main
5-
:prog: arraytex
6-
:nested: full
3+
<!-- ```{eval-rst} -->
4+
<!-- .. click:: arraytex.__main__:main -->
5+
<!-- :prog: arraytex -->
6+
<!-- :nested: full -->
7+
<!-- ``` -->
8+
9+
Suppose you want to convert a `numpy.NDArray` object to a LaTeX representation:
10+
11+
```python
12+
>>> import numpy as np
13+
>>> A = np.arange(6).reshape(2, 3)
14+
>>> A
15+
array([[0, 1, 2],
16+
[3, 4, 5]])
17+
```
18+
19+
## To matrix
20+
21+
First import the `to_matrix` function:
22+
23+
```python
24+
>>> from arraytex import to_matrix
25+
```
26+
27+
Then run `to_matrix` with a `numpy.NDArray` object as the first argument:
28+
29+
```python
30+
>>> print(to_matrix(A))
31+
\begin{bmatrix}
32+
0 & 1 & 2 \\
33+
3 & 4 & 5 \\
34+
\end{bmatrix}
35+
```
36+
37+
Different matrix style environment delimiters can be used:
38+
39+
```python
40+
>>> print(to_matrix(A, style="p"))
41+
\begin{pmatrix}
42+
0 & 1 & 2 \\
43+
3 & 4 & 5 \\
44+
\end{pmatrix}
45+
```
46+
47+
So can builtin number formatters:
48+
49+
```python
50+
>>> print(to_matrix(A, num_format=".2e"))
51+
\begin{bmatrix}
52+
0.00\mathrm{e}{+00} & 1.00\mathrm{e}{+00} & 2.00\mathrm{e}{+00} \\
53+
3.00\mathrm{e}{+00} & 4.00\mathrm{e}{+00} & 5.00\mathrm{e}{+00} \\
54+
\end{bmatrix}
55+
```
56+
57+
Prefer scientific notation to e-notation? No problem:
58+
59+
```python
60+
>>> print(to_matrix(A, num_format=".2e", scientific_notation=True))
61+
\begin{bmatrix}
62+
0.00 \times 10^{+00} & 1.00 \times 10^{+00} & 2.00 \times 10^{+00} \\
63+
3.00 \times 10^{+00} & 4.00 \times 10^{+00} & 5.00 \times 10^{+00} \\
64+
\end{bmatrix}
65+
```
66+
67+
## To tabular
68+
69+
First import the `to_tabular` function:
70+
71+
```python
72+
>>> from arraytex import to_tabular
73+
```
74+
75+
Then run `to_tabular` with a `numpy.NDArray` as the first argument:
76+
77+
```python
78+
>>> print(to_tabular(A))
79+
\begin{tabular}{c c c}
80+
\toprule
81+
Col 1 & Col 2 & Col 3 \\
82+
\midrule
83+
0 & 1 & 2 \\
84+
3 & 4 & 5 \\
85+
\bottomrule
86+
\end{tabular}
87+
```
88+
89+
The `num_format` and `scientific_notation` arguments are available to use:
90+
91+
```python
92+
>>> print(to_tabular(A, num_format=".2f"))
93+
\begin{tabular}{c c c}
94+
\toprule
95+
Col 1 & Col 2 & Col 3 \\
96+
\midrule
97+
0.00 & 1.00 & 2.00 \\
98+
3.00 & 4.00 & 5.00 \\
99+
\bottomrule
100+
\end{tabular}
101+
```
102+
103+
You can pass custom column names and column align identifiers:
104+
105+
```python
106+
>>> print(to_tabular(A, col_align=["l", "c", "r"], col_names=["Data", "More Data", "Even More Data"]))
107+
\begin{tabular}{l c r}
108+
\toprule
109+
Data & More Data & Even More Data \\
110+
\midrule
111+
0 & 1 & 2 \\
112+
3 & 4 & 5 \\
113+
\bottomrule
114+
\end{tabular}
115+
```
116+
117+
Pass a list of column indices:
118+
119+
```python
120+
>>> print(to_tabular(A, col_index=["Sample 1", "Sample 2"]))
121+
\begin{tabular}{l c c c}
122+
\toprule
123+
Index & Col 1 & Col 2 & Col 3 \\
124+
\midrule
125+
Sample 1 & 0 & 1 & 2 \\
126+
Sample 2 & 3 & 4 & 5 \\
127+
\bottomrule
128+
\end{tabular}
129+
```
130+
131+
Specify the name of the name of index column through `col_names`:
132+
133+
```python
134+
>>> print(to_tabular(A, col_index=["Sample 1", "Sample 2"], col_names=["Which Sample", "A", "B", "C"]))
135+
\begin{tabular}{l c c c}
136+
\toprule
137+
Which Sample & A & B & C \\
138+
\midrule
139+
Sample 1 & 0 & 1 & 2 \\
140+
Sample 2 & 3 & 4 & 5 \\
141+
\bottomrule
142+
\end{tabular}
7143
```

0 commit comments

Comments
 (0)