Created
September 15, 2018 22:11
-
-
Save WhiteAbeLincoln/7b87169b8f4e1b2759597ef18c9ea542 to your computer and use it in GitHub Desktop.
Generate mathematical symbol XCompose mappings
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
#!/usr/bin/env python3 | |
import unicodedata | |
import sys | |
# | |
# Helper script to generate XCompose files | |
# | |
# Usage: | |
# | |
# ./gen_x_compose.py >Compose | |
# | |
# Output in file 'Compose' then has to be manually adjusted | |
# | |
# How to use XCompose instructions on askubuntu.com: | |
# https://askubuntu.com/a/877344/99330 | |
# | |
# adapted from https://github.com/rybak/scripts/blob/master/extra/gen_x_compose.py | |
# and made to work with arbitrary unicode ranges and prefixes | |
def debug(x): | |
print(x, file=sys.stderr) | |
def print_alphabet(starters, latin_start, unicode_start, size): | |
for i in range(0, size): | |
latin_letter = chr(latin_start + i) | |
unicode_letter = chr(unicode_start + i) | |
prefix = ' '.join([f'<{s}>' for s in starters]) | |
try: | |
comment = unicodedata.name(unicode_letter) | |
print("<Multi_key> " + prefix + " <{}> : \"{}\" U{:04X} # {}".format( | |
latin_letter, | |
unicode_letter, | |
ord(unicode_letter), | |
comment | |
)) | |
except: | |
# undefined Unicode code point | |
debug("Skipping...") | |
pass | |
print('# MATHEMATICAL BOLD') | |
BOLD_A = ord('π') | |
BOLD_Z = ord('π') | |
print_alphabet(['m', 'b'], ord('A'), BOLD_A, BOLD_Z - BOLD_A + 1) | |
BOLD_a = ord('π') | |
BOLD_z = ord('π³') | |
print_alphabet(['m', 'b'], ord('a'), BOLD_a, BOLD_z - BOLD_a + 1) | |
print('# MATHEMATICAL ITALIC') | |
ITALIC_A = ord('π΄') | |
ITALIC_Z = ord('π') | |
print_alphabet(['m', 'i'], ord('A'), ITALIC_A, ITALIC_Z - ITALIC_A + 1) | |
ITALIC_a = ord('π') | |
ITALIC_z = ord('π§') | |
print_alphabet(['m', 'i'], ord('a'), ITALIC_a, ITALIC_z - ITALIC_a + 1) | |
print('# MATHEMATICAL BOLD ITALIC') | |
ITALIC_B_A = ord('π¨') | |
ITALIC_B_Z = ord('π') | |
print_alphabet(['m', 'I'], ord('A'), ITALIC_B_A, ITALIC_B_Z - ITALIC_B_A + 1) | |
ITALIC_B_a = ord('π') | |
ITALIC_B_z = ord('π') | |
print_alphabet(['m', 'I'], ord('a'), ITALIC_B_a, ITALIC_B_z - ITALIC_B_a + 1) | |
print('# MATHEMATICAL SCRIPT') | |
SCRIPT_A = ord('π') | |
SCRIPT_Z = ord('π΅') | |
print_alphabet(['m', 's'], ord('A'), SCRIPT_A, SCRIPT_Z - SCRIPT_A + 1) | |
SCRIPT_a = ord('πΆ') | |
SCRIPT_z = ord('π') | |
print_alphabet(['m', 's'], ord('a'), SCRIPT_a, SCRIPT_z - SCRIPT_a + 1) | |
print('# MATHEMATICAL BOLD SCRIPT') | |
SCRIPT_B_A = ord('π') | |
SCRIPT_B_Z = ord('π©') | |
print_alphabet(['m', 'S'], ord('A'), SCRIPT_B_A, SCRIPT_B_Z - SCRIPT_B_A + 1) | |
SCRIPT_B_a = ord('πͺ') | |
SCRIPT_B_z = ord('π') | |
print_alphabet(['m', 'S'], ord('a'), SCRIPT_B_a, SCRIPT_B_z - SCRIPT_B_a + 1) | |
print('# MATHEMATICAL FRACTUR') | |
FRACTUR_A = ord('π') | |
FRACTUR_Z = ord('π') # not actually Z, since Z is in a different symbols block | |
print_alphabet(['m', 'f'], ord('A'), FRACTUR_A, FRACTUR_Z - FRACTUR_A + 1) | |
FRACTUR_a = ord('πΆ') | |
FRACTUR_z = ord('π') | |
print_alphabet(['m', 'f'], ord('a'), FRACTUR_a, FRACTUR_z - FRACTUR_a + 1) | |
print('# MATHEMATICAL DOUBLE-STRUCK') | |
DOUBLE_A = ord('πΈ') | |
DOUBLE_Z = ord('π') # not actually Z, since Z is in a different symbols block | |
print_alphabet(['m', 'd'], ord('A'), DOUBLE_A, DOUBLE_Z - DOUBLE_A + 1) | |
DOUBLE_a = ord('π') | |
DOUBLE_z = ord('π«') | |
print_alphabet(['m', 'd'], ord('a'), DOUBLE_a, DOUBLE_z - DOUBLE_a + 1) | |
print('# MATHEMATICAL BOLD FRACTUR') | |
FRACTUR_B_A = ord('π¬') | |
FRACTUR_B_Z = ord('π ') | |
print_alphabet(['m', 'F'], ord('A'), FRACTUR_B_A, FRACTUR_B_Z - FRACTUR_B_A + 1) | |
FRACTUR_B_a = ord('π') | |
FRACTUR_B_z = ord('π') | |
print_alphabet(['m', 'F'], ord('a'), FRACTUR_B_a, FRACTUR_B_z - FRACTUR_B_a + 1) | |
print('# MATHEMATICAL LETTER-LIKE SYMBOLS') | |
# plank's constant, or italic h | |
print_alphabet(['m', 'i'], ord('h'), ord('β'), 1) | |
# script | |
print_alphabet(['m', 's'], ord('B'), ord('β¬'), 1) | |
print_alphabet(['m', 's'], ord('E'), ord('β°'), 1) | |
print_alphabet(['m', 's'], ord('F'), ord('β±'), 1) | |
print_alphabet(['m', 's'], ord('H'), ord('β'), 1) | |
print_alphabet(['m', 's'], ord('I'), ord('β'), 1) | |
print_alphabet(['m', 's'], ord('L'), ord('β'), 1) | |
print_alphabet(['m', 's'], ord('M'), ord('β³'), 1) | |
print_alphabet(['m', 's'], ord('R'), ord('β'), 1) | |
# script lower | |
print_alphabet(['m', 's'], ord('e'), ord('β―'), 1) | |
print_alphabet(['m', 's'], ord('g'), ord('β'), 1) | |
print_alphabet(['m', 's'], ord('o'), ord('β΄'), 1) | |
# fractur | |
print_alphabet(['m', 'f'], ord('C'), ord('β'), 1) | |
print_alphabet(['m', 'f'], ord('H'), ord('β'), 1) | |
print_alphabet(['m', 'f'], ord('I'), ord('β'), 1) | |
print_alphabet(['m', 'f'], ord('R'), ord('β'), 1) | |
print_alphabet(['m', 'f'], ord('Z'), ord('β¨'), 1) | |
# double-struck | |
print_alphabet(['m', 'd'], ord('C'), ord('β'), 1) | |
print_alphabet(['m', 'd'], ord('H'), ord('β'), 1) | |
print_alphabet(['m', 'd'], ord('N'), ord('β'), 1) | |
print_alphabet(['m', 'd'], ord('P'), ord('β'), 1) | |
print_alphabet(['m', 'd'], ord('Q'), ord('β'), 1) | |
print_alphabet(['m', 'd'], ord('R'), ord('β'), 1) | |
print_alphabet(['m', 'd'], ord('Z'), ord('β€'), 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment