JuliaEditorSupport / Julia-sublime

Julia syntax highlighting for Sublime Text
Other
117 stars 35 forks source link

Conversion between unicodes and Greek letters #49

Open randy3k opened 7 years ago

randy3k commented 7 years ago

@ViktorQvarfordt

I have justed add a conversion functionality in UnicodeCompletion which basically converts between \alpha and α, which is quite useful in LaTeX documents. However, while I am writing a julia script file, I usual have

mu = 0
sigma = 1
z = sqrt(mu/sigma)

It would be interesting to convert this to

μ = 0
σ = 1
z = √(μ/σ)

So the questions are

  1. Shall we ship this functionality in this package or a separate package?
  2. Obviously, not all symbols should be supported, besides greeks, what symbols should be included?
ViktorQvarfordt commented 7 years ago

I like this!

Some thoughts, remarks and questions:

  1. What's your view on the packages UnicodeMath and UnicodeTeX, they seem very similar to UnicodeCompletion.

  2. I have this experimental sublime package InstantUnicode ongoing. The intentions of this seems to be similar to what you discuss. What do you think of this?

  3. A while ago I found this script (cannot find the original), which essentially does what you describe. Just wanted to mention this as a reference. I don't use it that much any more, now that I have your plugin UnicodeCompletion and my experimental package mentioned above. But sometimes this is nice, and thus I like this new feature of UnicodeCompletion.

  4. You say you write with unicode in you LaTeX document, how do you do this? Do you use LuaTeX and unicode-math or \newunicodechar{α}{\alpha} (i've tried this, but it has limitations), or something else? I would love to go full unicode in my LaTeX documents (and everywhere else, but that's easier). Some argue one should not use unicode in the document, but rather use something like vim's :set conceallevel=2. Thoughts?

I like the use of unicode, and I welcome this discussion! Furthermore, it would be nice if all (most) unicode initiatives could be unified and somewhat standardized (thus asking what you think about the other ones in 1.)

randy3k commented 7 years ago
  1. Actually, I used to use UnicodeMath too, but it's completion system is not compatible with Julia, that's why I started the JuliaUnicode project, which was then merged into this repo. UnicodeMath is great, but it is lacking a standard (and it is buggy sometimes, \varepsilon is mapped to ϵ (\U03F5) instead of ε (\U03B5)). One of the primary factors that I am still using UnicodeCompletion is because of the community maintained table of unicodes. I haven't tried UnicodeTeX, but I will assume it will be similar. Also, they convert \alpha to α but not alpha to α.

  2. Sublime-InstantUnicode looks like what I am looking for, but it only converts while typing. I want to also convert existing scripts.

  3. As UnicodeMath and UnicodeCompletion, the script only converts latex commands to unicodes. We need a julia aware convertor. We definitely don't want to convert x^2 to .

  4. I use XeLaTeX. In fact, I do markdown more..

    
    \documentclass{article}
    \usepackage{fontspec}
    \usepackage{unicode-math}
    \setmainfont{Times New Roman}
    \begin{document}
    \[
    γ = α^2 + β^2
    \]

\end{document}

ViktorQvarfordt commented 7 years ago
  1. Indeed, for this package (Julia-sublime) we only want Julia-aware substitutions. More generally, it seems there are three use cases, Julia, LaTeX and plaintext (maybe the LaTeX and plaintext are the same in this perspective). When writing emails or whatever it is very nice if x^2 is converted to . I guess UnicodeCompletion wants to cover all cases? (I had UnicodeCompletion, not JuliaSublime, in mind when I wrote the previous post.)

  2. Nice, why Times New Roman though? Anyhow, is α^2 the same as α²? I see that α^{23} is not the same as α²³ (wrong spacing) unfortunately. Do you know of any method that allow repeated sub/superscripts to be used correctly?

randy3k commented 7 years ago
  1. Plain text support should be a superset of latex support. While \alpha to α in latex docs, conversion from alpha to α should be also supported in plain text docs. And UnicodeCompletion is moving to this direction ultimately.

  2. A font is needed if unicodes are used outside of math env, e.g.,

    The value of α is 1.
    \[
    γ = α^2 + β^2
    \]

    But why Times New Roman? It just works. And for the super/subscripts,

    \[
    α²³ = β₁₅ = ∫₀¹ f(x) dx
    \]

    They look good to me. screen shot 2017-04-24 at 6 29 03 pm

ViktorQvarfordt commented 7 years ago
  1. Sounds good.

  2. My bad, at first glance I thought α²³ was mapped to α^2{}^3 which has too much spacing. Btw, sidenote, do you know why unicode-math cannot support the default font cm-super? I.e so that α is shown as the glyph represented by \alpha. (I see Latin Modern exists, which is similar but not quite the same.)

Regarding your questions:

  1. Shall we ship this functionality in this package or a separate package? Not sure, I like to limit the scope of plugins. In principle, a syntax highlighter should perhaps not do unicode conversions. An option is to let JuliaSublime just have REPL-style unicode completion (essentially like we have it now). Or, it's worth playing with the idea, to remove all unicode-code from JuliaSublime and refer to UnicodeCompletion in the readme. Or, by the reasoning that Julia promotes unicode usage, throw in as much as possible from UnicodeCompletion. What are your thoughts on this?
  2. Obviously, not all symbols should be supported, besides greeks, what symbols should be included? A good choice is the operators that Julia supports, as listed here https://github.com/JuliaEditorSupport/Julia-sublime/blob/master/Julia.sublime-syntax#L28.
randy3k commented 7 years ago

I guess it is because Computer Modern (the default latex font) only has limited support of unicodes.

http://www.gust.org.pl/projects/e-foundry/lm-math suggests using Latin Modern Math font, so it may be the best option already.