Created
October 14, 2016 15:58
-
-
Save dreamlayers/ac7983ba13d84bf2b22447572c0261fc to your computer and use it in GitHub Desktop.
Transform text to math monospace
This file contains 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 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