texshot 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- texshot-0.1.0/.gitignore +19 -0
- texshot-0.1.0/LICENSE +21 -0
- texshot-0.1.0/PKG-INFO +502 -0
- texshot-0.1.0/README.md +474 -0
- texshot-0.1.0/examples/figures.json +13 -0
- texshot-0.1.0/examples/music/notes.tex +38 -0
- texshot-0.1.0/examples/music/octave.tex +15 -0
- texshot-0.1.0/examples/stuff/yinyang.tex +54 -0
- texshot-0.1.0/pyproject.toml +47 -0
- texshot-0.1.0/src/texshot/__init__.py +3 -0
- texshot-0.1.0/src/texshot/__main__.py +5 -0
- texshot-0.1.0/src/texshot/cli.py +298 -0
texshot-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Outputs generated by texshot
|
|
2
|
+
*.svg
|
|
3
|
+
*.pdf
|
|
4
|
+
*.jpg
|
|
5
|
+
|
|
6
|
+
# TeX auxiliary files (in case a figure is compiled by hand)
|
|
7
|
+
*.aux
|
|
8
|
+
*.log
|
|
9
|
+
*.dvi
|
|
10
|
+
*.mx1
|
|
11
|
+
|
|
12
|
+
__pycache__/
|
|
13
|
+
.DS_Store
|
|
14
|
+
|
|
15
|
+
# Python packaging
|
|
16
|
+
dist/
|
|
17
|
+
build/
|
|
18
|
+
*.egg-info/
|
|
19
|
+
.venv/
|
texshot-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lê Quốc Dũng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
texshot-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: texshot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Build standalone TeX figures (TikZ, MusiXTeX, ...) into SVG, PDF or JPEG for rST/Sphinx.
|
|
5
|
+
Author-email: Lê Quốc Dũng <dunglq@yandex.ru>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: dvisvgm,figures,latex,restructuredtext,sphinx,svg,tikz
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Education
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Documentation :: Sphinx
|
|
22
|
+
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
|
|
23
|
+
Classifier: Topic :: Text Processing :: Markup :: LaTeX
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Provides-Extra: jpeg
|
|
26
|
+
Requires-Dist: pdf2image; extra == 'jpeg'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# texshot
|
|
30
|
+
|
|
31
|
+
[Tiếng Việt](#tiếng-việt) · [English](#english) · [Русский](#русский)
|
|
32
|
+
|
|
33
|
+
## Tiếng Việt
|
|
34
|
+
|
|
35
|
+
CLI biên dịch các hình vẽ LaTeX (TikZ, MusiXTeX, ...) ở dạng `standalone` thành SVG để nhúng vào rST/Sphinx, ngoài ra có thể xuất PDF và JPEG.
|
|
36
|
+
|
|
37
|
+
- Mỗi file `.tex` cho ra hình nằm **ngay cạnh** file đó.
|
|
38
|
+
- Hình một trang cho ra `ten.svg`. Hình nhiều trang cho ra `ten-01.svg`, `ten-02.svg`, ..., mỗi trang một file.
|
|
39
|
+
- Các file trung gian (`.aux`, `.log`, `.dvi`, ...) được tạo trong thư mục tạm và tự xoá, không làm bẩn thư mục nội dung.
|
|
40
|
+
|
|
41
|
+
### Yêu cầu
|
|
42
|
+
|
|
43
|
+
- Python 3.9 trở lên. Bản SVG và PDF không cần thư viện ngoài.
|
|
44
|
+
- TeX Live (hoặc MacTeX) có `latex`, `pdflatex`, `lualatex` và `dvisvgm` trong `PATH`.
|
|
45
|
+
- Chỉ khi xuất JPEG: poppler (`brew install poppler` hoặc `apt install poppler-utils`).
|
|
46
|
+
|
|
47
|
+
### Cài đặt
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install texshot # SVG và PDF
|
|
51
|
+
pip install "texshot[jpeg]" # thêm pdf2image để xuất JPEG
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Cách chạy
|
|
55
|
+
|
|
56
|
+
Sau khi cài, dùng lệnh `texshot` (tương đương `python -m texshot`):
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
texshot [tuỳ chọn]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Không chỉ định định dạng thì mặc định chỉ build SVG.
|
|
63
|
+
|
|
64
|
+
| Tuỳ chọn | Ý nghĩa |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `--svg`, `--pdf`, `--jpeg` | Định dạng cần xuất, có thể kết hợp nhiều định dạng. |
|
|
67
|
+
| `-d DIR [DIR ...]` | Build mọi file `.tex` độc lập trong các thư mục này, kể cả thư mục con. |
|
|
68
|
+
| `-c FILE` | File cấu hình dùng khi không có `-d` (mặc định: `figures.json` trong thư mục hiện tại). |
|
|
69
|
+
| `-f`, `--force` | Build lại cả các hình đã cập nhật. |
|
|
70
|
+
| `-j N` | Build song song `N` hình. |
|
|
71
|
+
| `-v` | In toàn bộ output của TeX và `dvisvgm`. |
|
|
72
|
+
| `-V`, `--version` | In phiên bản. |
|
|
73
|
+
|
|
74
|
+
### Chọn file cần build
|
|
75
|
+
|
|
76
|
+
Có hai chế độ.
|
|
77
|
+
|
|
78
|
+
**1. Theo thư mục (`-d`).** Tìm mọi file `.tex` trong thư mục, kể cả thư mục con. Chỉ build những file có `\documentclass`; các file được `\input` vào file khác (không có `\documentclass`) bị bỏ qua.
|
|
79
|
+
|
|
80
|
+
Engine được chọn theo thứ tự:
|
|
81
|
+
|
|
82
|
+
1. dòng chú thích `% !TEX program = lualatex` (hoặc `pdflatex`) ở đầu file;
|
|
83
|
+
2. nếu không có dòng đó: file dùng `fontspec` hoặc `luacode` thì build bằng `lualatex`;
|
|
84
|
+
3. còn lại build bằng `pdflatex`.
|
|
85
|
+
|
|
86
|
+
**2. Theo `figures.json` (không có `-d`).** Đọc `figures.json` trong thư mục hiện tại (hoặc file chỉ định bằng `-c`) và chỉ build các file được liệt kê, với engine ghi trong file cấu hình. Ví dụ [`examples/figures.json`](examples/figures.json):
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"music": {
|
|
91
|
+
"lualatex": ["notes", "octave"]
|
|
92
|
+
},
|
|
93
|
+
"stuff": {
|
|
94
|
+
"pdflatex": ["yinyang"]
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Khoá là thư mục, tính **tương đối so với chính file JSON**. Giá trị ánh xạ engine (`pdflatex` hoặc `lualatex`) sang danh sách tên file, không kèm đuôi `.tex`.
|
|
100
|
+
|
|
101
|
+
### Ví dụ
|
|
102
|
+
|
|
103
|
+
#### Build một hình: `octave.tex`
|
|
104
|
+
|
|
105
|
+
[`examples/music/octave.tex`](examples/music/octave.tex) vẽ một quãng tám Đô–Đô bằng MusiXTeX, kèm lời ca tiếng Việt. Vì cần `fontspec`, file được build bằng `lualatex`:
|
|
106
|
+
|
|
107
|
+
```latex
|
|
108
|
+
% !TEX program = lualatex
|
|
109
|
+
\documentclass[border=2pt]{standalone}
|
|
110
|
+
\usepackage{musixtex}
|
|
111
|
+
\usepackage{fontspec}
|
|
112
|
+
|
|
113
|
+
\begin{document}
|
|
114
|
+
\begin{music}
|
|
115
|
+
\startextract
|
|
116
|
+
\NOTEs\zsong{Đô}\wh{-2} \zsong{Rê}\wh{-1} ... \zsong{Đô}\wh{5}\en
|
|
117
|
+
\zendextract
|
|
118
|
+
\end{music}
|
|
119
|
+
\end{document}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```console
|
|
123
|
+
$ texshot -d examples/music
|
|
124
|
+
built examples/music/notes.tex [lualatex]: notes.svg
|
|
125
|
+
built examples/music/octave.tex [lualatex]: octave.svg
|
|
126
|
+
2/2 figures OK
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Chạy lại khi chưa sửa file `.tex` nào thì các hình được bỏ qua. Dùng `-f` để build lại:
|
|
130
|
+
|
|
131
|
+
```console
|
|
132
|
+
$ texshot -d examples/music
|
|
133
|
+
skipped examples/music/notes.tex [lualatex]: up to date
|
|
134
|
+
skipped examples/music/octave.tex [lualatex]: up to date
|
|
135
|
+
2/2 figures OK
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Xuất thêm PDF cho mọi hình trong `examples/figures.json`:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
cd examples
|
|
142
|
+
texshot --svg --pdf
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Hình nhiều trang
|
|
146
|
+
|
|
147
|
+
Với `\documentclass[tikz]{standalone}`, mỗi `tikzpicture` là một trang. File `univariate.tex` có 10 `tikzpicture` nên cho ra 10 SVG:
|
|
148
|
+
|
|
149
|
+
```console
|
|
150
|
+
$ texshot -d mathematics/algebra/polynomial/figures -j 4
|
|
151
|
+
built mathematics/algebra/polynomial/figures/polynomials/univariate.tex [pdflatex]: univariate-01.svg, univariate-02.svg, ..., univariate-10.svg
|
|
152
|
+
1/1 figures OK
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Nếu hình giảm số trang, chẳng hạn từ 3 xuống 1, các file `ten-NN.svg` cũ sẽ bị xoá trước khi sinh `ten.svg`, nên không còn file thừa.
|
|
156
|
+
|
|
157
|
+
#### Nhúng vào rST
|
|
158
|
+
|
|
159
|
+
Viết đường dẫn **tương đối** từ file rST tới hình và để đuôi là `*`. Sphinx sẽ tự chọn định dạng phù hợp (SVG cho HTML):
|
|
160
|
+
|
|
161
|
+
```rst
|
|
162
|
+
.. figure:: figures/music/octave.*
|
|
163
|
+
|
|
164
|
+
Một quãng tám
|
|
165
|
+
|
|
166
|
+
.. figure:: figures/polynomials/univariate-03.*
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Khi có lỗi
|
|
170
|
+
|
|
171
|
+
Hình lỗi không làm dừng các hình khác. Các dòng lỗi `!` trong log được in ra để dễ sửa:
|
|
172
|
+
|
|
173
|
+
```console
|
|
174
|
+
$ texshot -d drafts
|
|
175
|
+
FAILED drafts/bad.tex [pdflatex]
|
|
176
|
+
latex failed
|
|
177
|
+
! Undefined control sequence.
|
|
178
|
+
l.3 \undefinedcommand
|
|
179
|
+
0/1 figures OK
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Mã thoát: `0` nếu mọi hình thành công, `1` nếu có hình lỗi, `2` nếu tham số hoặc cấu hình sai (thư mục không tồn tại, `figures.json` hỏng, ...).
|
|
183
|
+
|
|
184
|
+
### Lưu ý khi viết hình
|
|
185
|
+
|
|
186
|
+
- Dùng `\documentclass[border=2pt]{standalone}` (thêm option `tikz` nếu mỗi `tikzpicture` là một hình riêng) để hình được cắt sát nội dung.
|
|
187
|
+
- Với MusiXTeX, **không** dùng `crop,preview` vì sẽ cắt mất dòng lời ca, cũng không đặt `varwidth=<độ rộng>` nhỏ hơn khuông nhạc vì sẽ xén mất nốt. Một dòng nhạc ngắn trong `\startextract ... \zendextract` không cần chạy thêm `musixflx`.
|
|
188
|
+
- SVG được dựng qua DVI: `latex` cho hình `pdflatex`, `lualatex --output-format=dvi` cho hình `lualatex`, rồi `dvisvgm --no-fonts`. Chữ được chuyển thành đường vẽ, nên SVG hiển thị đúng mà không cần font trên máy người xem.
|
|
189
|
+
|
|
190
|
+
## English
|
|
191
|
+
|
|
192
|
+
A CLI that compiles `standalone` LaTeX figures (TikZ, MusiXTeX, ...) into SVG for embedding in rST/Sphinx; it can also export PDF and JPEG.
|
|
193
|
+
|
|
194
|
+
- Each `.tex` file produces its figures **next to** the file itself.
|
|
195
|
+
- A one-page figure produces `name.svg`. A multi-page figure produces `name-01.svg`, `name-02.svg`, ..., one file per page.
|
|
196
|
+
- Intermediate files (`.aux`, `.log`, `.dvi`, ...) are created in a temporary directory and removed afterwards, so content directories stay clean.
|
|
197
|
+
|
|
198
|
+
### Requirements
|
|
199
|
+
|
|
200
|
+
- Python 3.9 or newer. SVG and PDF output need no third-party packages.
|
|
201
|
+
- TeX Live (or MacTeX) with `latex`, `pdflatex`, `lualatex` and `dvisvgm` on the `PATH`.
|
|
202
|
+
- For JPEG output only: poppler (`brew install poppler` or `apt install poppler-utils`).
|
|
203
|
+
|
|
204
|
+
### Installation
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
pip install texshot # SVG and PDF
|
|
208
|
+
pip install "texshot[jpeg]" # adds pdf2image for JPEG output
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Usage
|
|
212
|
+
|
|
213
|
+
Once installed, run the `texshot` command (equivalent to `python -m texshot`):
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
texshot [options]
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
If no format is given, only SVG is built.
|
|
220
|
+
|
|
221
|
+
| Option | Meaning |
|
|
222
|
+
|---|---|
|
|
223
|
+
| `--svg`, `--pdf`, `--jpeg` | Output formats; several can be combined. |
|
|
224
|
+
| `-d DIR [DIR ...]` | Build every standalone `.tex` file in these directories, including subdirectories. |
|
|
225
|
+
| `-c FILE` | Configuration file used without `-d` (default: `figures.json` in the current directory). |
|
|
226
|
+
| `-f`, `--force` | Rebuild figures that are already up to date. |
|
|
227
|
+
| `-j N` | Build `N` figures in parallel. |
|
|
228
|
+
| `-v` | Print the full output of TeX and `dvisvgm`. |
|
|
229
|
+
| `-V`, `--version` | Print the version. |
|
|
230
|
+
|
|
231
|
+
### Choosing the files to build
|
|
232
|
+
|
|
233
|
+
There are two modes.
|
|
234
|
+
|
|
235
|
+
**1. By directory (`-d`).** Finds every `.tex` file in the directories, including subdirectories. Only files containing `\documentclass` are built; files pulled into another file with `\input` (which have no `\documentclass`) are skipped.
|
|
236
|
+
|
|
237
|
+
The engine is chosen in this order:
|
|
238
|
+
|
|
239
|
+
1. a magic comment `% !TEX program = lualatex` (or `pdflatex`) at the top of the file;
|
|
240
|
+
2. without it: files using `fontspec` or `luacode` are built with `lualatex`;
|
|
241
|
+
3. everything else is built with `pdflatex`.
|
|
242
|
+
|
|
243
|
+
**2. From `figures.json` (no `-d`).** Reads `figures.json` in the current directory (or the file given with `-c`) and builds only the listed files, with the engine given in the configuration. For example, [`examples/figures.json`](examples/figures.json):
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"music": {
|
|
248
|
+
"lualatex": ["notes", "octave"]
|
|
249
|
+
},
|
|
250
|
+
"stuff": {
|
|
251
|
+
"pdflatex": ["yinyang"]
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Keys are directories, **relative to the JSON file itself**. Values map an engine (`pdflatex` or `lualatex`) to a list of file names without the `.tex` extension.
|
|
257
|
+
|
|
258
|
+
### Examples
|
|
259
|
+
|
|
260
|
+
#### Building one figure: `octave.tex`
|
|
261
|
+
|
|
262
|
+
[`examples/music/octave.tex`](examples/music/octave.tex) draws a C–C octave with MusiXTeX, with Vietnamese solfège lyrics. It needs `fontspec`, so it is built with `lualatex`:
|
|
263
|
+
|
|
264
|
+
```latex
|
|
265
|
+
% !TEX program = lualatex
|
|
266
|
+
\documentclass[border=2pt]{standalone}
|
|
267
|
+
\usepackage{musixtex}
|
|
268
|
+
\usepackage{fontspec}
|
|
269
|
+
|
|
270
|
+
\begin{document}
|
|
271
|
+
\begin{music}
|
|
272
|
+
\startextract
|
|
273
|
+
\NOTEs\zsong{Đô}\wh{-2} \zsong{Rê}\wh{-1} ... \zsong{Đô}\wh{5}\en
|
|
274
|
+
\zendextract
|
|
275
|
+
\end{music}
|
|
276
|
+
\end{document}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
```console
|
|
280
|
+
$ texshot -d examples/music
|
|
281
|
+
built examples/music/notes.tex [lualatex]: notes.svg
|
|
282
|
+
built examples/music/octave.tex [lualatex]: octave.svg
|
|
283
|
+
2/2 figures OK
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Running again without changing any `.tex` file skips the figures. Use `-f` to rebuild them:
|
|
287
|
+
|
|
288
|
+
```console
|
|
289
|
+
$ texshot -d examples/music
|
|
290
|
+
skipped examples/music/notes.tex [lualatex]: up to date
|
|
291
|
+
skipped examples/music/octave.tex [lualatex]: up to date
|
|
292
|
+
2/2 figures OK
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Also export PDF for every figure in `examples/figures.json`:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
cd examples
|
|
299
|
+
texshot --svg --pdf
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
#### Multi-page figures
|
|
303
|
+
|
|
304
|
+
With `\documentclass[tikz]{standalone}`, every `tikzpicture` is a page. `univariate.tex` has 10 `tikzpicture`s, so it produces 10 SVGs:
|
|
305
|
+
|
|
306
|
+
```console
|
|
307
|
+
$ texshot -d mathematics/algebra/polynomial/figures -j 4
|
|
308
|
+
built mathematics/algebra/polynomial/figures/polynomials/univariate.tex [pdflatex]: univariate-01.svg, univariate-02.svg, ..., univariate-10.svg
|
|
309
|
+
1/1 figures OK
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
If a figure loses pages, say from 3 to 1, the old `name-NN.svg` files are removed before `name.svg` is written, so no stale files are left behind.
|
|
313
|
+
|
|
314
|
+
#### Embedding in rST
|
|
315
|
+
|
|
316
|
+
Use a path **relative** to the rST file and the extension `*`. Sphinx picks the right format (SVG for HTML):
|
|
317
|
+
|
|
318
|
+
```rst
|
|
319
|
+
.. figure:: figures/music/octave.*
|
|
320
|
+
|
|
321
|
+
An octave
|
|
322
|
+
|
|
323
|
+
.. figure:: figures/polynomials/univariate-03.*
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
#### Errors
|
|
327
|
+
|
|
328
|
+
A failing figure does not stop the others. The `!` error lines from the log are printed to help fix it:
|
|
329
|
+
|
|
330
|
+
```console
|
|
331
|
+
$ texshot -d drafts
|
|
332
|
+
FAILED drafts/bad.tex [pdflatex]
|
|
333
|
+
latex failed
|
|
334
|
+
! Undefined control sequence.
|
|
335
|
+
l.3 \undefinedcommand
|
|
336
|
+
0/1 figures OK
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Exit codes: `0` if every figure succeeded, `1` if some figure failed, `2` for invalid arguments or configuration (missing directory, broken `figures.json`, ...).
|
|
340
|
+
|
|
341
|
+
### Tips for writing figures
|
|
342
|
+
|
|
343
|
+
- Use `\documentclass[border=2pt]{standalone}` (add the `tikz` option if each `tikzpicture` is a separate figure) so the figure is cropped to its content.
|
|
344
|
+
- With MusiXTeX, do **not** use `crop,preview`, which cuts off the lyrics line, and do not set `varwidth=<width>` narrower than the staff, which clips notes. A short line of music in `\startextract ... \zendextract` does not need an extra `musixflx` run.
|
|
345
|
+
- SVG is produced through DVI: `latex` for `pdflatex` figures, `lualatex --output-format=dvi` for `lualatex` figures, then `dvisvgm --no-fonts`. Text is converted to paths, so the SVG renders correctly without the fonts installed on the viewer's machine.
|
|
346
|
+
|
|
347
|
+
## Русский
|
|
348
|
+
|
|
349
|
+
Утилита командной строки, которая компилирует рисунки LaTeX (TikZ, MusiXTeX, ...) в формате `standalone` в SVG для вставки в rST/Sphinx; также умеет выводить PDF и JPEG.
|
|
350
|
+
|
|
351
|
+
- Каждый файл `.tex` создаёт рисунки **рядом** с самим собой.
|
|
352
|
+
- Одностраничный рисунок даёт `name.svg`. Многостраничный рисунок даёт `name-01.svg`, `name-02.svg`, ..., по одному файлу на страницу.
|
|
353
|
+
- Промежуточные файлы (`.aux`, `.log`, `.dvi`, ...) создаются во временном каталоге и затем удаляются, поэтому каталоги с содержимым остаются чистыми.
|
|
354
|
+
|
|
355
|
+
### Требования
|
|
356
|
+
|
|
357
|
+
- Python 3.9 или новее. Для SVG и PDF сторонние пакеты не нужны.
|
|
358
|
+
- TeX Live (или MacTeX) с `latex`, `pdflatex`, `lualatex` и `dvisvgm` в `PATH`.
|
|
359
|
+
- Только для JPEG: poppler (`brew install poppler` или `apt install poppler-utils`).
|
|
360
|
+
|
|
361
|
+
### Установка
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
pip install texshot # SVG и PDF
|
|
365
|
+
pip install "texshot[jpeg]" # дополнительно pdf2image для JPEG
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Запуск
|
|
369
|
+
|
|
370
|
+
После установки используйте команду `texshot` (равнозначно `python -m texshot`):
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
texshot [параметры]
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Если формат не указан, собирается только SVG.
|
|
377
|
+
|
|
378
|
+
| Параметр | Назначение |
|
|
379
|
+
|---|---|
|
|
380
|
+
| `--svg`, `--pdf`, `--jpeg` | Выходные форматы; можно указать несколько. |
|
|
381
|
+
| `-d DIR [DIR ...]` | Собрать все самостоятельные файлы `.tex` в этих каталогах, включая подкаталоги. |
|
|
382
|
+
| `-c FILE` | Файл конфигурации, используемый без `-d` (по умолчанию `figures.json` в текущем каталоге). |
|
|
383
|
+
| `-f`, `--force` | Пересобрать и актуальные рисунки. |
|
|
384
|
+
| `-j N` | Собирать `N` рисунков параллельно. |
|
|
385
|
+
| `-v` | Выводить полный вывод TeX и `dvisvgm`. |
|
|
386
|
+
| `-V`, `--version` | Показать версию. |
|
|
387
|
+
|
|
388
|
+
### Выбор файлов для сборки
|
|
389
|
+
|
|
390
|
+
Есть два режима.
|
|
391
|
+
|
|
392
|
+
**1. По каталогу (`-d`).** Ищутся все файлы `.tex` в каталогах, включая подкаталоги. Собираются только файлы, содержащие `\documentclass`; файлы, подключаемые в другие через `\input` (без `\documentclass`), пропускаются.
|
|
393
|
+
|
|
394
|
+
Движок выбирается в следующем порядке:
|
|
395
|
+
|
|
396
|
+
1. магический комментарий `% !TEX program = lualatex` (или `pdflatex`) в начале файла;
|
|
397
|
+
2. если его нет: файлы с `fontspec` или `luacode` собираются через `lualatex`;
|
|
398
|
+
3. все остальные — через `pdflatex`.
|
|
399
|
+
|
|
400
|
+
**2. По `figures.json` (без `-d`).** Читается `figures.json` в текущем каталоге (или файл, заданный через `-c`), и собираются только перечисленные в нём файлы с указанным движком. Например, [`examples/figures.json`](examples/figures.json):
|
|
401
|
+
|
|
402
|
+
```json
|
|
403
|
+
{
|
|
404
|
+
"music": {
|
|
405
|
+
"lualatex": ["notes", "octave"]
|
|
406
|
+
},
|
|
407
|
+
"stuff": {
|
|
408
|
+
"pdflatex": ["yinyang"]
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Ключи — это каталоги, **относительно самого файла JSON**. Значения сопоставляют движку (`pdflatex` или `lualatex`) список имён файлов без расширения `.tex`.
|
|
414
|
+
|
|
415
|
+
### Примеры
|
|
416
|
+
|
|
417
|
+
#### Сборка одного рисунка: `octave.tex`
|
|
418
|
+
|
|
419
|
+
[`examples/music/octave.tex`](examples/music/octave.tex) рисует октаву до–до средствами MusiXTeX с подписями нот на вьетнамском. Файлу нужен `fontspec`, поэтому он собирается через `lualatex`:
|
|
420
|
+
|
|
421
|
+
```latex
|
|
422
|
+
% !TEX program = lualatex
|
|
423
|
+
\documentclass[border=2pt]{standalone}
|
|
424
|
+
\usepackage{musixtex}
|
|
425
|
+
\usepackage{fontspec}
|
|
426
|
+
|
|
427
|
+
\begin{document}
|
|
428
|
+
\begin{music}
|
|
429
|
+
\startextract
|
|
430
|
+
\NOTEs\zsong{Đô}\wh{-2} \zsong{Rê}\wh{-1} ... \zsong{Đô}\wh{5}\en
|
|
431
|
+
\zendextract
|
|
432
|
+
\end{music}
|
|
433
|
+
\end{document}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
```console
|
|
437
|
+
$ texshot -d examples/music
|
|
438
|
+
built examples/music/notes.tex [lualatex]: notes.svg
|
|
439
|
+
built examples/music/octave.tex [lualatex]: octave.svg
|
|
440
|
+
2/2 figures OK
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
При повторном запуске без изменений в файлах `.tex` рисунки пропускаются. Для пересборки используйте `-f`:
|
|
444
|
+
|
|
445
|
+
```console
|
|
446
|
+
$ texshot -d examples/music
|
|
447
|
+
skipped examples/music/notes.tex [lualatex]: up to date
|
|
448
|
+
skipped examples/music/octave.tex [lualatex]: up to date
|
|
449
|
+
2/2 figures OK
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Дополнительно вывести PDF для всех рисунков из `examples/figures.json`:
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
cd examples
|
|
456
|
+
texshot --svg --pdf
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
#### Многостраничные рисунки
|
|
460
|
+
|
|
461
|
+
При `\documentclass[tikz]{standalone}` каждый `tikzpicture` — отдельная страница. В `univariate.tex` 10 окружений `tikzpicture`, поэтому получается 10 файлов SVG:
|
|
462
|
+
|
|
463
|
+
```console
|
|
464
|
+
$ texshot -d mathematics/algebra/polynomial/figures -j 4
|
|
465
|
+
built mathematics/algebra/polynomial/figures/polynomials/univariate.tex [pdflatex]: univariate-01.svg, univariate-02.svg, ..., univariate-10.svg
|
|
466
|
+
1/1 figures OK
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
Если у рисунка стало меньше страниц, например 1 вместо 3, старые файлы `name-NN.svg` удаляются перед созданием `name.svg`, так что устаревших файлов не остаётся.
|
|
470
|
+
|
|
471
|
+
#### Вставка в rST
|
|
472
|
+
|
|
473
|
+
Укажите путь **относительно** файла rST и расширение `*`. Sphinx сам выберет подходящий формат (SVG для HTML):
|
|
474
|
+
|
|
475
|
+
```rst
|
|
476
|
+
.. figure:: figures/music/octave.*
|
|
477
|
+
|
|
478
|
+
Октава
|
|
479
|
+
|
|
480
|
+
.. figure:: figures/polynomials/univariate-03.*
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
#### Ошибки
|
|
484
|
+
|
|
485
|
+
Ошибка в одном рисунке не останавливает сборку остальных. Строки ошибок `!` из журнала выводятся, чтобы их было проще исправить:
|
|
486
|
+
|
|
487
|
+
```console
|
|
488
|
+
$ texshot -d drafts
|
|
489
|
+
FAILED drafts/bad.tex [pdflatex]
|
|
490
|
+
latex failed
|
|
491
|
+
! Undefined control sequence.
|
|
492
|
+
l.3 \undefinedcommand
|
|
493
|
+
0/1 figures OK
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
Коды возврата: `0`, если все рисунки собраны успешно; `1`, если какой-то рисунок не собрался; `2` при неверных аргументах или конфигурации (несуществующий каталог, повреждённый `figures.json`, ...).
|
|
497
|
+
|
|
498
|
+
### Советы по подготовке рисунков
|
|
499
|
+
|
|
500
|
+
- Используйте `\documentclass[border=2pt]{standalone}` (добавьте опцию `tikz`, если каждый `tikzpicture` — отдельный рисунок), чтобы рисунок обрезался по содержимому.
|
|
501
|
+
- С MusiXTeX **не** используйте `crop,preview`: это обрезает строку с текстом под нотами. Также не задавайте `varwidth=<ширина>` меньше ширины нотного стана: это срезает ноты. Короткой строке нот в `\startextract ... \zendextract` дополнительный запуск `musixflx` не нужен.
|
|
502
|
+
- SVG строится через DVI: `latex` для рисунков `pdflatex`, `lualatex --output-format=dvi` для рисунков `lualatex`, затем `dvisvgm --no-fonts`. Текст превращается в контуры, поэтому SVG отображается правильно без установленных шрифтов на компьютере читателя.
|