2

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

mlainz
  • 183
  • 1
    Which editor are you using? In TeXstudio there is a function Convert to LaTeX which 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:09
  • I am using atom – mlainz Jun 27 '16 at 12:10
  • Sublime has also a plugin to convert https://github.com/neilanderson/UnicodeTeX – yannisl Jun 27 '16 at 23:18

1 Answers1

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='')
mlainz
  • 183