tex_to_unicode 0.1.0
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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +168 -0
- data/bin/tex_to_unicode +16 -0
- data/lib/tex_to_unicode/converter.rb +128 -0
- data/lib/tex_to_unicode.rb +9 -0
- metadata +53 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 758d993499f29b722dad34af1ceb5ec83d73fb1fb9a72e00acd2e2b2a792c2b6
|
|
4
|
+
data.tar.gz: 9f538d5baf5abe40fe927ee34b082ecd144e3bf7c6e499ffcee1188e10d64b42
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c73fde054663f346c7af90734416dce4c9107e0c86f86f55fec88ff777174bbf926c24c52a042128ea94359db21ef9a517fa32f8ad1e580ec1d901cc56f7701e
|
|
7
|
+
data.tar.gz: 2a2b20a8ed92f4d02275c9a49b93e1135fe44c431ad814bd6bfa93451d88946bb8446965bcc94e64bd6375b18e85718b987e7b52b06718531bf49a694f8da360
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Thomas Powell
|
|
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# TexToUnicode
|
|
2
|
+
|
|
3
|
+
A Ruby gem that converts TeX mathematical and other symbols to their Unicode character equivalents, enabling easier display of mathematical notation in plain text.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the gem locally:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
gem build tex_to_unicode.gemspec
|
|
11
|
+
gem install tex_to_unicode-0.1.0.gem
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or add it to your Gemfile:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'tex_to_unicode'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Command Line
|
|
23
|
+
|
|
24
|
+
The gem provides a `tex_to_unicode` executable that converts TeX expressions passed as arguments:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Basic usage
|
|
28
|
+
tex_to_unicode '\alpha + \beta = \gamma'
|
|
29
|
+
# Output: α + β = γ
|
|
30
|
+
|
|
31
|
+
# Greek letters
|
|
32
|
+
tex_to_unicode '\pi \approx 3.14159'
|
|
33
|
+
# Output: π ≈ 3.14159
|
|
34
|
+
|
|
35
|
+
# Math operators
|
|
36
|
+
tex_to_unicode 'x \times y \leq z'
|
|
37
|
+
# Output: x × y ≤ z
|
|
38
|
+
|
|
39
|
+
# Arrows
|
|
40
|
+
tex_to_unicode 'A \rightarrow B \Rightarrow C'
|
|
41
|
+
# Output: A → B ⇒ C
|
|
42
|
+
|
|
43
|
+
# Integrals and sums
|
|
44
|
+
tex_to_unicode '\int_0^\infty x^2 dx'
|
|
45
|
+
# Output: ∫₀^∞ x² dx
|
|
46
|
+
|
|
47
|
+
# Set notation
|
|
48
|
+
tex_to_unicode 'x \in \mathbb{R}, y \notin \emptyset'
|
|
49
|
+
# Output: x ∈ ℝ, y ∉ ∅
|
|
50
|
+
|
|
51
|
+
# Complex expressions
|
|
52
|
+
tex_to_unicode '\forall x \exists y : x \leq y'
|
|
53
|
+
# Output: ∀ x ∃ y : x ≤ y
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Ruby API
|
|
57
|
+
|
|
58
|
+
You can also use the gem in your Ruby code:
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
require 'tex_to_unicode'
|
|
62
|
+
|
|
63
|
+
# Convert TeX to Unicode
|
|
64
|
+
result = TexToUnicode.convert('\alpha + \beta = \gamma')
|
|
65
|
+
puts result # => α + β = γ
|
|
66
|
+
|
|
67
|
+
# Use in string interpolation
|
|
68
|
+
formula = '\sum_{i=1}^n i = \frac{n(n+1)}{2}'
|
|
69
|
+
puts "The formula is: #{TexToUnicode.convert(formula)}"
|
|
70
|
+
# Output: The formula is: ∑ᵢ₌₁ⁿ i = n(n+1)/2
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Supported Symbols
|
|
74
|
+
|
|
75
|
+
The gem supports a wide range of TeX symbols including:
|
|
76
|
+
|
|
77
|
+
### Greek Letters
|
|
78
|
+
- Lowercase: `\alpha`, `\beta`, `\gamma`, `\delta`, `\epsilon`, `\theta`, `\lambda`, `\mu`, `\pi`, `\sigma`, `\phi`, `\omega`, etc.
|
|
79
|
+
- Uppercase: `\Gamma`, `\Delta`, `\Theta`, `\Lambda`, `\Pi`, `\Sigma`, `\Phi`, `\Omega`, etc.
|
|
80
|
+
|
|
81
|
+
### Math Operators
|
|
82
|
+
- `\pm` (±), `\times` (×), `\div` (÷), `\cdot` (·)
|
|
83
|
+
- `\oplus` (⊕), `\otimes` (⊗), `\ast` (∗)
|
|
84
|
+
|
|
85
|
+
### Relations
|
|
86
|
+
- `\leq` (≤), `\geq` (≥), `\neq` (≠), `\approx` (≈)
|
|
87
|
+
- `\equiv` (≡), `\sim` (∼), `\propto` (∝)
|
|
88
|
+
- `\subset` (⊂), `\supset` (⊃), `\in` (∈), `\notin` (∉)
|
|
89
|
+
|
|
90
|
+
### Arrows
|
|
91
|
+
- `\rightarrow` or `\to` (→), `\leftarrow` (←), `\leftrightarrow` (↔)
|
|
92
|
+
- `\Rightarrow` (⇒), `\Leftarrow` (⇐), `\Leftrightarrow` (⇔)
|
|
93
|
+
- `\uparrow` (↑), `\downarrow` (↓)
|
|
94
|
+
|
|
95
|
+
### Calculus & Analysis
|
|
96
|
+
- `\int` (∫), `\sum` (∑), `\prod` (∏)
|
|
97
|
+
- `\partial` (∂), `\nabla` (∇), `\infty` (∞)
|
|
98
|
+
|
|
99
|
+
### Logic & Set Theory
|
|
100
|
+
- `\forall` (∀), `\exists` (∃), `\neg` (¬)
|
|
101
|
+
- `\land` (∧), `\lor` (∨), `\cap` (∩), `\cup` (∪)
|
|
102
|
+
- `\emptyset` (∅), `\therefore` (∴), `\because` (∵)
|
|
103
|
+
|
|
104
|
+
### Superscripts & Subscripts
|
|
105
|
+
- `^0` through `^9` (⁰¹²³⁴⁵⁶⁷⁸⁹)
|
|
106
|
+
- `_0` through `_9` (₀₁₂₃₄₅₆₇₈₉)
|
|
107
|
+
- `^+`, `^-`, `^(`, `^)` and subscript equivalents
|
|
108
|
+
|
|
109
|
+
### Brackets
|
|
110
|
+
- `\langle`, `\rangle` (⟨⟩)
|
|
111
|
+
- `\lceil`, `\rceil` (⌈⌉)
|
|
112
|
+
- `\lfloor`, `\rfloor` (⌊⌋)
|
|
113
|
+
|
|
114
|
+
### Miscellaneous
|
|
115
|
+
- `\checkmark` (✓), `\degree` (°), `\copyright` (©)
|
|
116
|
+
- `\dots` (…), `\cdots` (⋯)
|
|
117
|
+
- Musical symbols: `\sharp` (♯), `\flat` (♭), `\natural` (♮)
|
|
118
|
+
|
|
119
|
+
## Examples
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Quadratic formula
|
|
123
|
+
tex_to_unicode 'x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}'
|
|
124
|
+
# Output: x = -b ± √(b² - 4ac)/2a
|
|
125
|
+
|
|
126
|
+
# Euler's identity
|
|
127
|
+
tex_to_unicode 'e^{i\pi} + 1 = 0'
|
|
128
|
+
# Output: eⁱᵖⁱ + 1 = 0
|
|
129
|
+
|
|
130
|
+
# Set theory
|
|
131
|
+
tex_to_unicode 'A \cup B = \{x : x \in A \lor x \in B\}'
|
|
132
|
+
# Output: A ∪ B = {x : x ∈ A ∨ x ∈ B}
|
|
133
|
+
|
|
134
|
+
# Calculus
|
|
135
|
+
tex_to_unicode '\int_a^b f(x)dx = F(b) - F(a)'
|
|
136
|
+
# Output: ∫ₐᵇ f(x)dx = F(b) - F(a)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Limitations
|
|
140
|
+
|
|
141
|
+
While Unicode provides many mathematical symbols, some TeX constructs cannot be perfectly represented:
|
|
142
|
+
- Complex fractions are approximated
|
|
143
|
+
- Matrices and arrays have limited support
|
|
144
|
+
- Some accents and diacritics are approximated
|
|
145
|
+
- Subscripts and superscripts support limited characters
|
|
146
|
+
|
|
147
|
+
## Development
|
|
148
|
+
|
|
149
|
+
To build and test locally:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Build the gem
|
|
153
|
+
gem build tex_to_unicode.gemspec
|
|
154
|
+
|
|
155
|
+
# Install locally
|
|
156
|
+
gem install tex_to_unicode-0.1.0.gem
|
|
157
|
+
|
|
158
|
+
# Test the executable
|
|
159
|
+
tex_to_unicode '\alpha + \beta'
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Contributing
|
|
163
|
+
|
|
164
|
+
Bug reports and pull requests are welcome!
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
This gem is available as open source under the terms of the MIT License.
|
data/bin/tex_to_unicode
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/tex_to_unicode'
|
|
4
|
+
|
|
5
|
+
if ARGV.empty?
|
|
6
|
+
puts "Usage: tex_to_unicode <TeX expressions>"
|
|
7
|
+
puts "Example: tex_to_unicode '\\alpha + \\beta = \\gamma'"
|
|
8
|
+
exit 1
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Join all arguments with spaces
|
|
12
|
+
input = ARGV.join(' ')
|
|
13
|
+
|
|
14
|
+
# Convert and output
|
|
15
|
+
output = TexToUnicode.convert(input)
|
|
16
|
+
puts output
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
module TexToUnicode
|
|
2
|
+
class Converter
|
|
3
|
+
# Comprehensive mapping of TeX commands to Unicode characters
|
|
4
|
+
TEX_TO_UNICODE = {
|
|
5
|
+
# Greek letters (lowercase)
|
|
6
|
+
'\\alpha' => 'α', '\\beta' => 'β', '\\gamma' => 'γ', '\\delta' => 'δ',
|
|
7
|
+
'\\epsilon' => 'ε', '\\varepsilon' => 'ϵ', '\\zeta' => 'ζ', '\\eta' => 'η',
|
|
8
|
+
'\\theta' => 'θ', '\\vartheta' => 'ϑ', '\\iota' => 'ι', '\\kappa' => 'κ',
|
|
9
|
+
'\\lambda' => 'λ', '\\mu' => 'μ', '\\nu' => 'ν', '\\xi' => 'ξ',
|
|
10
|
+
'\\pi' => 'π', '\\varpi' => 'ϖ', '\\rho' => 'ρ', '\\varrho' => 'ϱ',
|
|
11
|
+
'\\sigma' => 'σ', '\\varsigma' => 'ς', '\\tau' => 'τ', '\\upsilon' => 'υ',
|
|
12
|
+
'\\phi' => 'φ', '\\varphi' => 'ϕ', '\\chi' => 'χ', '\\psi' => 'ψ',
|
|
13
|
+
'\\omega' => 'ω',
|
|
14
|
+
|
|
15
|
+
# Greek letters (uppercase)
|
|
16
|
+
'\\Gamma' => 'Γ', '\\Delta' => 'Δ', '\\Theta' => 'Θ', '\\Lambda' => 'Λ',
|
|
17
|
+
'\\Xi' => 'Ξ', '\\Pi' => 'Π', '\\Sigma' => 'Σ', '\\Upsilon' => 'Υ',
|
|
18
|
+
'\\Phi' => 'Φ', '\\Psi' => 'Ψ', '\\Omega' => 'Ω',
|
|
19
|
+
|
|
20
|
+
# Math operators
|
|
21
|
+
'\\pm' => '±', '\\mp' => '∓', '\\times' => '×', '\\div' => '÷',
|
|
22
|
+
'\\cdot' => '·', '\\ast' => '∗', '\\star' => '⋆', '\\circ' => '∘',
|
|
23
|
+
'\\bullet' => '•', '\\oplus' => '⊕', '\\ominus' => '⊖', '\\otimes' => '⊗',
|
|
24
|
+
'\\oslash' => '⊘', '\\odot' => '⊙', '\\bigcirc' => '◯',
|
|
25
|
+
|
|
26
|
+
# Relations
|
|
27
|
+
'\\leq' => '≤', '\\le' => '≤', '\\geq' => '≥', '\\ge' => '≥',
|
|
28
|
+
'\\neq' => '≠', '\\ne' => '≠', '\\equiv' => '≡', '\\approx' => '≈',
|
|
29
|
+
'\\cong' => '≅', '\\simeq' => '≃', '\\sim' => '∼', '\\propto' => '∝',
|
|
30
|
+
'\\ll' => '≪', '\\gg' => '≫', '\\asymp' => '≍',
|
|
31
|
+
'\\subset' => '⊂', '\\supset' => '⊃', '\\subseteq' => '⊆', '\\supseteq' => '⊇',
|
|
32
|
+
'\\in' => '∈', '\\ni' => '∋', '\\notin' => '∉',
|
|
33
|
+
|
|
34
|
+
# Arrows
|
|
35
|
+
'\\leftarrow' => '←', '\\gets' => '←', '\\rightarrow' => '→', '\\to' => '→',
|
|
36
|
+
'\\leftrightarrow' => '↔', '\\Leftarrow' => '⇐', '\\Rightarrow' => '⇒',
|
|
37
|
+
'\\Leftrightarrow' => '⇔', '\\uparrow' => '↑', '\\downarrow' => '↓',
|
|
38
|
+
'\\updownarrow' => '↕', '\\Uparrow' => '⇑', '\\Downarrow' => '⇓',
|
|
39
|
+
'\\Updownarrow' => '⇕', '\\mapsto' => '↦', '\\longleftarrow' => '⟵',
|
|
40
|
+
'\\longrightarrow' => '⟶', '\\longleftrightarrow' => '⟷',
|
|
41
|
+
'\\Longleftarrow' => '⟸', '\\Longrightarrow' => '⟹', '\\Longleftrightarrow' => '⟺',
|
|
42
|
+
|
|
43
|
+
# Special symbols
|
|
44
|
+
'\\infty' => '∞', '\\partial' => '∂', '\\nabla' => '∇', '\\emptyset' => '∅',
|
|
45
|
+
'\\varnothing' => '∅', '\\aleph' => 'ℵ', '\\wp' => '℘', '\\Re' => 'ℜ',
|
|
46
|
+
'\\Im' => 'ℑ', '\\ell' => 'ℓ', '\\hbar' => 'ℏ', '\\angle' => '∠',
|
|
47
|
+
'\\forall' => '∀', '\\exists' => '∃', '\\nexists' => '∄',
|
|
48
|
+
'\\neg' => '¬', '\\lnot' => '¬', '\\land' => '∧', '\\lor' => '∨',
|
|
49
|
+
'\\wedge' => '∧', '\\vee' => '∨', '\\cap' => '∩', '\\cup' => '∪',
|
|
50
|
+
'\\top' => '⊤', '\\bot' => '⊥', '\\perp' => '⊥',
|
|
51
|
+
|
|
52
|
+
# Calculus
|
|
53
|
+
'\\int' => '∫', '\\iint' => '∬', '\\iiint' => '∭', '\\oint' => '∮',
|
|
54
|
+
'\\sum' => '∑', '\\prod' => '∏', '\\coprod' => '∐',
|
|
55
|
+
|
|
56
|
+
# Set theory
|
|
57
|
+
'\\setminus' => '∖', '\\bigcap' => '⋂', '\\bigcup' => '⋃',
|
|
58
|
+
'\\sqsubset' => '⊏', '\\sqsupset' => '⊐', '\\sqsubseteq' => '⊑', '\\sqsupseteq' => '⊒',
|
|
59
|
+
|
|
60
|
+
# Logic
|
|
61
|
+
'\\vdash' => '⊢', '\\dashv' => '⊣', '\\models' => '⊨',
|
|
62
|
+
'\\therefore' => '∴', '\\because' => '∵',
|
|
63
|
+
|
|
64
|
+
# Misc
|
|
65
|
+
'\\dagger' => '†', '\\ddagger' => '‡', '\\S' => '§', '\\P' => '¶',
|
|
66
|
+
'\\copyright' => '©', '\\pounds' => '£', '\\yen' => '¥', '\\euro' => '€',
|
|
67
|
+
'\\degree' => '°', '\\prime' => '′', '\\dprime' => '″',
|
|
68
|
+
'\\dots' => '…', '\\ldots' => '…', '\\cdots' => '⋯',
|
|
69
|
+
'\\vdots' => '⋮', '\\ddots' => '⋱',
|
|
70
|
+
|
|
71
|
+
# Fractions (common ones)
|
|
72
|
+
'\\frac12' => '½', '\\frac13' => '⅓', '\\frac14' => '¼',
|
|
73
|
+
'\\frac23' => '⅔', '\\frac34' => '¾',
|
|
74
|
+
|
|
75
|
+
# Superscripts
|
|
76
|
+
'^0' => '⁰', '^1' => '¹', '^2' => '²', '^3' => '³', '^4' => '⁴',
|
|
77
|
+
'^5' => '⁵', '^6' => '⁶', '^7' => '⁷', '^8' => '⁸', '^9' => '⁹',
|
|
78
|
+
'^+' => '⁺', '^-' => '⁻', '^=' => '⁼', '^(' => '⁽', '^)' => '⁾',
|
|
79
|
+
'^n' => 'ⁿ', '^i' => 'ⁱ',
|
|
80
|
+
|
|
81
|
+
# Subscripts
|
|
82
|
+
'_0' => '₀', '_1' => '₁', '_2' => '₂', '_3' => '₃', '_4' => '₄',
|
|
83
|
+
'_5' => '₅', '_6' => '₆', '_7' => '₇', '_8' => '₈', '_9' => '₉',
|
|
84
|
+
'_+' => '₊', '_-' => '₋', '_=' => '₌', '_(' => '₍', '_)' => '₎',
|
|
85
|
+
|
|
86
|
+
# Brackets
|
|
87
|
+
'\\langle' => '⟨', '\\rangle' => '⟩', '\\lceil' => '⌈', '\\rceil' => '⌉',
|
|
88
|
+
'\\lfloor' => '⌊', '\\rfloor' => '⌋', '\\lbrace' => '{', '\\rbrace' => '}',
|
|
89
|
+
'\\lbrack' => '[', '\\rbrack' => ']',
|
|
90
|
+
|
|
91
|
+
# Accents and modifiers (approximate)
|
|
92
|
+
'\\hat{a}' => 'â', '\\hat{e}' => 'ê', '\\hat{i}' => 'î', '\\hat{o}' => 'ô', '\\hat{u}' => 'û',
|
|
93
|
+
'\\tilde{a}' => 'ã', '\\tilde{n}' => 'ñ', '\\tilde{o}' => 'õ',
|
|
94
|
+
"\\'{a}" => 'á', "\\'{e}" => 'é', "\\'{i}" => 'í', "\\'{o}" => 'ó', "\\'{u}" => 'ú',
|
|
95
|
+
'\\`{a}' => 'à', '\\`{e}' => 'è', '\\`{i}' => 'ì', '\\`{o}' => 'ò', '\\`{u}' => 'ù',
|
|
96
|
+
|
|
97
|
+
# Box drawing
|
|
98
|
+
'\\square' => '□', '\\blacksquare' => '■', '\\Box' => '□',
|
|
99
|
+
'\\triangle' => '△', '\\blacktriangle' => '▲',
|
|
100
|
+
'\\diamondsuit' => '♦', '\\heartsuit' => '♥', '\\clubsuit' => '♣', '\\spadesuit' => '♠',
|
|
101
|
+
|
|
102
|
+
# Musical
|
|
103
|
+
'\\sharp' => '♯', '\\flat' => '♭', '\\natural' => '♮',
|
|
104
|
+
|
|
105
|
+
# Misc symbols
|
|
106
|
+
'\\checkmark' => '✓', '\\maltese' => '✠',
|
|
107
|
+
|
|
108
|
+
# Blackboard bold (common sets)
|
|
109
|
+
'\\mathbb{C}' => 'ℂ', '\\mathbb{H}' => 'ℍ', '\\mathbb{N}' => 'ℕ',
|
|
110
|
+
'\\mathbb{P}' => 'ℙ', '\\mathbb{Q}' => 'ℚ', '\\mathbb{R}' => 'ℝ',
|
|
111
|
+
'\\mathbb{Z}' => 'ℤ',
|
|
112
|
+
|
|
113
|
+
# Additional useful symbols
|
|
114
|
+
'\\sqrt' => '√', '\\surd' => '√',
|
|
115
|
+
}.freeze
|
|
116
|
+
|
|
117
|
+
def self.convert(text)
|
|
118
|
+
result = text.dup
|
|
119
|
+
|
|
120
|
+
# Sort by length (descending) to match longer patterns first
|
|
121
|
+
TEX_TO_UNICODE.keys.sort_by { |k| -k.length }.each do |tex|
|
|
122
|
+
result.gsub!(tex, TEX_TO_UNICODE[tex])
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
result
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tex_to_unicode
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Your Name
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-11-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A Ruby gem that converts TeX mathematical and other symbols to their
|
|
14
|
+
Unicode character equivalents, enabling easier display of mathematical notation
|
|
15
|
+
in plain text.
|
|
16
|
+
email:
|
|
17
|
+
- your.email@example.com
|
|
18
|
+
executables:
|
|
19
|
+
- tex_to_unicode
|
|
20
|
+
extensions: []
|
|
21
|
+
extra_rdoc_files: []
|
|
22
|
+
files:
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.md
|
|
25
|
+
- bin/tex_to_unicode
|
|
26
|
+
- lib/tex_to_unicode.rb
|
|
27
|
+
- lib/tex_to_unicode/converter.rb
|
|
28
|
+
homepage: https://github.com/yourusername/tex_to_unicode
|
|
29
|
+
licenses:
|
|
30
|
+
- MIT
|
|
31
|
+
metadata:
|
|
32
|
+
source_code_uri: https://github.com/yourusername/tex_to_unicode
|
|
33
|
+
bug_tracker_uri: https://github.com/yourusername/tex_to_unicode/issues
|
|
34
|
+
post_install_message:
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: 2.6.0
|
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
requirements: []
|
|
49
|
+
rubygems_version: 3.4.10
|
|
50
|
+
signing_key:
|
|
51
|
+
specification_version: 4
|
|
52
|
+
summary: Convert TeX math symbols to Unicode approximations
|
|
53
|
+
test_files: []
|