Last active
July 19, 2025 13:50
-
-
Save smeech/ad764bc78e0d7a34daa738dde1e0938d to your computer and use it in GitHub Desktop.
[Fractions] The Espanso package `espanso-fractions` I use routinely, produces the eighteen single character expansions of small fractions. I thought I'd play with a solution for longer fractions using super- and sub-script characters, and came up with the following, which can be triggered by e.g. `:1234/4567 `. #espanso #python #html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- regex: :(?P<before>\d+)/(?P<after>\d+)(?P<end>\s) | |
replace: "{{output}}{{end}}" | |
vars: | |
- name: output | |
type: script | |
params: | |
args: | |
- python | |
- -c | |
- | | |
sup = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹") | |
sub = str.maketrans("0123456789", "₀₁₂₃₄₅₆₇₈₉") | |
print("{{before}}".translate(sup) + "/" + "{{after}}".translate(sub)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For expansion into an HTML environment, like Thunderbird, or Google Docs, | |
# the following is simpler, avoids the need for a script, and produces a | |
# nicer output: | |
- regex: ;(?P<before>\d+)/(?P<after>\d+)(?P<end>\s) | |
html: | | |
<sup style="vertical-align: top; font-size: 0.6em;">{{before}}</sup>/ | |
<sub style="vertical-align: bottom; font-size: 0.6em;">{{after}}</sub> | |
<span style="all: unset;">{{end}}</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment