diff --git a/tools/gen_latex_symbols.py b/tools/gen_latex_symbols.py index 280ff88..47cb8af 100644 --- a/tools/gen_latex_symbols.py +++ b/tools/gen_latex_symbols.py @@ -46,13 +46,10 @@ lines = [line_to_tuple(line) for line in lines] print('Filtering out characters that are not valid Python 3 identifiers') def test_ident(i): - """Is the unicode string a valid Python 3 identifer.""" - try: - exec('a%s = 10' % i, {}, {}) - except SyntaxError: - return False - else: - return True + """Is the unicode string valid in a Python 3 identifer.""" + # Some characters are not valid at the start of a name, but we still want to + # include them. So prefix with 'a', which is valid at the start. + return ('a' + i).isidentifier() assert test_ident("α") assert not test_ident('‴')