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

RFC: tab substitution of LaTeX symbols in REPL #6911

Merged
merged 4 commits into from
May 22, 2014

Conversation

stevengj
Copy link
Member

This patch allows you to type things like \alpha<TAB> in the REPL to get α (as discussed in #6340). You can even type e.g. x\dot<TAB> to get .

Currently, you have to type out the whole LaTeX symbol....it seemed too complicated (at least in a first implementation) to support a two-level completion scheme where you could get a list of LaTeX symbols with a given prefix.

The list of substitutions is automatically generated from the W3C LaTeX/Unicode mapping.

@cbecker
Copy link
Contributor

cbecker commented May 21, 2014

Just gave it a try, very handy!

@StefanKarpinski
Copy link
Member

This is very slick. One thing that would be nice is to detect \ followed by something that could begin a LaTeX symbol name and list them, so \al<tab> would list \alpha, and whatever else is available. Currently it sees that al isn't a valid LaTeX name and decides that the backslash is an operator and just lists all and all!.

…looks like the most reasonable choice is listed first in the unicode.xml file
@stevengj
Copy link
Member Author

@StefanKarpinski, I agree that would be nice, but the REPL doesn't really seem to be set up right now to do that kind of 2-level substitution (since you really want to see the LaTeX symbol name first, I think, and not just a list of Unicode characters). My thinking was that this sort of refinement could go into a later patch.

Or are you thinking that you would hit TAB once and it would complete to \alpha, and then hit TAB again to get α?

@StefanKarpinski
Copy link
Member

Oh, absolutely. That's definitely a nice-to-have-later addition and not a show-stopper at all. I'm down to merge this right now :-)

@stevengj
Copy link
Member Author

Another plus: this patch uses a multiline comment.

@JeffBezanson
Copy link
Member

The astrological symbols feel a bit out of place :)

@stevengj
Copy link
Member Author

I always check the horoscope before naming my variables.

@stevengj
Copy link
Member Author

Interestingly, it seems to work out of the box in IJulia, too (at least in IPython 2.0; haven't tried 1.1). I was worried that we might need the upcoming IPython 3.0's protocol updates for it to function, but apparently not... cc: @fperez, @minrk

@stevengj
Copy link
Member Author

Now we just need to define what and mean for splatting. ;-)

@stevengj
Copy link
Member Author

This makes me want to do another pass on #6582 and define a whole bunch more aliases so that I can use (\cbrt) for cbrt, (\Re) for real, etcetera. cc: @jiahao

@StefanKarpinski
Copy link
Member

I propose that we use horoscope signs for base 12 numeric literals.

@jiahao
Copy link
Member

jiahao commented May 21, 2014

and Chinese for base-50,000 arithmetic.

@mbauman
Copy link
Member

mbauman commented May 21, 2014

+♈ for astro-literals. Astrologicals?

… What's Latex/Unicode doing here?

"\\mercury" => "☿",
"\\venus" => "♀",
"\\male" => "♂",
"\\jupiter" => "♃",

I've been meaning to play with two-phase tab completion for a while now. But it'll be tricky. The standard way to do it is that one-tab expands to the first branch, and then the second tab lists the options. Surely there are symbols whose names are a subset of other valid names. What happens then?

This is exciting.

@stevengj
Copy link
Member Author

@mbauman, I think the W3C unicode.xml file generally picked at most one LaTeX synonym per codepoint, but they weren't entirely consistent. (It's a technical report, not an official standard.) I've now manually added \female and \mars for consistency.

There are a whole bunch of other gender symbols in Unicode, but we can always add more later as needed. For now, I'm trying to stick to symbols with defined LaTeX names so that I'm not making up my own spellings.

@IainNZ
Copy link
Member

IainNZ commented May 22, 2014

👍 very cool

@StefanKarpinski
Copy link
Member

Since no one has complained that this isn't working and it seems that everyone loves the functionality, what say we merge it?

stevengj added a commit that referenced this pull request May 22, 2014
RFC: tab substitution of LaTeX symbols in REPL
@stevengj stevengj merged commit c5acdc7 into JuliaLang:master May 22, 2014
@johnmyleswhite
Copy link
Member

🍰

@jiahao
Copy link
Member

jiahao commented May 22, 2014

(image credit)

@tkelman
Copy link
Contributor

tkelman commented May 22, 2014

Agreed, this is really great. Now I'm wishing the default Windows console weren't so lousy and annoying to copy from (maybe I'll find and set up a better one), and that all editors would start doing this too!

@stevengj
Copy link
Member Author

You could just use IJulia... The Windows console is intolerable.

@tkelman
Copy link
Contributor

tkelman commented May 22, 2014

Grumble grumble Python dependency grumble grumble. But I may finally break down and do it now.

@StefanKarpinski
Copy link
Member

There's also Sublime Text, which works on Windows and has an add-on package that supports this exact behavior. It's pretty great being able to do this in the same way a) in the REPL, b) in my editor, and c) in IJulia.

@jiahao
Copy link
Member

jiahao commented May 22, 2014

The Julia REPL is quickly replacing the MacOS character palette as my Unicode IME of choice for all but the obscurest characters.

@Carreau
Copy link

Carreau commented May 27, 2014

Interestingly, it seems to work out of the box in IJulia, too (at least in IPython 2.0; haven't tried 1.1). I was worried that we might need the upcoming IPython 3.0's protocol updates for it to function, but apparently not... cc: @fperez, @minrk

Strange it does not work work me on 2.1 IJulia notebook, neither on master. I also got some exception with master :

KERNEL EXCEPTION
key not found: "text"
 in getindex at dict.jl:514
 in complete_request at /Users/matthiasbussonnier/.julia/IJulia/src/handlers.jl:16
 in eventloop at /Users/matthiasbussonnier/.julia/IJulia/src/IJulia.jl:68
 in anonymous at task.jl:335

Where text is a completion key which was removed in the new version of the protocol but should be automatically handled by the shim.

Anyway I wanted to propose also that [unicode symbol]<tab> would complete to [latex sequence] in order to easily know what to type when you do not get the full map in your head.

@stevengj
Copy link
Member Author

@Carreau, sounds like a bug in IPython, not sending the 4.0-protocol version of the complete_request?

@Carreau
Copy link

Carreau commented May 27, 2014

@Carreau, sounds like a bug in IPython, not sending the 4.0-protocol version of the complete_request?

Maybe but I can't it to work on 2.1 either, which does not use the new protocol, so I would like to have it to work (you said you had it to work in 2.x)

Base.REPLCompletions.completions("\\mars",5) seem to give the right thing, so it is not julia specific, will try to dig in kernel.jl

@Carreau
Copy link

Carreau commented May 27, 2014

@stevengj it does work if I replace completions in here by the exact reference to Base.REPLCompletions.completions apparently IJulia is picking things from REPLCompletions package which does not return the latex substitution if invoked from the REPL.

@stevengj
Copy link
Member Author

Hmm, that's weird, since IJulia.jl does

if isdefined(Base, :REPLCompletions)
    using Base.REPLCompletions
else
    using REPLCompletions
end

@vtjnash, is this the wrong way to conditionally include a module?

(Also, I don't understand how this could give a key not found: "text" exception. If it is using the old REPLCompletions package, the worst that would happen is that it wouldn't have the LaTeX tab completions.)

@Carreau
Copy link

Carreau commented May 27, 2014

Pkg was saying IJulia was up to date, but it was not, I reseted the git repo manualy to last master and it's ok. Wil investigate the errors on the 4.0 kernels adapter.

@stevengj
Copy link
Member Author

@Carreau, looks like I forgot to push to the METADATA for the latest IJulia; will fix ASAP. Actually, it seems it was already up-to-date; not sure what was wrong with your .julia directory. Maybe you had accidentally pinned it to an old version (by manually checking out an older revision)?

@Carreau
Copy link

Carreau commented May 27, 2014

Yep, maybe, and indeed you pushed to metadata 1 min after pushing to IJulia repo. Not sure what append. Anyway it does work with master IPython, the 4.0 adapter seem to swallow some logging errors though. Will narrow that and send upstream.

@Carreau
Copy link

Carreau commented May 28, 2014

Adapter should be fixed on IPython master the traceback handler had a forgotten parameter.
All seem fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unicode Related to unicode characters and encodings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants