I have written a lualatex file with unicode characters such as α, ≤ …
Now I need to convert it to latex. Is there a script that converts the symbols to tex commands \alpha, \leq …?
I have written a lualatex file with unicode characters such as α, ≤ …
Now I need to convert it to latex. Is there a script that converts the symbols to tex commands \alpha, \leq …?
I am using the following python script. The result required some small tweaking.
#!/usr/bin/env python3
import sys
import fileinput
import unicode_tex
excluded_chars = ['\\', '&', '$', '{', '}', '%', ' ', '_', '~', '\'', '`', '^', '*', '#']
tex_replacements = unicode_tex.unicode_to_tex_map.copy()
for char in excluded_chars:
tex_replacements.pop(char)
with fileinput.FileInput(sys.argv[1], inplace=True, backup='.bak') as file:
for line in file:
for src, target in tex_replacements.items():
line = line.replace(src, target+"{}")
print(line, end='')
Convert to LaTeXwhich does exactly this - I allready said this once today, maybe the other comments might be of interest to you too http://tex.stackexchange.com/questions/316802/convert-pasted-characters-to-latex-equivalent – samcarter_is_at_topanswers.xyz Jun 27 '16 at 12:09atom– mlainz Jun 27 '16 at 12:10