Skip to content

Instantly share code, notes, and snippets.

@dreamlayers
Created October 14, 2016 15:58
Show Gist options
  • Save dreamlayers/ac7983ba13d84bf2b22447572c0261fc to your computer and use it in GitHub Desktop.
Save dreamlayers/ac7983ba13d84bf2b22447572c0261fc to your computer and use it in GitHub Desktop.
Transform text to math monospace
#!/usr/bin/env python3
import sys
def mathmono(s):
res = ''
for c in s:
cn = ord(c)
if cn >= ord('a') and cn <= ord('z'):
cn += 0x1D68A - ord('a')
elif cn >= ord('A') and cn <= ord('Z'):
cn += 0x1D670 - ord('A')
elif cn >= ord('0') and cn <= ord('9'):
cn += 0x1D7F6 - ord('0')
elif cn == 0x20:
cn = 0x205F
res += chr(cn)
return res
if (len(sys.argv) > 1):
for arg in sys.argv[1:-1]:
print(mathmono(arg), end=' ')
print(mathmono(sys.argv[-1]))
else:
for line in sys.stdin:
print(mathmono(line), end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment