5

Every pages in the documentation has a hyperlink. Here are some examples:

"paclet:ref/NotebookRead"
"paclet:guide/GraphStylingAndLabeling"
"paclet:tutorial/ListsOverview"

Well, my question is:

If I open a docs page, then how can I get the hyperlink of it programmatically?

my tries

Till now, I can get the NotebookInformation of documentation notebooks (if it exist):

Select[NotebookInformation /@ 
     Notebooks[], ("DocumentType" /. #) == "Help" &]

The output might be:

{{"FileName" -> 
   FrontEnd`FileName[{$RootDirectory, "C:", "Program Files", 
 "Wolfram Research", "Mathematica", "9.0", "Documentation", 
 "ChineseSimplified", "System", "Tutorials"}, "ListsOverview.nb", 
     CharacterEncoding -> "CP936"], 
  "FileModificationTime" -> 3.56977*10^9, 
 "WindowTitle" -> "List - Wolfram Mathematica", 
"MemoryModificationTime" -> 3.58634*10^9, 
  "ModifiedInMemory" -> True, "DocumentType" -> "Help", 
 "StyleDefinitions" -> {NotebookObject[
    FrontEndObject[LinkObject["d5i_shm", 3, 1]], 46]}}}

But I don't know what to do next. The correspondence between the FileName and hyperlink seems to be confusing.

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
mmjang
  • 2,583
  • 20
  • 26

2 Answers2

7

Not very sophisticated but works so far:

nb = (Select[Notebooks[], ("DocumentType" /. NotebookInformation[#]) == "Help" &])

"uri" /. Options[Options[#, TaggingRules][[1, 2]], Metadata][[1, 2]] & /@ nb
{"tutorial/SettingUpFunctionsWithOptionalArguments"}

Please tell me if this works for you too.

Edit

Shorter one:

nb = (Select[Notebooks[], ("DocumentType" /. NotebookInformation[#]) == "Help" &])
Cases[Options /@ nb, HoldPattern["uri" -> x_] :> x, Infinity]
{"guide/Calculus"}
Kuba
  • 136,707
  • 13
  • 279
  • 740
2
"paclet:ref/" <> FileBaseName[Last[FileNameSplit[NotebookFileName[
SelectedNotebook[]]]]]

Will return a string of the paclet of the currently selected notebook document iff it is a reference. Change the "ref" for guide if needed for guides.

Frank
  • 121
  • 5
  • 1
    +1, it looks better for me :) but you need to place it in palette or use it after selecting automatically the Help Notebook because now it is not handy I think. I can copy a link directly if I have to put it in Help Notebook :) – Kuba Aug 24 '13 at 15:35