2
$\begingroup$

I would like to copy a part of a help section into a notebook. The objective is to add comment and save them.

My issue is that, when I copy a part of a help section into a notebook, all the links are broken and some tables are modified.

How can copy a help section into a notebook while preserving the Documentaion stylesheet?

$\endgroup$
  • 2
    $\begingroup$ You can use the same StyleDefinitions, manually: SetOptions[EvaluationNotebook[], StyleDefinitions -> FrontEnd`FileName[{"Wolfram"}, "Reference.nb", CharacterEncoding -> "UTF-8"]] or like that 17441 $\endgroup$ – Kuba Mar 17 '17 at 21:31
2
$\begingroup$

Here is a function that takes a low-level expression (boxes) and resolves all named styles into explicit style specifications for opened Notebook nb:

resolveAllStyles[expr_, nb_NotebookObject] := With[{
    heads = Cell | StyleBox,
    options = 
     Alternatives @@ Symbol /@ Names["System`" ~~ Except[{"$", "`"}] .. ~~ "Style"],
    resolve = 
     Flatten[Replace[#, 
        style_String :> CurrentValue[nb, {StyleDefinitions, style}], {1}]] &
    },
   Replace[expr, {
     (head : heads)[body_, opts__] :> RuleCondition@head[body, resolve[{opts}]],
     (r : Rule | RuleDelayed)[opt : options, val_] :> RuleCondition@r[opt, resolve[val]]
     }, -2]];

And here is how one can extract a Section from a Documentation notebook, convert all the style names into explicit style specifications, and then put this section into an ordinary notebook with default styles:

nb = NotebookOpen@
   FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", 
     "ReferencePages", "Symbols", "Style.nb"}];

(* Select the "Scope" section cell *)
cell = Select[
   Cells[nb, CellStyle -> {"ExampleSection"}], ! 
     FreeQ[NotebookRead[#], s_String /; StringContainsQ[s, "Scope"], -1] &];

(* Select the whole section and extract it *)
sel = SelectionMove[cell[[1]], All, CellGroup];
section = NotebookRead[nb];

(*Create new notebook containing the section extracted from the Documentation Notebook*)
CreateDocument[resolveAllStyles[section, nb], CellGrouping -> Manual];

screenshot

$\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.