4

I'm used to do

??symbol

when I want the reference for a given symbol, then I click on the >> arrows to open the help window.

Would it be possible to redefine the meaning of ?? in order to open the reference window directly ?

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Cedric H.
  • 696
  • 1
  • 4
  • 15

2 Answers2

9

The simplest (and canonical) method is to place the keyboard cursor in the Symbol name, or select it with a double-click, and press F1 if you use Windows/Linux or Command-Shift-F if you use OS X. This will bring up the Help for that item. This also works with compound operators, e.g. /;.

Nevertheless I like a challenge, therefore:

$PreRead =
  # /. RowBox[{"??", name_String}] :>
    FrontEndTokenExecute["OpenHelpLink", name] &;

Now this brings up the Help page for Fold directly:

?? Fold

While this will search the documentation for the term "Fold":

?? "Fold"

I chose $PreRead for this purpose so that it will not interfere with internal calls to Information.
You can also get the original behavior by writing out Information, e.g.:

? Plus

x+y+z represents a sum of terms.  >>

Information[Plus]  (* equivalent to ??Plus *)

x+y+z represents a sum of terms.  >>

Attributes[Plus]={Flat,Listable,NumericFunction,OneIdentity,Orderless,Protected}

Default[Plus]:=0
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • 2
    @Kuba Yes, the same in v7, which is why I stated "place the keyboard cursor in the Symbol name" but you need to select some operators for F1 to work; for example, try placing the cursor between the two ^ characters in 2^^10010 -- it does not work. However, selecting ^^ and pressing F1 directs you to the documentation for BaseForm. – Mr.Wizard Feb 05 '14 at 10:32
  • Good point :).. – Kuba Feb 05 '14 at 10:35
  • Note that on OS X, F1 also works. – TransferOrbit Feb 05 '14 at 18:40
3

The typical way to search the documentation is the keyboard shortcut Mr Wizard mentioned. In general, you can find the shortcut key for a command by looking in the menu ...

enter image description here

If you are looking for a built-in way to open a documentation pages using a built-in command, then you are looking for Documentation`HelpLookup.

Documentation`HelpLookup["euler"]

will open the documentation centre and do a search for "euler". It returns a reference to the notebook window containing the search result. The behaviour equivalent to typing the search term into the documentation search box.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • 1
    This method appears to have a massive overhead compared to "OpenHelpLink". Documentation`HelpLookup["Fold"] // Trace // LeafCount yields 104848 while FrontEndTokenExecute["OpenHelpLink", "Fold"] // Trace // LeafCount yields 21. What is HelpLookup doing and what is its benefit over "OpenHelpLink"? – Mr.Wizard Feb 05 '14 at 16:36
  • @Mr.Wizard As Szabolcs said, HelpLookup returns a notebook object, which can be very useful whereas "OpenHelpLink" returns Null, which makes it useful only for this particular evaluation and cannot be used in other programs/applications, etc. More importantly, does the leaf count matter for OP's question? :) – rm -rf Feb 05 '14 at 16:50
  • @rm-rf In version 7 HelpLookup also returns Null. It may not matter, but it does make me wonder about the overhead, and if given the choice between two methods that are apparently otherwise equivalent (in v7) I'll pick the one that seems to have less overhead. – Mr.Wizard Feb 05 '14 at 17:54
  • @Mr.Wizard Then you definitely do not want to look at the leaf count in the latest version — 1727136 vs. 21 :) – rm -rf Feb 05 '14 at 18:03
  • 1
    @Mr.Wizard It's an interactive operation. You are going to look at the result and read it. Does it really matter if it takes 0.1 seconds or 0.01 seconds, or does it really influence your choice? ;-) Also, what takes longer: opening the window and displaying the contents or running the function in the kernel? – Szabolcs Feb 05 '14 at 18:10
  • @rm-rf lol. Szabolcs, no, it probably doesn't matter, but I'm still wondering when one would prefer HelpLookup over "OpenHelpLink", and perhaps more importantly why there is a seemingly large difference in what is going on behind the scenes. Is the same work being done, only by the FrontEnd, with "OpenHelpLink"? – Mr.Wizard Feb 05 '14 at 18:14
  • 1
    @Mr.Wizard I would have used HelpLookup for the simple reason that I've seen it before and I remembered it, so it's less searching for me. I think you'd use OpenHelpLink for the same reason. I think that ultimately both will end up running the same code, and that OpenHelpLink will end up doing kernel evaluations as well. This is a guess that might be wrong. One might test it by using LinkSnooper to monitor the kernel-frontend communication during help lookup, but I don't think I'm going to spend the time to do it. – Szabolcs Feb 05 '14 at 18:18
  • @Mr.Wizard Anyway, this function is just an alternative, so I posted it. I am not arguing that it's better than your solution. It's worse in that it's not documented. Ultimately it's just a different solution, so why not post it? – Szabolcs Feb 05 '14 at 18:19
  • Agreed! Sorry for being overly critical; I did not mean to direct that at you. I was just a bit stunned when I tried a Trace and got a massive output for this function. By the way, I did not vote for your answer, but only because you did not (yet) provide a solution to open a help page using ??name. – Mr.Wizard Feb 05 '14 at 18:21