7
$\begingroup$

I would like a documentation function that works like that following.

doc["search terms"]

and it displays the list of search terms.

And then doc["search terms",2] displays the second result. The important key here is that the printed out values and part of the print out.

EDIT: So I have added a bounty because I would like to do this without bringing up the window everytime.

$\endgroup$
  • 1
    $\begingroup$ Something like this (incomplete)? doc = Import@Documentation`ResolveLink["Tab"]; Cases[doc, TemplateBox[{Cell[TextData[name_]], link_}, "SearchResultLink", ___] :> {name, link}, Infinity] $\endgroup$ – Szabolcs Sep 14 '16 at 8:24
  • $\begingroup$ @Szabolcs It appears calling you function with the name displays the actual page which isn't perfect but does work. How do you recommend accounting for page numbers and distinguishing searching and displaying a page $\endgroup$ – William Sep 14 '16 at 14:26
4
$\begingroup$

I haven't figured out how to do this without having the documentation pop up for a second but this is the basic idea.

doc[i_] := (
   n = Documentation`HelpLookup[i]; nG = NotebookGet[n]; 
   NotebookClose[n]; 
   CellPrint@Replace[nG, Notebook[{x___}, y___] :> {x}]
   );
doc["Print"]
$\endgroup$
  • 2
    $\begingroup$ FYI this reliably crashes version 11.0.0 for me (Windows). $\endgroup$ – chuy Sep 14 '16 at 14:49
  • $\begingroup$ @chuy does the version Szabolics have in the comments above work? doc = Import@Documentation``ResolveLink["Tab"]; Cases[doc, TemplateBox[{Cell[TextData[name_]], link_}, "SearchResultLink", ___] :> {name, link}, Infinity] $\endgroup$ – William Sep 14 '16 at 15:05
  • 1
    $\begingroup$ Yes it works (no crash) $\endgroup$ – chuy Sep 14 '16 at 15:36
  • 1
    $\begingroup$ Mathematica 11.0 crashes when CellPrint acts on the result of Replace[nG, Notebook[{x___}, y___] :> {x}]. $\endgroup$ – bbgodfrey Sep 21 '16 at 1:05
  • $\begingroup$ @bbgodfrey Does the version I posted above as a comment work? $\endgroup$ – William Sep 21 '16 at 1:11
3
$\begingroup$

This should be a good starting point:

nb = Import@Documentation`ResolveLink["NSolve start:1"];

Cases[nb, Cell[___, "SearchResultCell", ___], Infinity]

There's no popup. start:1 causes this to get the first page of search results (instead of going directly to the NSolve page).

In v10.1 or later, use

NotebookImport[ 
    Documentation`ResolveLink["NSolve start:1"],
    "SearchResultCell" 
]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.