rage_flip 2.6.1 → 2.7.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +45 -0
- data/exe/latex +19 -0
- data/lib/rage_flip/emote.rb +59 -1
- data/lib/rage_flip/latex.rb +230 -0
- data/lib/rage_flip/version.rb +1 -1
- data/lib/rage_flip.rb +1 -0
- data/spec/rage_flip_spec.rb +74 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1dd813996cd3fdb75c67e24b575b5d262b77fad86fca527b3beb2e401bd2be37
|
|
4
|
+
data.tar.gz: 76520df4f90f31cf87b83d05bb58eec366554b3f30995e1be98ee3ec1f223248
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05dbaf5a3ed7d026703a8b5749d5081435ac29a80b7650f94e241d2455758543f5c5e7adc36de7af9b8555d59eb1c7d73ead91a796dd49dd8e788a533a6280d0
|
|
7
|
+
data.tar.gz: 36d35d23d2d6ce6522efdd2650cf50ba5d391649354c5dd6822c056e9e6cf3142b60f5fb84464702f0d379da43cc2c55e93ed432f1b9e35d53ff14f1b5c9e8fc
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
|
+
- `latex` command that replaces LaTeX-style markup (`\int`, `\sqrt{x}`, `x^2`, `a_{n+1}`, `\frac{1}{2}`, Greek letters, relations, arrows) with Unicode symbols
|
|
12
|
+
- `emote` math symbols in a new `math` category: roots (`sqrt`/`radical` √, `cbrt` ∛, `fourthroot` ∜), integrals (`integral` ∫ and friends), `summation` ∑, `squared` ², `cubed` ³, `sup0`–`sup9`, `sub0`–`sub9`, and common relations like `plusminus` ±
|
|
11
13
|
- `emote celsius`, `fahrenheit`, `kelvin`, and `rankine` temperature unit symbols (℃ ℉ K °R)
|
|
12
14
|
- `italic` command that swaps letters for slanted Unicode alternatives, or script ones with `--script`
|
|
13
15
|
- `flip_text` command for flipping text without any emoticons
|
|
@@ -17,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
17
19
|
- `emote list` to display all available emotes
|
|
18
20
|
- `table_flip` command with classic `(╯°□°)╯︵` and `┻━┻` emoticons
|
|
19
21
|
|
|
22
|
+
### Changed
|
|
23
|
+
- `emote plusminus` and `emote minusplus` now return ± and ∓ instead of the compound ➕➖ / ➖➕ (`emote plus-minus` still gives ➕➖)
|
|
24
|
+
|
|
20
25
|
### Fixed
|
|
21
26
|
- **Windows Unicode Support**: Fixed clipboard handling of Unicode characters on Windows by implementing proper UTF-16LE encoding with BOM. This resolves issues where Unicode characters (rage flip emoticons, flipped text characters, emoji, accented characters, etc.) would not copy correctly to the Windows clipboard.
|
|
22
27
|
|
data/README.md
CHANGED
|
@@ -120,6 +120,19 @@ emote kelvin # Output: K (U+212A KELVIN SIGN)
|
|
|
120
120
|
emote rankine # Output: °R
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
+
Math symbols:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
emote sqrt # Output: √ (also: radical)
|
|
127
|
+
emote cbrt # Output: ∛ (also: cuberoot; fourthroot is ∜)
|
|
128
|
+
emote integral # Output: ∫ (also: doubleintegral ∬, tripleintegral ∭, contourintegral ∮)
|
|
129
|
+
emote summation # Output: ∑
|
|
130
|
+
emote squared # Output: ²
|
|
131
|
+
emote cubed # Output: ³
|
|
132
|
+
emote sup2 sub1 # Output: ²₁ (sup0–sup9, supplus, supminus, supn, sub0–sub9)
|
|
133
|
+
emote plusminus # Output: ± (also: minusplus ∓, approx ≈, notequal ≠, lessequal ≤, greaterequal ≥)
|
|
134
|
+
```
|
|
135
|
+
|
|
123
136
|
#### Special Emotes
|
|
124
137
|
Multi-line and unique expressions:
|
|
125
138
|
|
|
@@ -204,6 +217,27 @@ italic --script "script text"
|
|
|
204
217
|
# Output: 𝓈𝒸𝓇𝒾𝓅𝓉 𝓉ℯ𝓍𝓉
|
|
205
218
|
```
|
|
206
219
|
|
|
220
|
+
### latex
|
|
221
|
+
|
|
222
|
+
Replaces LaTeX-style markup with Unicode symbols. Use single quotes so the shell keeps the backslashes:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
latex '\int_0^1 x^2 dx'
|
|
226
|
+
# Output: ∫₀¹ x² dx
|
|
227
|
+
|
|
228
|
+
latex '\sqrt{x+1} \approx \sqrt[3]{8} \pm \frac{1}{2}'
|
|
229
|
+
# Output: √(x+1) ≈ ∛8 ± ½
|
|
230
|
+
|
|
231
|
+
latex '\alpha + \beta \to \gamma, \forall x \in \emptyset'
|
|
232
|
+
# Output: α + β → γ, ∀ x ∈ ∅
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
- `\name` commands cover Greek letters, big operators (`\int`, `\sum`, `\prod`, `\partial`, `\nabla`, `\infty`), operators (`\pm`, `\times`, `\cdot`), relations (`\approx`, `\neq`, `\leq`, `\geq`, `\equiv`), arrows (`\to`, `\Rightarrow`, `\iff`), and sets/logic (`\forall`, `\exists`, `\in`, `\subset`, `\cup`, `\cap`, `\emptyset`). Unknown commands are left as typed.
|
|
236
|
+
- `^2`, `^{n+1}`, `_0` and `_{i=1}` become superscripts and subscripts when every character has a Unicode form; otherwise (e.g. `e^{i\pi}`, since there's no superscript π) they're left as typed.
|
|
237
|
+
- `\sqrt{x}` → `√x`, `\sqrt{x+1}` → `√(x+1)`, `\sqrt[3]{x}` → `∛x`, `\sqrt[5]{x}` → `⁵√x`.
|
|
238
|
+
- `\frac{1}{2}` → `½` when a vulgar fraction exists, otherwise `\frac{a+b}{c}` → `(a+b)/c`.
|
|
239
|
+
- Spaces are kept as typed, `$` delimiters pass through, `\left`/`\right` are dropped, and `\{ \} \_ \^ \$ \% \& \# \\` output the escaped character.
|
|
240
|
+
|
|
207
241
|
### chaos
|
|
208
242
|
|
|
209
243
|
Adds random Unicode combining characters for a chaotic effect:
|
|
@@ -267,6 +301,13 @@ The gem includes an extensive collection of emotes organized into categories:
|
|
|
267
301
|
### Temperature Units
|
|
268
302
|
- `celsius` (℃), `fahrenheit` (℉), `kelvin` (K), `rankine` (°R)
|
|
269
303
|
|
|
304
|
+
### Math Symbols
|
|
305
|
+
- Roots: `sqrt`/`radical` (√), `cbrt`/`cuberoot` (∛), `fourthroot` (∜)
|
|
306
|
+
- Calculus: `integral` (∫), `doubleintegral` (∬), `tripleintegral` (∭), `contourintegral` (∮), `summation` (∑), `prod` (∏), `partialdiff` (∂), `nabla` (∇), `infty` (∞)
|
|
307
|
+
- Relations: `plusminus` (±), `minusplus` (∓), `approx` (≈), `notequal` (≠), `lessequal` (≤), `greaterequal` (≥), `equiv` (≡), `propto` (∝)
|
|
308
|
+
- Superscripts: `squared` (²), `cubed` (³), `sup0`–`sup9` (⁰–⁹), `supplus` (⁺), `supminus` (⁻), `supn` (ⁿ)
|
|
309
|
+
- Subscripts: `sub0`–`sub9` (₀–₉)
|
|
310
|
+
|
|
270
311
|
### Special Characters
|
|
271
312
|
- `noevil` (🙈🙉🙊), `omw` ("On my way!"), `heresatable`, `kungfuhamster` (ASCII art), `unsee`
|
|
272
313
|
|
|
@@ -329,6 +370,10 @@ RageFlip::Italic.slanted("text")
|
|
|
329
370
|
RageFlip::Italic.script("text")
|
|
330
371
|
# => "𝓉ℯ𝓍𝓉"
|
|
331
372
|
|
|
373
|
+
# LaTeX-style markup to Unicode
|
|
374
|
+
RageFlip::Latex.process("\\int_0^1 x^2 dx")
|
|
375
|
+
# => "∫₀¹ x² dx"
|
|
376
|
+
|
|
332
377
|
# Chaos
|
|
333
378
|
RageFlip::Chaos.process("text", 5)
|
|
334
379
|
# => "t̸e̷x̸t̷"
|
data/exe/latex
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative "../lib/rage_flip"
|
|
4
|
+
|
|
5
|
+
text = ARGV.join(" ")
|
|
6
|
+
|
|
7
|
+
if text.empty?
|
|
8
|
+
puts "Usage: latex <latex_text>"
|
|
9
|
+
puts "Quote the text so the shell keeps the backslashes: latex '\\int_0^1 x^2 dx'"
|
|
10
|
+
exit 1
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
result = RageFlip::Latex.process(text)
|
|
14
|
+
|
|
15
|
+
if RageFlip::Clipboard.copy(result)
|
|
16
|
+
else
|
|
17
|
+
puts "Failed to copy to clipboard, but here's your text:"
|
|
18
|
+
end
|
|
19
|
+
puts result
|
data/lib/rage_flip/emote.rb
CHANGED
|
@@ -40,6 +40,55 @@ module RageFlip
|
|
|
40
40
|
"kelvin" => "\u212A", # K KELVIN SIGN
|
|
41
41
|
"rankine" => "\u00B0R", # °R (Unicode has no dedicated Rankine sign)
|
|
42
42
|
|
|
43
|
+
# Math Symbols
|
|
44
|
+
"sqrt" => "\u221A", # √ SQUARE ROOT
|
|
45
|
+
"radical" => "\u221A", # √ SQUARE ROOT
|
|
46
|
+
"cbrt" => "\u221B", # ∛ CUBE ROOT
|
|
47
|
+
"cuberoot" => "\u221B", # ∛ CUBE ROOT
|
|
48
|
+
"fourthroot" => "\u221C", # ∜ FOURTH ROOT
|
|
49
|
+
"integral" => "\u222B", # ∫ INTEGRAL
|
|
50
|
+
"doubleintegral" => "\u222C", # ∬ DOUBLE INTEGRAL
|
|
51
|
+
"tripleintegral" => "\u222D", # ∭ TRIPLE INTEGRAL
|
|
52
|
+
"contourintegral" => "\u222E", # ∮ CONTOUR INTEGRAL
|
|
53
|
+
"summation" => "\u2211", # ∑ N-ARY SUMMATION
|
|
54
|
+
"prod" => "\u220F", # ∏ N-ARY PRODUCT
|
|
55
|
+
"partialdiff" => "\u2202", # ∂ PARTIAL DIFFERENTIAL
|
|
56
|
+
"nabla" => "\u2207", # ∇ NABLA
|
|
57
|
+
"infty" => "\u221E", # ∞ INFINITY (text, unlike the ♾️ "infinity" emoji)
|
|
58
|
+
"plusminus" => "\u00B1", # ± PLUS-MINUS SIGN
|
|
59
|
+
"minusplus" => "\u2213", # ∓ MINUS-OR-PLUS SIGN
|
|
60
|
+
"approx" => "\u2248", # ≈ ALMOST EQUAL TO
|
|
61
|
+
"notequal" => "\u2260", # ≠ NOT EQUAL TO
|
|
62
|
+
"lessequal" => "\u2264", # ≤ LESS-THAN OR EQUAL TO
|
|
63
|
+
"greaterequal" => "\u2265", # ≥ GREATER-THAN OR EQUAL TO
|
|
64
|
+
"equiv" => "\u2261", # ≡ IDENTICAL TO
|
|
65
|
+
"propto" => "\u221D", # ∝ PROPORTIONAL TO
|
|
66
|
+
"squared" => "\u00B2", # ² SUPERSCRIPT TWO
|
|
67
|
+
"cubed" => "\u00B3", # ³ SUPERSCRIPT THREE
|
|
68
|
+
"sup0" => "\u2070", # ⁰
|
|
69
|
+
"sup1" => "\u00B9", # ¹
|
|
70
|
+
"sup2" => "\u00B2", # ²
|
|
71
|
+
"sup3" => "\u00B3", # ³
|
|
72
|
+
"sup4" => "\u2074", # ⁴
|
|
73
|
+
"sup5" => "\u2075", # ⁵
|
|
74
|
+
"sup6" => "\u2076", # ⁶
|
|
75
|
+
"sup7" => "\u2077", # ⁷
|
|
76
|
+
"sup8" => "\u2078", # ⁸
|
|
77
|
+
"sup9" => "\u2079", # ⁹
|
|
78
|
+
"supplus" => "\u207A", # ⁺
|
|
79
|
+
"supminus" => "\u207B", # ⁻
|
|
80
|
+
"supn" => "\u207F", # ⁿ
|
|
81
|
+
"sub0" => "\u2080", # ₀
|
|
82
|
+
"sub1" => "\u2081", # ₁
|
|
83
|
+
"sub2" => "\u2082", # ₂
|
|
84
|
+
"sub3" => "\u2083", # ₃
|
|
85
|
+
"sub4" => "\u2084", # ₄
|
|
86
|
+
"sub5" => "\u2085", # ₅
|
|
87
|
+
"sub6" => "\u2086", # ₆
|
|
88
|
+
"sub7" => "\u2087", # ₇
|
|
89
|
+
"sub8" => "\u2088", # ₈
|
|
90
|
+
"sub9" => "\u2089", # ₉
|
|
91
|
+
|
|
43
92
|
# Smileys & People
|
|
44
93
|
"grin" => "😀",
|
|
45
94
|
"smiley" => "😃",
|
|
@@ -1615,6 +1664,15 @@ module RageFlip
|
|
|
1615
1664
|
description: "Temperature Units",
|
|
1616
1665
|
emotes: ["celsius", "fahrenheit", "kelvin", "rankine"]
|
|
1617
1666
|
},
|
|
1667
|
+
"math" => {
|
|
1668
|
+
description: "Math Symbols",
|
|
1669
|
+
emotes: ["sqrt", "radical", "cbrt", "cuberoot", "fourthroot", "integral", "doubleintegral",
|
|
1670
|
+
"tripleintegral", "contourintegral", "summation", "prod", "partialdiff", "nabla",
|
|
1671
|
+
"infty", "plusminus", "minusplus", "approx", "notequal", "lessequal", "greaterequal",
|
|
1672
|
+
"equiv", "propto", "squared", "cubed", "sup0", "sup1", "sup2", "sup3", "sup4", "sup5",
|
|
1673
|
+
"sup6", "sup7", "sup8", "sup9", "supplus", "supminus", "supn", "sub0", "sub1", "sub2",
|
|
1674
|
+
"sub3", "sub4", "sub5", "sub6", "sub7", "sub8", "sub9"]
|
|
1675
|
+
},
|
|
1618
1676
|
"smileys" => {
|
|
1619
1677
|
description: "Smileys & People",
|
|
1620
1678
|
emotes: EMOTES.keys.select { |k|
|
|
@@ -2158,7 +2216,7 @@ module RageFlip
|
|
|
2158
2216
|
emote category food - Show all food emotes
|
|
2159
2217
|
|
|
2160
2218
|
Categories:
|
|
2161
|
-
custom, keyboard, smileys, animals, combined, food,
|
|
2219
|
+
custom, keyboard, temperature, math, smileys, animals, combined, food,
|
|
2162
2220
|
activity, travel, objects, symbols, flags
|
|
2163
2221
|
|
|
2164
2222
|
Compound Emotes:
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
module RageFlip
|
|
2
|
+
# Replaces LaTeX-style markup with Unicode: `\int_0^1 x^2 dx` -> `∫₀¹ x² dx`.
|
|
3
|
+
#
|
|
4
|
+
# - `\name` commands from SYMBOLS (Greek letters, operators, relations,
|
|
5
|
+
# arrows, sets and logic). Unknown commands are left as typed.
|
|
6
|
+
# - `^x`, `^{...}`, `_x`, `_{...}` become superscripts/subscripts when every
|
|
7
|
+
# character has one; otherwise they're left as typed.
|
|
8
|
+
# - `\sqrt{x}` -> `√x`, `\sqrt{x+1}` -> `√(x+1)`, `\sqrt[3]{x}` -> `∛x`.
|
|
9
|
+
# - `\frac{a}{b}` -> `a/b` (or a vulgar fraction like ½), with parentheses
|
|
10
|
+
# around multi-character parts.
|
|
11
|
+
# - `\{`, `\}`, `\_`, `\^`, `\$`, `\%`, `\&`, `\#` and `\\` output the character.
|
|
12
|
+
#
|
|
13
|
+
# Spaces are kept as typed, and `$` delimiters pass through.
|
|
14
|
+
class Latex
|
|
15
|
+
SYMBOLS = {
|
|
16
|
+
# Greek lowercase
|
|
17
|
+
"alpha" => "α", "beta" => "β", "gamma" => "γ", "delta" => "δ", "epsilon" => "ε",
|
|
18
|
+
"varepsilon" => "ε", "zeta" => "ζ", "eta" => "η", "theta" => "θ", "vartheta" => "ϑ",
|
|
19
|
+
"iota" => "ι", "kappa" => "κ", "lambda" => "λ", "mu" => "μ", "nu" => "ν", "xi" => "ξ",
|
|
20
|
+
"omicron" => "ο", "pi" => "π", "varpi" => "ϖ", "rho" => "ρ", "varrho" => "ϱ",
|
|
21
|
+
"sigma" => "σ", "varsigma" => "ς", "tau" => "τ", "upsilon" => "υ", "phi" => "φ",
|
|
22
|
+
"varphi" => "ϕ", "chi" => "χ", "psi" => "ψ", "omega" => "ω",
|
|
23
|
+
# Greek uppercase
|
|
24
|
+
"Gamma" => "Γ", "Delta" => "Δ", "Theta" => "Θ", "Lambda" => "Λ", "Xi" => "Ξ", "Pi" => "Π",
|
|
25
|
+
"Sigma" => "Σ", "Upsilon" => "Υ", "Phi" => "Φ", "Psi" => "Ψ", "Omega" => "Ω",
|
|
26
|
+
# Big operators and calculus
|
|
27
|
+
"int" => "∫", "iint" => "∬", "iiint" => "∭", "oint" => "∮", "sum" => "∑", "prod" => "∏",
|
|
28
|
+
"coprod" => "∐", "partial" => "∂", "nabla" => "∇", "infty" => "∞", "sqrt" => "√",
|
|
29
|
+
# Binary operators
|
|
30
|
+
"pm" => "±", "mp" => "∓", "times" => "×", "div" => "÷", "cdot" => "⋅", "ast" => "∗",
|
|
31
|
+
"star" => "⋆", "circ" => "∘", "bullet" => "∙", "oplus" => "⊕", "otimes" => "⊗",
|
|
32
|
+
# Relations
|
|
33
|
+
"approx" => "≈", "neq" => "≠", "ne" => "≠", "leq" => "≤", "le" => "≤", "geq" => "≥",
|
|
34
|
+
"ge" => "≥", "equiv" => "≡", "propto" => "∝", "sim" => "∼", "simeq" => "≃", "cong" => "≅",
|
|
35
|
+
"ll" => "≪", "gg" => "≫", "perp" => "⊥", "parallel" => "∥", "mid" => "∣",
|
|
36
|
+
# Arrows
|
|
37
|
+
"to" => "→", "rightarrow" => "→", "leftarrow" => "←", "gets" => "←",
|
|
38
|
+
"leftrightarrow" => "↔", "Rightarrow" => "⇒", "implies" => "⇒", "Leftarrow" => "⇐",
|
|
39
|
+
"Leftrightarrow" => "⇔", "iff" => "⇔", "mapsto" => "↦", "uparrow" => "↑",
|
|
40
|
+
"downarrow" => "↓",
|
|
41
|
+
# Sets and logic
|
|
42
|
+
"forall" => "∀", "exists" => "∃", "nexists" => "∄", "neg" => "¬", "lnot" => "¬",
|
|
43
|
+
"land" => "∧", "wedge" => "∧", "lor" => "∨", "vee" => "∨", "in" => "∈", "notin" => "∉",
|
|
44
|
+
"ni" => "∋", "subset" => "⊂", "supset" => "⊃", "subseteq" => "⊆", "supseteq" => "⊇",
|
|
45
|
+
"cup" => "∪", "cap" => "∩", "emptyset" => "∅", "varnothing" => "∅", "setminus" => "∖",
|
|
46
|
+
"therefore" => "∴", "because" => "∵",
|
|
47
|
+
# Letterlike and miscellaneous
|
|
48
|
+
"hbar" => "ℏ", "ell" => "ℓ", "Re" => "ℜ", "Im" => "ℑ", "aleph" => "ℵ", "wp" => "℘",
|
|
49
|
+
"angle" => "∠", "degree" => "°", "prime" => "′", "cdots" => "⋯", "ldots" => "…",
|
|
50
|
+
"dots" => "…", "vdots" => "⋮", "ddots" => "⋱",
|
|
51
|
+
# Sizing commands with no plain-text equivalent
|
|
52
|
+
"left" => "", "right" => ""
|
|
53
|
+
}.freeze
|
|
54
|
+
|
|
55
|
+
SUPERSCRIPTS = {
|
|
56
|
+
"0" => "⁰", "1" => "¹", "2" => "²", "3" => "³", "4" => "⁴", "5" => "⁵", "6" => "⁶",
|
|
57
|
+
"7" => "⁷", "8" => "⁸", "9" => "⁹", "+" => "⁺", "-" => "⁻", "=" => "⁼", "(" => "⁽",
|
|
58
|
+
")" => "⁾", " " => " ",
|
|
59
|
+
"a" => "ᵃ", "b" => "ᵇ", "c" => "ᶜ", "d" => "ᵈ", "e" => "ᵉ", "f" => "ᶠ", "g" => "ᵍ",
|
|
60
|
+
"h" => "ʰ", "i" => "ⁱ", "j" => "ʲ", "k" => "ᵏ", "l" => "ˡ", "m" => "ᵐ", "n" => "ⁿ",
|
|
61
|
+
"o" => "ᵒ", "p" => "ᵖ", "r" => "ʳ", "s" => "ˢ", "t" => "ᵗ", "u" => "ᵘ", "v" => "ᵛ",
|
|
62
|
+
"w" => "ʷ", "x" => "ˣ", "y" => "ʸ", "z" => "ᶻ",
|
|
63
|
+
"A" => "ᴬ", "B" => "ᴮ", "D" => "ᴰ", "E" => "ᴱ", "G" => "ᴳ", "H" => "ᴴ", "I" => "ᴵ",
|
|
64
|
+
"J" => "ᴶ", "K" => "ᴷ", "L" => "ᴸ", "M" => "ᴹ", "N" => "ᴺ", "O" => "ᴼ", "P" => "ᴾ",
|
|
65
|
+
"R" => "ᴿ", "T" => "ᵀ", "U" => "ᵁ", "V" => "ⱽ", "W" => "ᵂ"
|
|
66
|
+
}.freeze
|
|
67
|
+
|
|
68
|
+
SUBSCRIPTS = {
|
|
69
|
+
"0" => "₀", "1" => "₁", "2" => "₂", "3" => "₃", "4" => "₄", "5" => "₅", "6" => "₆",
|
|
70
|
+
"7" => "₇", "8" => "₈", "9" => "₉", "+" => "₊", "-" => "₋", "=" => "₌", "(" => "₍",
|
|
71
|
+
")" => "₎", " " => " ",
|
|
72
|
+
"a" => "ₐ", "e" => "ₑ", "h" => "ₕ", "i" => "ᵢ", "j" => "ⱼ", "k" => "ₖ", "l" => "ₗ",
|
|
73
|
+
"m" => "ₘ", "n" => "ₙ", "o" => "ₒ", "p" => "ₚ", "r" => "ᵣ", "s" => "ₛ", "t" => "ₜ",
|
|
74
|
+
"u" => "ᵤ", "v" => "ᵥ", "x" => "ₓ"
|
|
75
|
+
}.freeze
|
|
76
|
+
|
|
77
|
+
VULGAR_FRACTIONS = {
|
|
78
|
+
"1/2" => "½", "1/3" => "⅓", "2/3" => "⅔", "1/4" => "¼", "3/4" => "¾", "1/5" => "⅕",
|
|
79
|
+
"2/5" => "⅖", "3/5" => "⅗", "4/5" => "⅘", "1/6" => "⅙", "5/6" => "⅚", "1/7" => "⅐",
|
|
80
|
+
"1/8" => "⅛", "3/8" => "⅜", "5/8" => "⅝", "7/8" => "⅞", "1/9" => "⅑", "1/10" => "⅒"
|
|
81
|
+
}.freeze
|
|
82
|
+
|
|
83
|
+
ROOTS = { "" => "√", "2" => "√", "3" => "∛", "4" => "∜" }.freeze
|
|
84
|
+
|
|
85
|
+
ESCAPABLE = "{}_^$%&#\\".chars.freeze
|
|
86
|
+
WHITESPACE = [" ", "\t", "\n", "\r"].freeze
|
|
87
|
+
|
|
88
|
+
def self.process(text)
|
|
89
|
+
convert(text.chars)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# `chars` is an array of single-codepoint strings.
|
|
93
|
+
def self.convert(chars)
|
|
94
|
+
out = +""
|
|
95
|
+
i = 0
|
|
96
|
+
while i < chars.length
|
|
97
|
+
c = chars[i]
|
|
98
|
+
if c == "\\"
|
|
99
|
+
name = letters_at(chars, i + 1)
|
|
100
|
+
if name.empty?
|
|
101
|
+
if ESCAPABLE.include?(chars[i + 1])
|
|
102
|
+
out << chars[i + 1]
|
|
103
|
+
i += 2
|
|
104
|
+
else
|
|
105
|
+
out << c
|
|
106
|
+
i += 1
|
|
107
|
+
end
|
|
108
|
+
elsif name == "sqrt" && (root = sqrt_at(chars, i + 1 + name.length))
|
|
109
|
+
text, i = root
|
|
110
|
+
out << text
|
|
111
|
+
elsif name == "frac" && (frac = frac_at(chars, i + 1 + name.length))
|
|
112
|
+
text, i = frac
|
|
113
|
+
out << text
|
|
114
|
+
else
|
|
115
|
+
out << SYMBOLS.fetch(name) { "\\#{name}" }
|
|
116
|
+
i += 1 + name.length
|
|
117
|
+
end
|
|
118
|
+
elsif c == "^" || c == "_"
|
|
119
|
+
arg = argument_at(chars, i + 1)
|
|
120
|
+
if arg
|
|
121
|
+
inner, raw, i = arg
|
|
122
|
+
converted = convert(inner)
|
|
123
|
+
out << (script(converted, c == "^" ? SUPERSCRIPTS : SUBSCRIPTS) ||
|
|
124
|
+
"#{c}#{raw ? "{#{converted}}" : converted}")
|
|
125
|
+
else
|
|
126
|
+
out << c
|
|
127
|
+
i += 1
|
|
128
|
+
end
|
|
129
|
+
else
|
|
130
|
+
out << c
|
|
131
|
+
i += 1
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
out
|
|
135
|
+
end
|
|
136
|
+
private_class_method :convert
|
|
137
|
+
|
|
138
|
+
def self.letters_at(chars, i)
|
|
139
|
+
name = +""
|
|
140
|
+
while i < chars.length && chars[i].match?(/\A[A-Za-z]\z/)
|
|
141
|
+
name << chars[i]
|
|
142
|
+
i += 1
|
|
143
|
+
end
|
|
144
|
+
name
|
|
145
|
+
end
|
|
146
|
+
private_class_method :letters_at
|
|
147
|
+
|
|
148
|
+
# The argument starting at `i`: a {braced group}, a \command, or one
|
|
149
|
+
# non-space character. Returns [inner_chars, braced?, next_index] or nil.
|
|
150
|
+
def self.argument_at(chars, i)
|
|
151
|
+
return nil if i >= chars.length
|
|
152
|
+
c = chars[i]
|
|
153
|
+
return nil if WHITESPACE.include?(c) || c == "}"
|
|
154
|
+
|
|
155
|
+
if c == "{"
|
|
156
|
+
close = matching_brace(chars, i)
|
|
157
|
+
return nil unless close
|
|
158
|
+
[chars[(i + 1)...close], true, close + 1]
|
|
159
|
+
elsif c == "\\" && !(name = letters_at(chars, i + 1)).empty?
|
|
160
|
+
[chars[i, 1 + name.length], false, i + 1 + name.length]
|
|
161
|
+
elsif c == "\\" && ESCAPABLE.include?(chars[i + 1])
|
|
162
|
+
[chars[i, 2], false, i + 2]
|
|
163
|
+
else
|
|
164
|
+
[[c], false, i + 1]
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
private_class_method :argument_at
|
|
168
|
+
|
|
169
|
+
def self.matching_brace(chars, open)
|
|
170
|
+
depth = 0
|
|
171
|
+
i = open
|
|
172
|
+
while i < chars.length
|
|
173
|
+
case chars[i]
|
|
174
|
+
when "\\" then i += 1
|
|
175
|
+
when "{" then depth += 1
|
|
176
|
+
when "}"
|
|
177
|
+
depth -= 1
|
|
178
|
+
return i if depth.zero?
|
|
179
|
+
end
|
|
180
|
+
i += 1
|
|
181
|
+
end
|
|
182
|
+
nil
|
|
183
|
+
end
|
|
184
|
+
private_class_method :matching_brace
|
|
185
|
+
|
|
186
|
+
def self.script(text, map)
|
|
187
|
+
return nil if text.empty?
|
|
188
|
+
mapped = text.chars.map { |ch| map[ch] }
|
|
189
|
+
mapped.all? ? mapped.join : nil
|
|
190
|
+
end
|
|
191
|
+
private_class_method :script
|
|
192
|
+
|
|
193
|
+
def self.wrap(text)
|
|
194
|
+
text.length > 1 ? "(#{text})" : text
|
|
195
|
+
end
|
|
196
|
+
private_class_method :wrap
|
|
197
|
+
|
|
198
|
+
# `\sqrt[n]{x}` starting just after "sqrt". Returns [text, next_index] or nil.
|
|
199
|
+
def self.sqrt_at(chars, i)
|
|
200
|
+
index = ""
|
|
201
|
+
if chars[i] == "["
|
|
202
|
+
offset = chars[i..].index("]")
|
|
203
|
+
return nil unless offset
|
|
204
|
+
close = i + offset
|
|
205
|
+
index = convert(chars[(i + 1)...close]).strip
|
|
206
|
+
i = close + 1
|
|
207
|
+
end
|
|
208
|
+
arg = argument_at(chars, i)
|
|
209
|
+
return nil unless arg
|
|
210
|
+
|
|
211
|
+
inner, _braced, after = arg
|
|
212
|
+
sign = ROOTS[index] || "#{script(index, SUPERSCRIPTS) || index}√"
|
|
213
|
+
["#{sign}#{wrap(convert(inner))}", after]
|
|
214
|
+
end
|
|
215
|
+
private_class_method :sqrt_at
|
|
216
|
+
|
|
217
|
+
# `\frac{a}{b}` starting just after "frac". Returns [text, next_index] or nil.
|
|
218
|
+
def self.frac_at(chars, i)
|
|
219
|
+
numerator = argument_at(chars, i)
|
|
220
|
+
return nil unless numerator
|
|
221
|
+
denominator = argument_at(chars, numerator[2])
|
|
222
|
+
return nil unless denominator
|
|
223
|
+
|
|
224
|
+
num = convert(numerator[0])
|
|
225
|
+
den = convert(denominator[0])
|
|
226
|
+
[VULGAR_FRACTIONS["#{num}/#{den}"] || "#{wrap(num)}/#{wrap(den)}", denominator[2]]
|
|
227
|
+
end
|
|
228
|
+
private_class_method :frac_at
|
|
229
|
+
end
|
|
230
|
+
end
|
data/lib/rage_flip/version.rb
CHANGED
data/lib/rage_flip.rb
CHANGED
|
@@ -4,6 +4,7 @@ require_relative "rage_flip/sarcasm"
|
|
|
4
4
|
require_relative "rage_flip/strikethrough"
|
|
5
5
|
require_relative "rage_flip/underline"
|
|
6
6
|
require_relative "rage_flip/italic"
|
|
7
|
+
require_relative "rage_flip/latex"
|
|
7
8
|
require_relative "rage_flip/chaos"
|
|
8
9
|
require_relative "rage_flip/clipboard"
|
|
9
10
|
require_relative "rage_flip/emote"
|
data/spec/rage_flip_spec.rb
CHANGED
|
@@ -150,6 +150,54 @@ RSpec.describe RageFlip do
|
|
|
150
150
|
end
|
|
151
151
|
end
|
|
152
152
|
|
|
153
|
+
describe RageFlip::Latex do
|
|
154
|
+
describe ".process" do
|
|
155
|
+
def latex(text) = RageFlip::Latex.process(text)
|
|
156
|
+
|
|
157
|
+
it "replaces symbol commands and keeps spacing as typed" do
|
|
158
|
+
expect(latex("\\alpha + \\beta \\to \\Omega")).to eq("α + β → Ω")
|
|
159
|
+
expect(latex("\\forall x \\in \\emptyset, x \\neq \\infty")).to eq("∀ x ∈ ∅, x ≠ ∞")
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "converts superscripts and subscripts" do
|
|
163
|
+
expect(latex("\\int_0^1 x^2 dx")).to eq("∫₀¹ x² dx")
|
|
164
|
+
expect(latex("x_{n+1} = x_n^2")).to eq("xₙ₊₁ = xₙ²")
|
|
165
|
+
expect(latex("\\sum_{i=1}^{n} i^{-1}")).to eq("∑ᵢ₌₁ⁿ i⁻¹")
|
|
166
|
+
expect(latex("H_2O and E = mc^2")).to eq("H₂O and E = mc²")
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "leaves scripts as typed when a character has no Unicode script form" do
|
|
170
|
+
expect(latex("e^{i\\pi}")).to eq("e^{iπ}")
|
|
171
|
+
expect(latex("x^{q}")).to eq("x^{q}")
|
|
172
|
+
expect(latex("a^ b_")).to eq("a^ b_")
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it "converts square and nth roots" do
|
|
176
|
+
expect(latex("\\sqrt{x+1}")).to eq("√(x+1)")
|
|
177
|
+
expect(latex("\\sqrt2 \\sqrt{x} \\sqrt\\pi")).to eq("√2 √x √π")
|
|
178
|
+
expect(latex("\\sqrt[3]{8} \\sqrt[4]{x} \\sqrt[5]{y}")).to eq("∛8 ∜x ⁵√y")
|
|
179
|
+
expect(latex("\\sqrt")).to eq("√")
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it "converts fractions" do
|
|
183
|
+
expect(latex("\\frac{1}{2} \\frac34")).to eq("½ ¾")
|
|
184
|
+
expect(latex("\\frac{a+b}{c}")).to eq("(a+b)/c")
|
|
185
|
+
expect(latex("\\frac{1}")).to eq("\\frac{1}")
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it "handles escapes, unknown commands and unbalanced braces" do
|
|
189
|
+
expect(latex("\\{x\\} 100\\% \\$5")).to eq("{x} 100% $5")
|
|
190
|
+
expect(latex("\\unknown \\alphax")).to eq("\\unknown \\alphax")
|
|
191
|
+
expect(latex("x^{2")).to eq("x^{2")
|
|
192
|
+
expect(latex("\\left( x \\right)^2")).to eq("( x )²")
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it "leaves plain text unchanged" do
|
|
196
|
+
expect(latex("Hello World 123 é 👍🏽")).to eq("Hello World 123 é 👍🏽")
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
153
201
|
describe RageFlip::Chaos do
|
|
154
202
|
let(:chaos_file) { File.expand_path("~/.chaos_level.txt") }
|
|
155
203
|
|
|
@@ -240,6 +288,32 @@ RSpec.describe RageFlip do
|
|
|
240
288
|
expect(RageFlip::Emote.process("rankine")).to eq("°R")
|
|
241
289
|
end
|
|
242
290
|
|
|
291
|
+
it "returns math symbols" do
|
|
292
|
+
expect(RageFlip::Emote.process("sqrt")).to eq("√")
|
|
293
|
+
expect(RageFlip::Emote.process("radical")).to eq("√")
|
|
294
|
+
expect(RageFlip::Emote.process("cbrt")).to eq("∛")
|
|
295
|
+
expect(RageFlip::Emote.process("integral")).to eq("∫")
|
|
296
|
+
expect(RageFlip::Emote.process("doubleintegral")).to eq("∬")
|
|
297
|
+
expect(RageFlip::Emote.process("summation")).to eq("∑")
|
|
298
|
+
expect(RageFlip::Emote.process("squared")).to eq("²")
|
|
299
|
+
expect(RageFlip::Emote.process("cubed")).to eq("³")
|
|
300
|
+
expect(RageFlip::Emote.process("plusminus")).to eq("±")
|
|
301
|
+
expect(RageFlip::Emote.process("infty")).to eq("∞")
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
it "returns superscript and subscript digits" do
|
|
305
|
+
superscripts = (0..9).map { |d| RageFlip::Emote.process("sup#{d}") }.join
|
|
306
|
+
subscripts = (0..9).map { |d| RageFlip::Emote.process("sub#{d}") }.join
|
|
307
|
+
expect(superscripts).to eq("⁰¹²³⁴⁵⁶⁷⁸⁹")
|
|
308
|
+
expect(subscripts).to eq("₀₁₂₃₄₅₆₇₈₉")
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
it "lists math symbols in their own category" do
|
|
312
|
+
math = RageFlip::Emote.get_category_emotes("math")
|
|
313
|
+
expect(math).to include("sqrt", "integral", "squared", "sup2", "sub2")
|
|
314
|
+
expect(math).to all(satisfy { |name| !RageFlip::Emote.emoji_only?(RageFlip::Emote::EMOTES[name]) })
|
|
315
|
+
end
|
|
316
|
+
|
|
243
317
|
it "handles case insensitive input" do
|
|
244
318
|
result = RageFlip::Emote.process("DISAPPROVAL")
|
|
245
319
|
expect(result).to eq("(ಠ_ಠ)")
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rage_flip
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Powell
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -53,6 +53,7 @@ executables:
|
|
|
53
53
|
- flip_text
|
|
54
54
|
- frustrated
|
|
55
55
|
- italic
|
|
56
|
+
- latex
|
|
56
57
|
- rage_flip
|
|
57
58
|
- sarcasm
|
|
58
59
|
- strikethrough
|
|
@@ -79,6 +80,7 @@ files:
|
|
|
79
80
|
- exe/flip_text
|
|
80
81
|
- exe/frustrated
|
|
81
82
|
- exe/italic
|
|
83
|
+
- exe/latex
|
|
82
84
|
- exe/rage_flip
|
|
83
85
|
- exe/sarcasm
|
|
84
86
|
- exe/strikethrough
|
|
@@ -92,6 +94,7 @@ files:
|
|
|
92
94
|
- lib/rage_flip/flipper.rb
|
|
93
95
|
- lib/rage_flip/frustrated.rb
|
|
94
96
|
- lib/rage_flip/italic.rb
|
|
97
|
+
- lib/rage_flip/latex.rb
|
|
95
98
|
- lib/rage_flip/sarcasm.rb
|
|
96
99
|
- lib/rage_flip/strikethrough.rb
|
|
97
100
|
- lib/rage_flip/text_substitution.rb
|