typsphinx 0.3.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.
- typsphinx-0.3.0/LICENSE +21 -0
- typsphinx-0.3.0/PKG-INFO +355 -0
- typsphinx-0.3.0/README.md +310 -0
- typsphinx-0.3.0/pyproject.toml +136 -0
- typsphinx-0.3.0/setup.cfg +4 -0
- typsphinx-0.3.0/tests/test_admonitions.py +217 -0
- typsphinx-0.3.0/tests/test_builder.py +175 -0
- typsphinx-0.3.0/tests/test_builder_requirement13.py +204 -0
- typsphinx-0.3.0/tests/test_config.py +156 -0
- typsphinx-0.3.0/tests/test_config_other_options.py +240 -0
- typsphinx-0.3.0/tests/test_config_template_mapping.py +240 -0
- typsphinx-0.3.0/tests/test_config_toctree_defaults.py +249 -0
- typsphinx-0.3.0/tests/test_documentation_configuration.py +155 -0
- typsphinx-0.3.0/tests/test_documentation_installation.py +143 -0
- typsphinx-0.3.0/tests/test_documentation_usage.py +152 -0
- typsphinx-0.3.0/tests/test_entry_points.py +60 -0
- typsphinx-0.3.0/tests/test_examples_basic.py +197 -0
- typsphinx-0.3.0/tests/test_extension.py +76 -0
- typsphinx-0.3.0/tests/test_inline_references.py +188 -0
- typsphinx-0.3.0/tests/test_integration_advanced.py +311 -0
- typsphinx-0.3.0/tests/test_integration_basic.py +287 -0
- typsphinx-0.3.0/tests/test_integration_multi_doc.py +244 -0
- typsphinx-0.3.0/tests/test_integration_nested_toctree.py +455 -0
- typsphinx-0.3.0/tests/test_math_fallback.py +248 -0
- typsphinx-0.3.0/tests/test_math_mitex.py +269 -0
- typsphinx-0.3.0/tests/test_math_native.py +195 -0
- typsphinx-0.3.0/tests/test_nested_toctree_paths.py +254 -0
- typsphinx-0.3.0/tests/test_pdf_generation.py +377 -0
- typsphinx-0.3.0/tests/test_template_codly.py +144 -0
- typsphinx-0.3.0/tests/test_template_engine.py +574 -0
- typsphinx-0.3.0/tests/test_template_mitex.py +62 -0
- typsphinx-0.3.0/tests/test_toctree_requirement13.py +340 -0
- typsphinx-0.3.0/tests/test_translator.py +2072 -0
- typsphinx-0.3.0/typsphinx/__init__.py +58 -0
- typsphinx-0.3.0/typsphinx/builder.py +322 -0
- typsphinx-0.3.0/typsphinx/pdf.py +192 -0
- typsphinx-0.3.0/typsphinx/template_engine.py +396 -0
- typsphinx-0.3.0/typsphinx/templates/base.typ +81 -0
- typsphinx-0.3.0/typsphinx/translator.py +1583 -0
- typsphinx-0.3.0/typsphinx/writer.py +144 -0
- typsphinx-0.3.0/typsphinx.egg-info/PKG-INFO +355 -0
- typsphinx-0.3.0/typsphinx.egg-info/SOURCES.txt +44 -0
- typsphinx-0.3.0/typsphinx.egg-info/dependency_links.txt +1 -0
- typsphinx-0.3.0/typsphinx.egg-info/entry_points.txt +3 -0
- typsphinx-0.3.0/typsphinx.egg-info/requires.txt +21 -0
- typsphinx-0.3.0/typsphinx.egg-info/top_level.txt +1 -0
typsphinx-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 YuSabo90002
|
|
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.
|
typsphinx-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: typsphinx
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Sphinx extension for Typst output
|
|
5
|
+
Author-email: Sphinx Typst Contributors <noreply@example.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/YuSabo90002/typsphinx
|
|
8
|
+
Project-URL: Documentation, https://github.com/YuSabo90002/typsphinx#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/YuSabo90002/typsphinx
|
|
10
|
+
Project-URL: Issues, https://github.com/YuSabo90002/typsphinx/issues
|
|
11
|
+
Keywords: sphinx,typst,documentation,pdf
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Framework :: Sphinx :: Extension
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
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: Topic :: Documentation :: Sphinx
|
|
21
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: sphinx>=5.0
|
|
26
|
+
Requires-Dist: docutils>=0.18
|
|
27
|
+
Requires-Dist: typst>=0.11.1
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
31
|
+
Requires-Dist: tox>=4.0; extra == "dev"
|
|
32
|
+
Requires-Dist: tox-uv>=1.0; extra == "dev"
|
|
33
|
+
Requires-Dist: black>=23.0; extra == "dev"
|
|
34
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
36
|
+
Requires-Dist: sphinx-testing>=1.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pre-commit>=3.0; extra == "dev"
|
|
38
|
+
Requires-Dist: types-docutils>=0.18; extra == "dev"
|
|
39
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
40
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
41
|
+
Provides-Extra: docs
|
|
42
|
+
Requires-Dist: sphinx-rtd-theme>=2.0; extra == "docs"
|
|
43
|
+
Requires-Dist: sphinx-autodoc-typehints>=1.0; extra == "docs"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# typsphinx
|
|
47
|
+
|
|
48
|
+
[](https://badge.fury.io/py/typsphinx)
|
|
49
|
+
[](https://pypi.org/project/typsphinx/)
|
|
50
|
+
[](https://opensource.org/licenses/MIT)
|
|
51
|
+
[](https://github.com/psf/black)
|
|
52
|
+
|
|
53
|
+
Sphinx extension for Typst output format support.
|
|
54
|
+
|
|
55
|
+
## Overview
|
|
56
|
+
|
|
57
|
+
typsphinx is a Sphinx extension that enables generating Typst documents from reStructuredText sources. Typst is a modern typesetting system designed as an alternative to LaTeX, offering faster compilation and a more intuitive syntax.
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- **Convert Sphinx documentation to Typst format**: Seamlessly transform your reStructuredText/Markdown documents
|
|
62
|
+
- **Standard docutils nodes**: Full support for paragraphs, sections, lists, tables, admonitions, and more
|
|
63
|
+
- **Mathematical expressions**:
|
|
64
|
+
- LaTeX syntax via mitex (`@preview/mitex:0.2.4`)
|
|
65
|
+
- Native Typst math syntax
|
|
66
|
+
- **Code blocks with syntax highlighting**: Using codly package (`@preview/codly:1.3.0`)
|
|
67
|
+
- Automatic line numbering
|
|
68
|
+
- Syntax highlighting for multiple languages
|
|
69
|
+
- Highlight specific lines
|
|
70
|
+
- **Images and figures**: Embed images with captions and references
|
|
71
|
+
- **Cross-references and citations**: Maintain document structure with internal links
|
|
72
|
+
- **Customizable templates**: Use default or custom Typst templates
|
|
73
|
+
- **Direct PDF generation**: Self-contained PDF generation via typst-py (no external Typst CLI required)
|
|
74
|
+
- **Multi-document support**: Generate multiple Typst files with toctree integration using `#include()`
|
|
75
|
+
|
|
76
|
+
## Requirements
|
|
77
|
+
|
|
78
|
+
- Python 3.9 or higher
|
|
79
|
+
- Sphinx 5.0 or higher
|
|
80
|
+
- typst-py 0.11.1 or higher
|
|
81
|
+
|
|
82
|
+
## Installation
|
|
83
|
+
|
|
84
|
+
### From PyPI (Beta Release)
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install typsphinx
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Using uv (recommended for development)
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Clone the repository
|
|
94
|
+
git clone https://github.com/YuSabo90002/typsphinx.git
|
|
95
|
+
cd typsphinx
|
|
96
|
+
|
|
97
|
+
# Install dependencies with uv
|
|
98
|
+
uv sync
|
|
99
|
+
|
|
100
|
+
# For development dependencies
|
|
101
|
+
uv sync --extra dev
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Quick Start
|
|
105
|
+
|
|
106
|
+
### Basic Configuration
|
|
107
|
+
|
|
108
|
+
Configure Typst output in your `conf.py`:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
# conf.py
|
|
112
|
+
|
|
113
|
+
# Note: typsphinx is auto-discovered via entry points.
|
|
114
|
+
# Adding to extensions list is optional but recommended for clarity.
|
|
115
|
+
# extensions = ['typsphinx']
|
|
116
|
+
|
|
117
|
+
# Optional: Configure Typst builder
|
|
118
|
+
typst_use_mitex = True # Use mitex for LaTeX math (default: True)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Build Typst Output
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Generate Typst files
|
|
125
|
+
sphinx-build -b typst source build/typst
|
|
126
|
+
|
|
127
|
+
# Generate PDF directly
|
|
128
|
+
sphinx-build -b typstpdf source build/pdf
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Example Document
|
|
132
|
+
|
|
133
|
+
Create a simple reStructuredText document:
|
|
134
|
+
|
|
135
|
+
```rst
|
|
136
|
+
==============
|
|
137
|
+
My Document
|
|
138
|
+
==============
|
|
139
|
+
|
|
140
|
+
This is a paragraph with **bold** and *italic* text.
|
|
141
|
+
|
|
142
|
+
Math Example
|
|
143
|
+
============
|
|
144
|
+
|
|
145
|
+
Inline math: :math:`E = mc^2`
|
|
146
|
+
|
|
147
|
+
Block math:
|
|
148
|
+
|
|
149
|
+
.. math::
|
|
150
|
+
|
|
151
|
+
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
|
|
152
|
+
|
|
153
|
+
Code Example
|
|
154
|
+
============
|
|
155
|
+
|
|
156
|
+
.. code-block:: python
|
|
157
|
+
|
|
158
|
+
def hello_world():
|
|
159
|
+
print("Hello, Typst!")
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
This will generate a Typst file with:
|
|
163
|
+
- Proper heading hierarchy
|
|
164
|
+
- Formatted text with emphasis
|
|
165
|
+
- LaTeX math via mitex (or native Typst math)
|
|
166
|
+
- Syntax-highlighted code blocks with codly
|
|
167
|
+
|
|
168
|
+
## Advanced Usage
|
|
169
|
+
|
|
170
|
+
### Custom Templates
|
|
171
|
+
|
|
172
|
+
Create a custom Typst template:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
# conf.py
|
|
176
|
+
typst_template = '_templates/custom.typ'
|
|
177
|
+
|
|
178
|
+
typst_elements = {
|
|
179
|
+
'papersize': 'a4',
|
|
180
|
+
'fontsize': '11pt',
|
|
181
|
+
'lang': 'ja',
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Template Parameter Mapping
|
|
186
|
+
|
|
187
|
+
Map Sphinx metadata to template parameters:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
# conf.py
|
|
191
|
+
typst_template_mapping = {
|
|
192
|
+
'title': 'project',
|
|
193
|
+
'authors': ['author'],
|
|
194
|
+
'date': 'release',
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Multi-Document Projects
|
|
199
|
+
|
|
200
|
+
Use toctree to combine multiple documents:
|
|
201
|
+
|
|
202
|
+
```rst
|
|
203
|
+
.. toctree::
|
|
204
|
+
:maxdepth: 2
|
|
205
|
+
:numbered:
|
|
206
|
+
|
|
207
|
+
intro
|
|
208
|
+
chapter1
|
|
209
|
+
chapter2
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
This generates `#include()` directives in Typst with proper heading level adjustments.
|
|
213
|
+
|
|
214
|
+
### Working with Third-Party Extensions
|
|
215
|
+
|
|
216
|
+
typsphinx integrates with Sphinx's standard extension mechanism. For custom nodes from third-party extensions (e.g., sphinxcontrib-mermaid), you can register Typst handlers in your `conf.py`:
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
# conf.py
|
|
220
|
+
def setup(app):
|
|
221
|
+
# Example: Support sphinxcontrib-mermaid diagrams
|
|
222
|
+
if 'sphinxcontrib.mermaid' in app.config.extensions:
|
|
223
|
+
from sphinxcontrib.mermaid import mermaid
|
|
224
|
+
from docutils import nodes
|
|
225
|
+
|
|
226
|
+
def typst_visit_mermaid(self, node):
|
|
227
|
+
"""Render Mermaid diagram as image in Typst output"""
|
|
228
|
+
# Export diagram as SVG and include in Typst
|
|
229
|
+
diagram_path = f"diagrams/{node['name']}.svg"
|
|
230
|
+
self.add_text(f'#image("{diagram_path}")\n\n')
|
|
231
|
+
raise nodes.SkipNode
|
|
232
|
+
|
|
233
|
+
# Register with Sphinx's standard API
|
|
234
|
+
app.add_node(mermaid, typst=(typst_visit_mermaid, None))
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**How it works**:
|
|
238
|
+
- typsphinx uses Sphinx's standard `app.add_node()` API (no custom registry needed)
|
|
239
|
+
- Unknown nodes trigger `unknown_visit()` which logs a warning and extracts text content
|
|
240
|
+
- Users can add Typst support for any extension by registering handlers in `conf.py`
|
|
241
|
+
|
|
242
|
+
For more details, see the [Sphinx Extension API documentation](https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_node).
|
|
243
|
+
|
|
244
|
+
## Configuration Options
|
|
245
|
+
|
|
246
|
+
See [docs/configuration.rst](docs/configuration.rst) for all available configuration options:
|
|
247
|
+
|
|
248
|
+
- `typst_use_mitex`: Enable/disable mitex for LaTeX math
|
|
249
|
+
- `typst_template`: Custom template path
|
|
250
|
+
- `typst_elements`: Template parameters (paper size, fonts, etc.)
|
|
251
|
+
- `typst_template_mapping`: Sphinx metadata to template parameter mapping
|
|
252
|
+
- `typst_toctree_defaults`: Default toctree options
|
|
253
|
+
|
|
254
|
+
## Development
|
|
255
|
+
|
|
256
|
+
This project uses uv for fast package management and follows TDD (Test-Driven Development) practices.
|
|
257
|
+
|
|
258
|
+
### Setup Development Environment
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Install with development dependencies
|
|
262
|
+
uv sync --extra dev
|
|
263
|
+
|
|
264
|
+
# Run tests (286 tests, 93% coverage)
|
|
265
|
+
uv run pytest
|
|
266
|
+
|
|
267
|
+
# Run tests with coverage report
|
|
268
|
+
uv run pytest --cov=typsphinx --cov-report=html
|
|
269
|
+
|
|
270
|
+
# Run tests across multiple Python versions
|
|
271
|
+
uv run tox
|
|
272
|
+
|
|
273
|
+
# Run linters
|
|
274
|
+
uv run black .
|
|
275
|
+
uv run ruff check .
|
|
276
|
+
uv run mypy sphinxcontrib/
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Testing Strategy
|
|
280
|
+
|
|
281
|
+
- **Unit tests**: 286 tests covering all major components
|
|
282
|
+
- **Integration tests**: Full build process validation
|
|
283
|
+
- **Example projects**: `examples/basic/` and `examples/advanced/`
|
|
284
|
+
- **Code coverage**: 93% overall
|
|
285
|
+
|
|
286
|
+
### Project Structure
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
typsphinx/
|
|
290
|
+
├── sphinxcontrib/typst/ # Main package
|
|
291
|
+
│ ├── builder.py # Typst builder
|
|
292
|
+
│ ├── writer.py # Doctree writer
|
|
293
|
+
│ ├── translator.py # Node translator
|
|
294
|
+
│ ├── template_engine.py # Template processor
|
|
295
|
+
│ ├── pdf.py # PDF generation
|
|
296
|
+
│ └── templates/ # Default templates
|
|
297
|
+
├── tests/ # Test suite
|
|
298
|
+
├── docs/ # Documentation
|
|
299
|
+
├── examples/ # Example projects
|
|
300
|
+
└── pyproject.toml # Project configuration
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Known Limitations (v0.2.0)
|
|
304
|
+
|
|
305
|
+
- **Bibliography**: BibTeX integration not yet supported
|
|
306
|
+
- **Glossary**: Glossary generation not yet supported
|
|
307
|
+
|
|
308
|
+
See full requirements verification in project documentation.
|
|
309
|
+
|
|
310
|
+
## Documentation
|
|
311
|
+
|
|
312
|
+
- [Installation Guide](docs/installation.rst)
|
|
313
|
+
- [Usage Guide](docs/usage.rst)
|
|
314
|
+
- [Configuration Reference](docs/configuration.rst)
|
|
315
|
+
- [Examples](examples/)
|
|
316
|
+
|
|
317
|
+
## Contributing
|
|
318
|
+
|
|
319
|
+
Contributions are welcome! Please:
|
|
320
|
+
|
|
321
|
+
1. Fork the repository
|
|
322
|
+
2. Create a feature branch
|
|
323
|
+
3. Write tests for new features
|
|
324
|
+
4. Ensure all tests pass: `uv run pytest`
|
|
325
|
+
5. Submit a pull request
|
|
326
|
+
|
|
327
|
+
### Development Guidelines
|
|
328
|
+
|
|
329
|
+
- Follow TDD (Test-Driven Development)
|
|
330
|
+
- Maintain 80%+ code coverage
|
|
331
|
+
- Use black for code formatting
|
|
332
|
+
- Follow Sphinx extension conventions
|
|
333
|
+
- Add tests for all new features
|
|
334
|
+
|
|
335
|
+
## License
|
|
336
|
+
|
|
337
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
338
|
+
|
|
339
|
+
## Acknowledgments
|
|
340
|
+
|
|
341
|
+
- Built on top of [Sphinx](https://www.sphinx-doc.org/)
|
|
342
|
+
- Uses [Typst](https://typst.app/) for typesetting
|
|
343
|
+
- Integrates [mitex](https://github.com/mitex-rs/mitex) for LaTeX math
|
|
344
|
+
- Uses [codly](https://typst.app/universe/package/codly) for code highlighting
|
|
345
|
+
- Uses [gentle-clues](https://typst.app/universe/package/gentle-clues) for admonitions
|
|
346
|
+
- Developed with [Claude Code](https://claude.ai/code) and Kiro-style Spec-Driven Development
|
|
347
|
+
|
|
348
|
+
## Version History
|
|
349
|
+
|
|
350
|
+
See [CHANGELOG.md](CHANGELOG.md) for detailed version history.
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
**Status**: Stable (v0.2.2) - Production ready
|
|
355
|
+
**Python**: 3.9+ | **Sphinx**: 5.0+ | **Typst**: 0.11.1+
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# typsphinx
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/typsphinx)
|
|
4
|
+
[](https://pypi.org/project/typsphinx/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://github.com/psf/black)
|
|
7
|
+
|
|
8
|
+
Sphinx extension for Typst output format support.
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
typsphinx is a Sphinx extension that enables generating Typst documents from reStructuredText sources. Typst is a modern typesetting system designed as an alternative to LaTeX, offering faster compilation and a more intuitive syntax.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Convert Sphinx documentation to Typst format**: Seamlessly transform your reStructuredText/Markdown documents
|
|
17
|
+
- **Standard docutils nodes**: Full support for paragraphs, sections, lists, tables, admonitions, and more
|
|
18
|
+
- **Mathematical expressions**:
|
|
19
|
+
- LaTeX syntax via mitex (`@preview/mitex:0.2.4`)
|
|
20
|
+
- Native Typst math syntax
|
|
21
|
+
- **Code blocks with syntax highlighting**: Using codly package (`@preview/codly:1.3.0`)
|
|
22
|
+
- Automatic line numbering
|
|
23
|
+
- Syntax highlighting for multiple languages
|
|
24
|
+
- Highlight specific lines
|
|
25
|
+
- **Images and figures**: Embed images with captions and references
|
|
26
|
+
- **Cross-references and citations**: Maintain document structure with internal links
|
|
27
|
+
- **Customizable templates**: Use default or custom Typst templates
|
|
28
|
+
- **Direct PDF generation**: Self-contained PDF generation via typst-py (no external Typst CLI required)
|
|
29
|
+
- **Multi-document support**: Generate multiple Typst files with toctree integration using `#include()`
|
|
30
|
+
|
|
31
|
+
## Requirements
|
|
32
|
+
|
|
33
|
+
- Python 3.9 or higher
|
|
34
|
+
- Sphinx 5.0 or higher
|
|
35
|
+
- typst-py 0.11.1 or higher
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
### From PyPI (Beta Release)
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install typsphinx
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Using uv (recommended for development)
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Clone the repository
|
|
49
|
+
git clone https://github.com/YuSabo90002/typsphinx.git
|
|
50
|
+
cd typsphinx
|
|
51
|
+
|
|
52
|
+
# Install dependencies with uv
|
|
53
|
+
uv sync
|
|
54
|
+
|
|
55
|
+
# For development dependencies
|
|
56
|
+
uv sync --extra dev
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
### Basic Configuration
|
|
62
|
+
|
|
63
|
+
Configure Typst output in your `conf.py`:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
# conf.py
|
|
67
|
+
|
|
68
|
+
# Note: typsphinx is auto-discovered via entry points.
|
|
69
|
+
# Adding to extensions list is optional but recommended for clarity.
|
|
70
|
+
# extensions = ['typsphinx']
|
|
71
|
+
|
|
72
|
+
# Optional: Configure Typst builder
|
|
73
|
+
typst_use_mitex = True # Use mitex for LaTeX math (default: True)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Build Typst Output
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Generate Typst files
|
|
80
|
+
sphinx-build -b typst source build/typst
|
|
81
|
+
|
|
82
|
+
# Generate PDF directly
|
|
83
|
+
sphinx-build -b typstpdf source build/pdf
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Example Document
|
|
87
|
+
|
|
88
|
+
Create a simple reStructuredText document:
|
|
89
|
+
|
|
90
|
+
```rst
|
|
91
|
+
==============
|
|
92
|
+
My Document
|
|
93
|
+
==============
|
|
94
|
+
|
|
95
|
+
This is a paragraph with **bold** and *italic* text.
|
|
96
|
+
|
|
97
|
+
Math Example
|
|
98
|
+
============
|
|
99
|
+
|
|
100
|
+
Inline math: :math:`E = mc^2`
|
|
101
|
+
|
|
102
|
+
Block math:
|
|
103
|
+
|
|
104
|
+
.. math::
|
|
105
|
+
|
|
106
|
+
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
|
|
107
|
+
|
|
108
|
+
Code Example
|
|
109
|
+
============
|
|
110
|
+
|
|
111
|
+
.. code-block:: python
|
|
112
|
+
|
|
113
|
+
def hello_world():
|
|
114
|
+
print("Hello, Typst!")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This will generate a Typst file with:
|
|
118
|
+
- Proper heading hierarchy
|
|
119
|
+
- Formatted text with emphasis
|
|
120
|
+
- LaTeX math via mitex (or native Typst math)
|
|
121
|
+
- Syntax-highlighted code blocks with codly
|
|
122
|
+
|
|
123
|
+
## Advanced Usage
|
|
124
|
+
|
|
125
|
+
### Custom Templates
|
|
126
|
+
|
|
127
|
+
Create a custom Typst template:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
# conf.py
|
|
131
|
+
typst_template = '_templates/custom.typ'
|
|
132
|
+
|
|
133
|
+
typst_elements = {
|
|
134
|
+
'papersize': 'a4',
|
|
135
|
+
'fontsize': '11pt',
|
|
136
|
+
'lang': 'ja',
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Template Parameter Mapping
|
|
141
|
+
|
|
142
|
+
Map Sphinx metadata to template parameters:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
# conf.py
|
|
146
|
+
typst_template_mapping = {
|
|
147
|
+
'title': 'project',
|
|
148
|
+
'authors': ['author'],
|
|
149
|
+
'date': 'release',
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Multi-Document Projects
|
|
154
|
+
|
|
155
|
+
Use toctree to combine multiple documents:
|
|
156
|
+
|
|
157
|
+
```rst
|
|
158
|
+
.. toctree::
|
|
159
|
+
:maxdepth: 2
|
|
160
|
+
:numbered:
|
|
161
|
+
|
|
162
|
+
intro
|
|
163
|
+
chapter1
|
|
164
|
+
chapter2
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
This generates `#include()` directives in Typst with proper heading level adjustments.
|
|
168
|
+
|
|
169
|
+
### Working with Third-Party Extensions
|
|
170
|
+
|
|
171
|
+
typsphinx integrates with Sphinx's standard extension mechanism. For custom nodes from third-party extensions (e.g., sphinxcontrib-mermaid), you can register Typst handlers in your `conf.py`:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
# conf.py
|
|
175
|
+
def setup(app):
|
|
176
|
+
# Example: Support sphinxcontrib-mermaid diagrams
|
|
177
|
+
if 'sphinxcontrib.mermaid' in app.config.extensions:
|
|
178
|
+
from sphinxcontrib.mermaid import mermaid
|
|
179
|
+
from docutils import nodes
|
|
180
|
+
|
|
181
|
+
def typst_visit_mermaid(self, node):
|
|
182
|
+
"""Render Mermaid diagram as image in Typst output"""
|
|
183
|
+
# Export diagram as SVG and include in Typst
|
|
184
|
+
diagram_path = f"diagrams/{node['name']}.svg"
|
|
185
|
+
self.add_text(f'#image("{diagram_path}")\n\n')
|
|
186
|
+
raise nodes.SkipNode
|
|
187
|
+
|
|
188
|
+
# Register with Sphinx's standard API
|
|
189
|
+
app.add_node(mermaid, typst=(typst_visit_mermaid, None))
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**How it works**:
|
|
193
|
+
- typsphinx uses Sphinx's standard `app.add_node()` API (no custom registry needed)
|
|
194
|
+
- Unknown nodes trigger `unknown_visit()` which logs a warning and extracts text content
|
|
195
|
+
- Users can add Typst support for any extension by registering handlers in `conf.py`
|
|
196
|
+
|
|
197
|
+
For more details, see the [Sphinx Extension API documentation](https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_node).
|
|
198
|
+
|
|
199
|
+
## Configuration Options
|
|
200
|
+
|
|
201
|
+
See [docs/configuration.rst](docs/configuration.rst) for all available configuration options:
|
|
202
|
+
|
|
203
|
+
- `typst_use_mitex`: Enable/disable mitex for LaTeX math
|
|
204
|
+
- `typst_template`: Custom template path
|
|
205
|
+
- `typst_elements`: Template parameters (paper size, fonts, etc.)
|
|
206
|
+
- `typst_template_mapping`: Sphinx metadata to template parameter mapping
|
|
207
|
+
- `typst_toctree_defaults`: Default toctree options
|
|
208
|
+
|
|
209
|
+
## Development
|
|
210
|
+
|
|
211
|
+
This project uses uv for fast package management and follows TDD (Test-Driven Development) practices.
|
|
212
|
+
|
|
213
|
+
### Setup Development Environment
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
# Install with development dependencies
|
|
217
|
+
uv sync --extra dev
|
|
218
|
+
|
|
219
|
+
# Run tests (286 tests, 93% coverage)
|
|
220
|
+
uv run pytest
|
|
221
|
+
|
|
222
|
+
# Run tests with coverage report
|
|
223
|
+
uv run pytest --cov=typsphinx --cov-report=html
|
|
224
|
+
|
|
225
|
+
# Run tests across multiple Python versions
|
|
226
|
+
uv run tox
|
|
227
|
+
|
|
228
|
+
# Run linters
|
|
229
|
+
uv run black .
|
|
230
|
+
uv run ruff check .
|
|
231
|
+
uv run mypy sphinxcontrib/
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Testing Strategy
|
|
235
|
+
|
|
236
|
+
- **Unit tests**: 286 tests covering all major components
|
|
237
|
+
- **Integration tests**: Full build process validation
|
|
238
|
+
- **Example projects**: `examples/basic/` and `examples/advanced/`
|
|
239
|
+
- **Code coverage**: 93% overall
|
|
240
|
+
|
|
241
|
+
### Project Structure
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
typsphinx/
|
|
245
|
+
├── sphinxcontrib/typst/ # Main package
|
|
246
|
+
│ ├── builder.py # Typst builder
|
|
247
|
+
│ ├── writer.py # Doctree writer
|
|
248
|
+
│ ├── translator.py # Node translator
|
|
249
|
+
│ ├── template_engine.py # Template processor
|
|
250
|
+
│ ├── pdf.py # PDF generation
|
|
251
|
+
│ └── templates/ # Default templates
|
|
252
|
+
├── tests/ # Test suite
|
|
253
|
+
├── docs/ # Documentation
|
|
254
|
+
├── examples/ # Example projects
|
|
255
|
+
└── pyproject.toml # Project configuration
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Known Limitations (v0.2.0)
|
|
259
|
+
|
|
260
|
+
- **Bibliography**: BibTeX integration not yet supported
|
|
261
|
+
- **Glossary**: Glossary generation not yet supported
|
|
262
|
+
|
|
263
|
+
See full requirements verification in project documentation.
|
|
264
|
+
|
|
265
|
+
## Documentation
|
|
266
|
+
|
|
267
|
+
- [Installation Guide](docs/installation.rst)
|
|
268
|
+
- [Usage Guide](docs/usage.rst)
|
|
269
|
+
- [Configuration Reference](docs/configuration.rst)
|
|
270
|
+
- [Examples](examples/)
|
|
271
|
+
|
|
272
|
+
## Contributing
|
|
273
|
+
|
|
274
|
+
Contributions are welcome! Please:
|
|
275
|
+
|
|
276
|
+
1. Fork the repository
|
|
277
|
+
2. Create a feature branch
|
|
278
|
+
3. Write tests for new features
|
|
279
|
+
4. Ensure all tests pass: `uv run pytest`
|
|
280
|
+
5. Submit a pull request
|
|
281
|
+
|
|
282
|
+
### Development Guidelines
|
|
283
|
+
|
|
284
|
+
- Follow TDD (Test-Driven Development)
|
|
285
|
+
- Maintain 80%+ code coverage
|
|
286
|
+
- Use black for code formatting
|
|
287
|
+
- Follow Sphinx extension conventions
|
|
288
|
+
- Add tests for all new features
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
293
|
+
|
|
294
|
+
## Acknowledgments
|
|
295
|
+
|
|
296
|
+
- Built on top of [Sphinx](https://www.sphinx-doc.org/)
|
|
297
|
+
- Uses [Typst](https://typst.app/) for typesetting
|
|
298
|
+
- Integrates [mitex](https://github.com/mitex-rs/mitex) for LaTeX math
|
|
299
|
+
- Uses [codly](https://typst.app/universe/package/codly) for code highlighting
|
|
300
|
+
- Uses [gentle-clues](https://typst.app/universe/package/gentle-clues) for admonitions
|
|
301
|
+
- Developed with [Claude Code](https://claude.ai/code) and Kiro-style Spec-Driven Development
|
|
302
|
+
|
|
303
|
+
## Version History
|
|
304
|
+
|
|
305
|
+
See [CHANGELOG.md](CHANGELOG.md) for detailed version history.
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
**Status**: Stable (v0.2.2) - Production ready
|
|
310
|
+
**Python**: 3.9+ | **Sphinx**: 5.0+ | **Typst**: 0.11.1+
|