Unicode 输入表

在 Julia REPL 或其它编辑器中,可以像输入 LaTeX 符号一样,用 tab 补全下表列出的 Unicode 字符。在 REPL 中,可以先按 ? 进入帮助模式,然后将 Unicode 字符复制粘贴进去,一般在文档开头就会写输入方式。

!!! warning

  1. 此表第二列可能会缺失一些字符,对某些字符的显示效果也可能会与在 Julia REPL 中不一致。如果发生了这种状况,强烈建议用户检查一下浏览器或 REPL 的字体设置,目前已知很多字体都有显示问题。
  1. #
  2. # Generate a table containing all LaTeX and Emoji tab completions available in the REPL.
  3. #
  4. import REPL, Markdown
  5. const NBSP = '\u00A0'
  6. function tab_completions(symbols...)
  7. completions = Dict{String, Vector{String}}()
  8. for each in symbols, (k, v) in each
  9. completions[v] = push!(get!(completions, v, String[]), k)
  10. end
  11. return completions
  12. end
  13. function unicode_data()
  14. file = normpath(Sys.BINDIR, "..", "UnicodeData.txt")
  15. names = Dict{UInt32, String}()
  16. open(file) do unidata
  17. for line in readlines(unidata)
  18. id, name, desc = split(line, ";")[[1, 2, 11]]
  19. codepoint = parse(UInt32, "0x$id")
  20. names[codepoint] = titlecase(lowercase(
  21. name == "" ? desc : desc == "" ? name : "$name / $desc"))
  22. end
  23. end
  24. return names
  25. end
  26. # Surround combining characters with no-break spaces (i.e '\u00A0'). Follows the same format
  27. # for how unicode is displayed on the unicode.org website:
  28. # http://unicode.org/cldr/utility/character.jsp?a=0300
  29. function fix_combining_chars(char)
  30. cat = Base.Unicode.category_code(char)
  31. return cat == 6 || cat == 8 ? "$NBSP$char$NBSP" : "$char"
  32. end
  33. function table_entries(completions, unicode_dict)
  34. entries = [[
  35. "Code point(s)", "Character(s)",
  36. "Tab completion sequence(s)", "Unicode name(s)"
  37. ]]
  38. for (chars, inputs) in sort!(collect(completions), by = first)
  39. code_points, unicode_names, characters = String[], String[], String[]
  40. for char in chars
  41. push!(code_points, "U+$(uppercase(string(UInt32(char), base = 16, pad = 5)))")
  42. push!(unicode_names, get(unicode_dict, UInt32(char), "(No Unicode name)"))
  43. push!(characters, isempty(characters) ? fix_combining_chars(char) : "$char")
  44. end
  45. push!(entries, [
  46. join(code_points, " + "), join(characters),
  47. join(inputs, ", "), join(unicode_names, " + ")
  48. ])
  49. end
  50. return Markdown.Table(entries, [:l, :l, :l, :l])
  51. end
  52. table_entries(
  53. tab_completions(
  54. REPL.REPLCompletions.latex_symbols,
  55. REPL.REPLCompletions.emoji_symbols
  56. ),
  57. unicode_data()
  58. )