1

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 …?

2

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='')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.