Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LaTeX completions of Greek variants, add \frakI and \frakR #39148

Merged
merged 4 commits into from
Jan 15, 2021

Conversation

knuesel
Copy link
Member

@knuesel knuesel commented Jan 8, 2021

Missing completions

This PR fixes two holes in the \frak... alphabet:

\frakI: same as \Im
\frakR: same as \Re

(Reference: https://www.unicode.org/charts/PDF/U1D400.pdf page 10.)

This is similar to how \euler is also mapped to \scre and \planck is also mapped to \ith.

Note that this leads to a change in the suggested completions:

help?> ℜℑ
"ℜℑ" can be typed by \Re<tab>\Im<tab>

becomes

help?> ℜℑ
"ℜℑ" can be typed by \frakR<tab>\frakI<tab>

Currently the reverse mapping is a bit random when there are several completions for one symbol, see:

symbols_latex[v] = k
If this is deemed a problem, maybe it would make sense to add an explicit reverse mapping for ambiguous cases?

Bad completions

Julia uses \varphi for the loopy variant of phi, and \varepsilon for the curly variant of epsilon (same as LaTeX). However Julia is not consistent with the style variants (italic, bold, sans...) of these letters:

help?> ϕ𝜙𝛟𝞍𝝓𝟇
"ϕ𝜙𝛟𝞍𝝓𝟇" can be typed by \phi<tab>\itvarphi<tab>\bfphi<tab>\bsansvarphi<tab>\bivarphi<tab>\bisansvarphi<tab>

help?> ϵ𝜖𝛜𝞊𝝐𝟄
"ϵ𝜖𝛜𝞊𝝐𝟄" can be typed by \epsilon<tab>\itvarepsilon<tab>\bfvarepsilon<tab>\bsansvarepsilon<tab>\bivarepsilon<tab>\bisansvarepsilon<tab>

This PR fixes the commands of the style variants.

Phi superscripts

This one might be more controversial.

Unicode distinguishes three variants of lowercase phi:

  • U+03d5 = "Greek phi symbol" = \phi in Julia and LaTeX
  • U+03c6 = "Greek small letter phi" = \varphi in Julia and LaTeX
  • U+0278 = "Latin small letter phi" = \ltphi, a phonetic symbol that looks like a \phi with small serifs

Based on these characters, Unicode defines two superscript phi letters:

  • U+1d60: modifier letter small Greek phi, based on "Greek phi symbol"
  • U+1db2: modifier letter small phi, based on "Latin small letter phi"

The first one is straightforward: it's like \phi but as superscript. Julia maps it to \^phi as expected.

The second one is problematic: it's a superscript version of \ltphi, yet Julia maps it to \^Phi.

This PR fixes it by remapping U+1db2 to \^ltphi. It's not as discoverable, but the current completion is misleading: a font could correctly implement \^Phi as something that doesn't really look like a superscript \Phi. And a future Unicode version might add a real superscript \Phi.

Note: the situation is similar to U+1d4b = \^epsilon: that Unicode character is actually a superscript version of the "Latin small letter open e" (rather thn "Greek small letter epsilon"). But it's different because Julia doesn't have \ltepsilon or \openepsilon, and Julia actually normalizes the "Latin" and "Greek" letters in this case (which is reasonable, they really look the same), see #14751.

@stevengj
Copy link
Member

stevengj commented Jan 9, 2021

It would be good to manually fix the REPL help dictionary in cases like this where there are multiple possible tab-completion options.

@stevengj stevengj added the REPL Julia's REPL (Read Eval Print Loop) label Jan 9, 2021
It is redundant with \join
A test checks that all ambiguous cases are handled.
@knuesel
Copy link
Member Author

knuesel commented Jan 9, 2021

I've added a canonical mapping for ambiguous cases (in latex_symbols.jl rather than docview.jl to keep all the mapping specifications in one file).

Looking at all the duplicates uncovered a few inconsistencies, so I made a few more changes to the completions suggested by the REPL. I generally chose the shorter option, which is often also the more mathematical meaning (e.g. \implies vs \Longrightarrow).

Duplicates were found with the following commands:

using REPL
ls = REPL.REPLCompletions.latex_symbols; symbols = values(ls)
duplicates = [v for v in unique(symbols) if count(==(v), symbols) > 1]
[(v, REPL.symbol_latex(v)) => findall(==(v), ls) for v in duplicates]

Here is the current list of duplicates (including changes from this PR):

         ("", "\\Re") => ["\\Re", "\\frakR"]
  ("", "\\impliedby") => ["\\impliedby", "\\Longleftarrow"], # was \Longleftarrow
         ("", "\\Im") => ["\\Im", "\\frakI"]
       ("", "\\sqrt") => ["\\surd", "\\sqrt"]
         ("", "\\ge") => ["\\ge", "\\geq"],  # was \geq
       ("", "\\male") => ["\\male", "\\mars"], # was \mars
         ("", "\\to") => ["\\to", "\\rightarrow"], # was \rightarrow
  ("", "\\rrbracket") => ["\\openbracketright", "\\rrbracket"]
     ("", "\\female") => ["\\venus", "\\female"]
   ("", "\\emptyset") => ["\\varnothing", "\\emptyset"]
       ("", "\\dots") => ["\\dots", "\\ldots"],  # was \ldots
        ("", "\\xor") => ["\\veebar", "\\xor"]
    ("", "\\implies") => ["\\implies", "\\Longrightarrow"], # was \Longrightarrow
  ("", "\\llbracket") => ["\\llbracket", "\\openbracketleft"], # was \openbracketleft
     ("", "\\planck") => ["\\ith", "\\planck"]
        ("", "\\del") => ["\\del", "\\nabla"], # was \nabla
        ("̶", "\\sout") => ["\\strike", "\\sout"]
 ("ε", "\\varepsilon") => ["\\upepsilon", "\\varepsilon"]
         ("ð", "\\dh") => ["\\eth", "\\dh"]
        ("", "\\iff") => ["\\Longleftrightarrow", "\\iff"]
      ("", "\\euler") => ["\\scre", "\\euler"]
         ("", "\\le") => ["\\le", "\\leq"], # was \leq

The left side shows the canonical mapping. Comments show the old one if it was changed by this PR.

The duplicate list also revealed that we had both \join and \Join for . I removed \Join.

A test is included to check that a canonical mapping is specified for all ambiguous cases.

@stevengj
Copy link
Member

stevengj commented Jan 9, 2021

I would maybe keep ("…", "\\ldots") to parallel \cdots, but otherwise LGTM.

@knuesel
Copy link
Member Author

knuesel commented Jan 9, 2021

Wouldn't a user likely prefer to know that the symbol is available as \dots? It seems a bit more memorable (and it's shorter of course). On the other hand, one can also argue that \ldots is more correct/explicit since in amsmath \dots adapts to context so it's not always three dots on the baseline.

Just making sure the case for \dots is made properly 😊 I'll happily change it if you still prefer \ldots.

@stevengj
Copy link
Member

\ldots seems less confusing to me from a LaTeX perspective.

@knuesel
Copy link
Member Author

knuesel commented Jan 11, 2021

OK! I've changed the suggestion to \ldots.

@stevengj
Copy link
Member

CI failure is apparently unrelated: LoadError: "hard kill repl test"?

@knuesel
Copy link
Member Author

knuesel commented Jan 12, 2021

Yes that looks like #38996.

@stevengj stevengj merged commit 0e6ed75 into JuliaLang:master Jan 15, 2021
@knuesel knuesel deleted the fix-greek-variants branch January 16, 2021 09:18
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
…Lang#39148)

* Fix LaTeX completions of Greek variants, add \frakI and \frakR

* Remove \Join completion

It is redundant with \join

* Add canonical symbol->LaTeX mapping for ambiguous cases

A test checks that all ambiguous cases are handled.

* Replace \dots suggestion with \ldots
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this pull request May 9, 2021
…Lang#39148)

* Fix LaTeX completions of Greek variants, add \frakI and \frakR

* Remove \Join completion

It is redundant with \join

* Add canonical symbol->LaTeX mapping for ambiguous cases

A test checks that all ambiguous cases are handled.

* Replace \dots suggestion with \ldots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants