##// END OF EJS Templates
Avoid calling the input transformer twice in the execution stack....
Avoid calling the input transformer twice in the execution stack. This should allow to register input transformers that have side effects, at least in Notebooks. Right now there are sill multiple calls which may happen in the terminal on execution requests.

File last commit:

r25245:39b51818
r25891:d5a8359c
Show More
gen_latex_symbols.py
88 lines | 2.7 KiB | text/x-python | PythonLexer
/ tools / gen_latex_symbols.py
Brian E. Granger
Adding script to generate latex_symbols.py.
r17744 # coding: utf-8
# This script autogenerates `IPython.core.latex_symbols.py`, which contains a
# single dict , named `latex_symbols`. The keys in this dict are latex symbols,
# such as `\\alpha` and the values in the dict are the unicode equivalents for
luzpaz
Misc. typo fixes...
r24084 # those. Most importantly, only unicode symbols that are valid identifiers in
Brian E. Granger
Adding script to generate latex_symbols.py.
r17744 # Python 3 are included.
#
# The original mapping of latex symbols to unicode comes from the `latex_symbols.jl` files from Julia.
Brian E. Granger
Updating gen_latex_symbols.py
r17745 import os, sys
Brian E. Granger
Adding script to generate latex_symbols.py.
r17744 # Import the Julia LaTeX symbols
print('Importing latex_symbols.js from Julia...')
import requests
Massimo Santini
Attempt to fix latex symbols in the completer
r24703 url = 'https://raw.githubusercontent.com/JuliaLang/julia/master/stdlib/REPL/src/latex_symbols.jl'
Brian E. Granger
Adding script to generate latex_symbols.py.
r17744 r = requests.get(url)
# Build a list of key, value pairs
Andrew Murray
Fixed typo
r21530 print('Building a list of (latex, unicode) key-value pairs...')
Massimo Santini
Attempt to fix latex symbols in the completer
r24703 lines = r.text.splitlines()
prefixes_line = lines.index('# "font" prefixes')
symbols_line = lines.index('# manual additions:')
prefix_dict = {}
for l in lines[prefixes_line + 1: symbols_line]:
p = l.split()
if not p or p[1] == 'latex_symbols': continue
prefix_dict[p[1]] = p[3]
idents = []
for l in lines[symbols_line:]:
if not '=>' in l: continue # if it's not a def, skip
if '#' in l: l = l[:l.index('#')] # get rid of eol comments
x, y = l.strip().split('=>')
if '*' in x: # if a prefix is present substitute it with its value
p, x = x.split('*')
x = prefix_dict[p][:-1] + x[1:]
x, y = x.split('"')[1], y.split('"')[1] # get the values in quotes
idents.append((x, y))
Brian E. Granger
Adding script to generate latex_symbols.py.
r17744
# Filter out non-valid identifiers
print('Filtering out characters that are not valid Python 3 identifiers')
def test_ident(i):
luz.paz
Misc. typos fixes...
r24132 """Is the unicode string valid in a Python 3 identifier."""
Thomas Kluyver
Simplify test_ident using str.isidentifier()...
r17807 # 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()
Brian E. Granger
Adding script to generate latex_symbols.py.
r17744
assert test_ident("α")
assert not test_ident('‴')
Massimo Santini
Attempt to fix latex symbols in the completer
r24703 valid_idents = [line for line in idents if test_ident(line[1])]
Brian E. Granger
Adding script to generate latex_symbols.py.
r17744
# Write the `latex_symbols.py` module in the cwd
s = """# encoding: utf-8
Brian E. Granger
Updating gen_latex_symbols.py
r17745 # DO NOT EDIT THIS FILE BY HAND.
# To update this file, run the script /tools/gen_latex_symbols.py using Python 3
Brian E. Granger
Adding script to generate latex_symbols.py.
r17744 # This file is autogenerated from the file:
# https://raw.githubusercontent.com/JuliaLang/julia/master/base/latex_symbols.jl
# This original list is filtered to remove any unicode characters that are not valid
# Python identifiers.
latex_symbols = {\n
"""
for line in valid_idents:
s += ' "%s" : "%s",\n' % (line[0], line[1])
s += "}\n"
Matthias Bussonnier
worjk latex completion and back
r21101 s += """
reverse_latex_symbol = { v:k for k,v in latex_symbols.items()}
"""
Brian E. Granger
Updating gen_latex_symbols.py
r17745 fn = os.path.join('..','IPython','core','latex_symbols.py')
print("Writing the file: %s" % fn)
with open(fn, 'w', encoding='utf-8') as f:
Brian E. Granger
Adding script to generate latex_symbols.py.
r17744 f.write(s)