tylax 0.3.5__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.
Files changed (85) hide show
  1. tylax-0.3.5/.gitignore +25 -0
  2. tylax-0.3.5/CHANGELOG.md +132 -0
  3. tylax-0.3.5/CODE_OF_CONDUCT.md +27 -0
  4. tylax-0.3.5/CONTRIBUTING.md +97 -0
  5. tylax-0.3.5/Cargo.lock +1677 -0
  6. tylax-0.3.5/Cargo.toml +110 -0
  7. tylax-0.3.5/LICENSE +191 -0
  8. tylax-0.3.5/PKG-INFO +78 -0
  9. tylax-0.3.5/README.md +224 -0
  10. tylax-0.3.5/README_CN.md +224 -0
  11. tylax-0.3.5/SECURITY.md +47 -0
  12. tylax-0.3.5/assets/logo.svg +9 -0
  13. tylax-0.3.5/bindings/python/.gitignore +16 -0
  14. tylax-0.3.5/bindings/python/Cargo.toml +14 -0
  15. tylax-0.3.5/bindings/python/README.md +54 -0
  16. tylax-0.3.5/bindings/python/src/lib.rs +313 -0
  17. tylax-0.3.5/bindings/python/tests/test_tylax.py +118 -0
  18. tylax-0.3.5/pyproject.toml +35 -0
  19. tylax-0.3.5/python/tylax/__init__.py +35 -0
  20. tylax-0.3.5/python/tylax/_native.pyi +71 -0
  21. tylax-0.3.5/python/tylax/py.typed +0 -0
  22. tylax-0.3.5/src/bin/t2l.rs +691 -0
  23. tylax-0.3.5/src/core/latex2typst/context.rs +1533 -0
  24. tylax-0.3.5/src/core/latex2typst/engine/engine.rs +2762 -0
  25. tylax-0.3.5/src/core/latex2typst/engine/lexer.rs +407 -0
  26. tylax-0.3.5/src/core/latex2typst/engine/mod.rs +289 -0
  27. tylax-0.3.5/src/core/latex2typst/engine/primitives.rs +803 -0
  28. tylax-0.3.5/src/core/latex2typst/engine/token.rs +213 -0
  29. tylax-0.3.5/src/core/latex2typst/engine/utils.rs +160 -0
  30. tylax-0.3.5/src/core/latex2typst/environment.rs +1185 -0
  31. tylax-0.3.5/src/core/latex2typst/markup.rs +3134 -0
  32. tylax-0.3.5/src/core/latex2typst/math.rs +612 -0
  33. tylax-0.3.5/src/core/latex2typst/mod.rs +329 -0
  34. tylax-0.3.5/src/core/latex2typst/table/cell.rs +195 -0
  35. tylax-0.3.5/src/core/latex2typst/table/hline.rs +231 -0
  36. tylax-0.3.5/src/core/latex2typst/table/mod.rs +37 -0
  37. tylax-0.3.5/src/core/latex2typst/table/parser.rs +234 -0
  38. tylax-0.3.5/src/core/latex2typst/table/tests.rs +145 -0
  39. tylax-0.3.5/src/core/latex2typst/utils.rs +454 -0
  40. tylax-0.3.5/src/core/mod.rs +20 -0
  41. tylax-0.3.5/src/core/typst2latex/context.rs +395 -0
  42. tylax-0.3.5/src/core/typst2latex/engine/data.rs +435 -0
  43. tylax-0.3.5/src/core/typst2latex/engine/eval.rs +3349 -0
  44. tylax-0.3.5/src/core/typst2latex/engine/library.rs +2053 -0
  45. tylax-0.3.5/src/core/typst2latex/engine/mod.rs +72 -0
  46. tylax-0.3.5/src/core/typst2latex/engine/ops.rs +550 -0
  47. tylax-0.3.5/src/core/typst2latex/engine/scope.rs +271 -0
  48. tylax-0.3.5/src/core/typst2latex/engine/value.rs +2068 -0
  49. tylax-0.3.5/src/core/typst2latex/engine/vfs.rs +303 -0
  50. tylax-0.3.5/src/core/typst2latex/markup.rs +2113 -0
  51. tylax-0.3.5/src/core/typst2latex/math.rs +620 -0
  52. tylax-0.3.5/src/core/typst2latex/math_emit.rs +591 -0
  53. tylax-0.3.5/src/core/typst2latex/math_ir.rs +1194 -0
  54. tylax-0.3.5/src/core/typst2latex/mod.rs +671 -0
  55. tylax-0.3.5/src/core/typst2latex/preprocess.rs +783 -0
  56. tylax-0.3.5/src/core/typst2latex/table/cell.rs +230 -0
  57. tylax-0.3.5/src/core/typst2latex/table/generator.rs +284 -0
  58. tylax-0.3.5/src/core/typst2latex/table/hline.rs +137 -0
  59. tylax-0.3.5/src/core/typst2latex/table/mod.rs +32 -0
  60. tylax-0.3.5/src/core/typst2latex/table/tests.rs +280 -0
  61. tylax-0.3.5/src/core/typst2latex/utils.rs +1328 -0
  62. tylax-0.3.5/src/data/colors.rs +411 -0
  63. tylax-0.3.5/src/data/constants.rs +728 -0
  64. tylax-0.3.5/src/data/extended_symbols.rs +810 -0
  65. tylax-0.3.5/src/data/maps.rs +2552 -0
  66. tylax-0.3.5/src/data/mod.rs +37 -0
  67. tylax-0.3.5/src/data/physics.rs +110 -0
  68. tylax-0.3.5/src/data/shorthands.rs +152 -0
  69. tylax-0.3.5/src/data/siunitx.rs +593 -0
  70. tylax-0.3.5/src/data/symbols.rs +891 -0
  71. tylax-0.3.5/src/data/typst_compat.rs +427 -0
  72. tylax-0.3.5/src/features/bibtex.rs +919 -0
  73. tylax-0.3.5/src/features/images.rs +829 -0
  74. tylax-0.3.5/src/features/mod.rs +21 -0
  75. tylax-0.3.5/src/features/refs.rs +992 -0
  76. tylax-0.3.5/src/features/tables.rs +1196 -0
  77. tylax-0.3.5/src/features/templates.rs +706 -0
  78. tylax-0.3.5/src/features/tikz.rs +3593 -0
  79. tylax-0.3.5/src/lib.rs +559 -0
  80. tylax-0.3.5/src/utils/diagnostics.rs +675 -0
  81. tylax-0.3.5/src/utils/error.rs +295 -0
  82. tylax-0.3.5/src/utils/files.rs +596 -0
  83. tylax-0.3.5/src/utils/mod.rs +18 -0
  84. tylax-0.3.5/src/wasm.rs +555 -0
  85. tylax-0.3.5/tests/integration_tests.rs +4366 -0
tylax-0.3.5/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ # Rust
2
+ /target
3
+ *.pdb
4
+
5
+ # Web
6
+ /web/node_modules
7
+ /web/dist
8
+ /web/src/pkg
9
+ /web/.vite
10
+
11
+ # Test artifacts
12
+ test_outputs/*
13
+
14
+ # System
15
+ .DS_Store
16
+ Thumbs.db
17
+ ehthumbs.db
18
+ Desktop.ini
19
+
20
+ # IDEs & Editors
21
+ .idea/
22
+ .vscode/
23
+ *.swp
24
+ *.swo
25
+ *.log
@@ -0,0 +1,132 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.3.5] - 2026-04-03
11
+
12
+ ### Fixed
13
+ - **L2T mathop**: `\mathop{\mathrm{Tr}}` now emits `op("Tr")` instead of `class("large", ...)` fallback.
14
+ - **L2T sqrt**: Nested `frac()` commas no longer trigger spurious brace wrapping.
15
+ - **T2L Assignment**: `:=`, `=:`, `::=` emit `\mathrel{:=}` without requiring mathtools.
16
+ - **T2L Subscripts**: Multiline big-operator subscripts use `\substack{}`.
17
+
18
+ ### Added
19
+ - **T2L Math Spacing**: `#h(1cm)` emits `\hspace{1cm}` in math mode.
20
+
21
+ ### Changed
22
+ - **T2L MathSegment**: Inline `#expr` in math preserved as structured nodes instead of pre-stringified.
23
+
24
+ ## [0.3.4] - 2026-03-12
25
+
26
+ This release unifies citation, reference, and label semantics across both LaTeX→Typst and Typst→LaTeX conversion. Citations now stay explicit as `#cite(...)` on the Typst side, bare `@key` consistently remains reference-first on the T2L path, and the shared refs layer now drives more of the conversion logic in both directions.
27
+
28
+ MiniEval also preserves `cite`, `ref`, `label`, and `bibliography` as semantic content nodes instead of reconstructing them from generic function calls. That makes dynamic cases like `#let k = <knuth>; #cite(k)` and loop-expanded citations round-trip cleanly and fixes a number of malformed citation/reference outputs.
29
+
30
+ ## [0.3.3] - 2026-03-08
31
+
32
+ ### Fixed
33
+ - **LaTeX-to-Typst Matrix Delimiters**: Preserve matrix semantics for `\left...\right` wrapped `array` and matrix environments. Delimiter-less environments now inherit the outer delimiter as `mat(delim: ...)`, while environments with intrinsic delimiters keep their nested structure instead of collapsing to `abs()` or `norm()`.
34
+
35
+ ## [0.3.2] - 2026-03-08
36
+
37
+ ### Fixed
38
+ - **Typst-to-LaTeX Math**: Fixed escaped punctuation, `accent()` mapping, grouped scripts, `mat(delim: ...)`, `attach()` script output, and stray math whitespace.
39
+
40
+ ### Changed
41
+ - **T2L Math Pipeline**: Moved Typst-to-LaTeX math conversion onto an `AST -> MathIr -> emit` pipeline and removed the legacy runtime path.
42
+
43
+ ## [0.3.1] - 2026-03-07
44
+
45
+ ### Fixed
46
+ - **Typst Named Arguments**: Refactored `typst2latex` to parse named arguments through a shared AST-aware `FuncArgs` layer instead of per-call string splitting.
47
+ - Fixed `lr(..., size: ...)` so `size: #200%` no longer leaks into math output and now maps cleanly to fixed-size LaTeX delimiters.
48
+ - Fixed tuple-valued and function-valued named arguments such as `grid(columns: (auto, auto, auto))` and `fill: rgb(255, 0, 0)` so values are preserved intact.
49
+ - Fixed `rotate(angle: 90deg)` and `bibliography(..., style: plain)` to preserve named argument values instead of silently degrading.
50
+
51
+ ### Changed
52
+ - **Color Conversion**: Unified Typst color handling for text, rectangles, and table cells through a shared normalization and LaTeX color-spec pipeline.
53
+ - Added support for `rgb(...)`, `cmyk(...)`, and `luma(...)` color values in Typst-to-LaTeX conversion.
54
+ - Kept named colors and `lighten(...)` / `darken(...)` method chains on the same conversion path to reduce duplicated logic.
55
+
56
+ ## [0.3.0] - 2026-03-07
57
+
58
+ ### Added
59
+ - **Physics Package Support**: Added initial support for common `physics` package commands in LaTeX to Typst conversion.
60
+ - Automatic bracing helpers such as `\pqty`, `\bqty`, `\Bqty`, `\vqty`, `\abs`, and `\norm`
61
+ - Derivative helpers such as `\dd`, `\dv`, `\pdv`, and `\fdv`
62
+ - Dirac notation such as `\bra`, `\ket`, `\braket`, `\dyad`, `\expval`, `\mel`, and `\vev`
63
+ - Matrix helpers such as `\mqty`, `\pmqty`, `\bmqty`, `\vmqty`, `\dmat`, and `\zmat`
64
+ - Quick-quad text helpers such as `\qq`, `\qif`, `\qthen`, and related variants
65
+
66
+ ### Fixed
67
+ - **Mixed Partial Derivatives**: Preserved argument order for mixed partial derivative forms such as `\pdv{f}{x}{y}`.
68
+
69
+ ## [0.2.2] - 2026-02-23
70
+
71
+ ### Fixed
72
+ - **Math Spacing**: `\,`, `\;`, `\quad`, `\qquad` now convert to Typst math spacing keywords (`thin`, `thick`, `quad`, `wide`) instead of plain spaces when in math mode. Reverse mapping (`wide` → `\qquad`) also added for T2L.
73
+ - **Array Environment**: `\begin{array}` now converts to `mat(delim: #none, ...)` instead of being incorrectly treated as a `table()`.
74
+
75
+ ## [0.2.1] - 2026-01-25
76
+
77
+ ### Fixed
78
+ - **Infinite Recursion**: Fixed a nasty browser freeze when macros call each other infinitely (like `\foo` ↔ `\bar`).
79
+ - Added a hard step limit to kill the loop before it kills the browser.
80
+ - If it hits the limit, we now just dump the text (e.g., `x`) instead of choking.
81
+ - Fixed the real culprit: raw `\newcommand` definitions were leaking into the parser when things went wrong.
82
+
83
+ ## [0.2.0] - 2026-01-16
84
+
85
+ This release is a major overhaul of the core conversion logic, introducing proper macro expansion engines for both directions.
86
+
87
+ ### Core Engines
88
+ - **L2T Engine**: Replaced the old regex hacks with a proper token-based macro expander (`latex2typst/engine`).
89
+ - Now supports `\def`, `\newcommand`, `\let`, `\newif`, and delimited parameters (e.g., `#1...#2`).
90
+ - Implemented correct scoping (`\begingroup`) and recursion limits.
91
+ - **T2L Engine**: Introduced "MiniEval", a lightweight interpreter (`typst2latex/engine`).
92
+ - Handles `#let` bindings, loops (`#for`/`#while`), conditionals, and custom function calls before conversion.
93
+ - Added VFS abstraction to support `#import` resolution in both CLI and WASM.
94
+
95
+ ### Fixed
96
+ - **Math Mode**: Implemented dynamic `$` tracking for `\ifmmode`. Macros now properly detect if they are inside inline/display math during expansion.
97
+ - **Escaping**: Patched missing escapes for special chars (`_`, `$`, `#`) in text mode. The logic is now shared with `convert_command_sym` to prevent regressions.
98
+ - **Typst Math**: Added missing mappings for keywords like `plus`, `minus`, `eq`. They now convert to operators (`+`, `-`, `=`) instead of raw identifiers.
99
+ - **Operators**: Fixed `\DeclareMathOperator*` ignoring the star; it now correctly adds `limits()` to the Typst operator.
100
+ - **Diagnostics**: `\let` now warns when the target macro doesn't exist (previously failed silently).
101
+
102
+ ### Added
103
+ - **WASM**: New `expand_macros` option to toggle MiniEval in document mode.
104
+
105
+ ### Removed
106
+ - Dropped the legacy `features/macros.rs` module in favor of the new engines.
107
+
108
+ ## [0.1.0] - 2026-01-05
109
+
110
+ ### Added
111
+ - Bidirectional LaTeX ↔ Typst conversion
112
+ - Full document conversion support (headings, lists, tables, figures)
113
+ - 700+ symbol mappings (376 LaTeX→Typst + 341 Typst→LaTeX)
114
+ - TikZ ↔ CeTZ graphics conversion
115
+ - Advanced table engine with multirow/multicolumn support
116
+ - Macro expansion (`\def`, `\newcommand`, `#let`)
117
+ - siunitx and mhchem support
118
+ - WebAssembly support
119
+ - CLI tool (`t2l`)
120
+ - Structured error handling with warnings
121
+
122
+ [Unreleased]: https://github.com/scipenai/tylax/compare/v0.3.5...HEAD
123
+ [0.3.5]: https://github.com/scipenai/tylax/compare/v0.3.4...v0.3.5
124
+ [0.3.4]: https://github.com/scipenai/tylax/compare/v0.3.3...v0.3.4
125
+ [0.3.3]: https://github.com/scipenai/tylax/compare/v0.3.2...v0.3.3
126
+ [0.3.2]: https://github.com/scipenai/tylax/compare/v0.3.1...v0.3.2
127
+ [0.3.1]: https://github.com/scipenai/tylax/compare/v0.3.0...v0.3.1
128
+ [0.3.0]: https://github.com/scipenai/tylax/compare/v0.2.2...v0.3.0
129
+ [0.2.2]: https://github.com/scipenai/tylax/compare/v0.2.1...v0.2.2
130
+ [0.2.1]: https://github.com/scipenai/tylax/compare/v0.2.0...v0.2.1
131
+ [0.2.0]: https://github.com/scipenai/tylax/compare/v0.1.0...v0.2.0
132
+ [0.1.0]: https://github.com/scipenai/tylax/releases/tag/v0.1.0
@@ -0,0 +1,27 @@
1
+ # Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We pledge to make participation in our project a harassment-free experience for everyone.
6
+
7
+ ## Our Standards
8
+
9
+ **Positive behavior:**
10
+ - Using welcoming and inclusive language
11
+ - Being respectful of differing viewpoints
12
+ - Accepting constructive criticism gracefully
13
+ - Focusing on what is best for the community
14
+
15
+ **Unacceptable behavior:**
16
+ - Harassment, trolling, or insulting comments
17
+ - Personal or political attacks
18
+ - Publishing others' private information
19
+ - Other conduct inappropriate in a professional setting
20
+
21
+ ## Enforcement
22
+
23
+ Project maintainers may remove, edit, or reject contributions not aligned with this Code of Conduct.
24
+
25
+ ## Attribution
26
+
27
+ Adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1.
@@ -0,0 +1,97 @@
1
+ # Contributing to tylax
2
+
3
+ Thank you for your interest in contributing to tylax!
4
+
5
+ ## Getting Started
6
+
7
+ 1. Fork the repository
8
+ 2. Clone your fork:
9
+ ```bash
10
+ git clone https://github.com/YOUR_USERNAME/tylax.git
11
+ cd tylax
12
+ ```
13
+ 3. Create a new branch:
14
+ ```bash
15
+ git checkout -b feature/your-feature-name
16
+ ```
17
+
18
+ ## Development Setup
19
+
20
+ ### Prerequisites
21
+
22
+ - Rust 1.70+ (install via [rustup](https://rustup.rs/))
23
+ - For WASM builds: `wasm-pack` (`cargo install wasm-pack`)
24
+
25
+ ### Building
26
+
27
+ ```bash
28
+ # Build CLI
29
+ cargo build --release --features cli
30
+
31
+ # Build WASM
32
+ wasm-pack build --target web --features wasm --no-default-features
33
+ ```
34
+
35
+ ### Testing
36
+
37
+ ```bash
38
+ # Run all tests
39
+ cargo test --release
40
+
41
+ # Run specific tests
42
+ cargo test latex2typst
43
+ cargo test typst2latex
44
+ cargo test tikz
45
+ ```
46
+
47
+ ## Architecture
48
+
49
+ This project uses **AST-based parsing** for high-precision bidirectional conversion:
50
+
51
+ - **LaTeX parsing**: [MiTeX](https://github.com/mitex-rs/mitex) - High-performance LaTeX parser with Rowan AST
52
+ - **Typst parsing**: [typst-syntax](https://github.com/typst/typst) - Official Typst syntax parser
53
+
54
+ ### Module Structure
55
+
56
+ ```
57
+ src/
58
+ ├── core/
59
+ │ ├── latex2typst/ # LaTeX → Typst conversion
60
+ │ │ ├── context.rs # Conversion state & options
61
+ │ │ ├── markup.rs # Document structure
62
+ │ │ └── table/ # Smart table parser with coverage tracking
63
+ │ └── typst2latex/ # Typst → LaTeX conversion
64
+ ├── features/
65
+ │ ├── tikz.rs # TikZ ↔ CeTZ with 5 coordinate systems
66
+ │ ├── macros.rs # Depth-limited macro expansion
67
+ │ └── refs.rs # Citations & references
68
+ ├── data/
69
+ │ ├── maps.rs # Symbol mappings
70
+ │ └── symbols.rs # Greek, operators, arrows
71
+ └── bin/
72
+ └── t2l.rs # CLI application
73
+ ```
74
+
75
+ ## Code Style
76
+
77
+ - Run `cargo fmt` before committing
78
+ - Run `cargo clippy --all-features` and fix all warnings
79
+ - Follow Rust naming conventions
80
+ - Add tests for new features
81
+
82
+ ## Pull Request Process
83
+
84
+ 1. Ensure all tests pass
85
+ 2. Update documentation if needed
86
+ 3. Add a clear description of your changes
87
+ 4. Reference any related issues
88
+
89
+ ## Reporting Issues
90
+
91
+ - Use the issue templates when available
92
+ - Include minimal reproduction steps
93
+ - Specify your environment (OS, Rust version)
94
+
95
+ ## License
96
+
97
+ By contributing, you agree that your contributions will be licensed under the Apache-2.0 License.