Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. SetOptions[EvaluationNotebook[], DockedCells -> Cell[#, "Output", CellMargins -> 0]] &@
  2. BoxData@ToBoxes@
  3. With[{GetTOC =
  4. Cases[NotebookGet@SelectedNotebook[],
  5. Cell[name_, style : "Section" | "Subsection" | "Subsubsection", ___] :> {style, name},
  6. Infinity] /. {"Subsubsection", x_} :> x[] //.
  7. {x___, {"Subsection", y_}, z : Except[_List] ...,
  8. w : PatternSequence[{_, _}, ___] | PatternSequence[]} :> {x, y[z], w} //.
  9. {x___, {"Section", y_}, z : Except[_List] ...,
  10. w : PatternSequence[{_, _}, ___] | PatternSequence[]} :> {x, y[z], w} &},
  11. DynamicModule[{TOC = GetTOC[]}, Row@
  12. {Button["Update", TOC = GetTOC[]],
  13. Dynamic@Refresh[" " <> StringJoin @@ (ToString[#] <> "." & /@ #) <>
  14. " " <> If[Length[#] == 0, "",
  15. Head@Catch@Fold[If[Length[#] >= #2, #[[#2]], Throw[#]] &, TOC, #]] &[
  16. CurrentValue[NotebookSelection[], {"CounterValue", #}] & /@
  17. {"Section", "Subsection", "Subsubsection"} /. {x___, 0 ...} :> {x}],
  18. UpdateInterval -> 1]}]]
  19.  
  20. Button["press", Print @ FrontEndExecute @ FrontEnd`CellInformation[NotebookSelection[]]]
  21.  
  22. current = First @ Cells[ExpressionUUID -> "a4103240-2c81-4d64-90fc-deb0941ca4a0"]
  23.  
  24. PreviousCell[current, CellStyle->"Section"]
  25.  
  26. Dynamic[FrontEndExecute @ FrontEnd`CellInformation[NotebookSelection[]]]
  27.  
  28. Dynamic[{
  29. CurrentValue[NotebookSelection[], CellStyle],
  30. FrontEndExecute @ FrontEnd`CellInformation[NotebookSelection[]]
  31. }]
  32.  
  33. SetOptions[
  34. EvaluationNotebook[],
  35. StyleDefinitions -> Notebook[
  36. {
  37. Cell[StyleData[StyleDefinitions->"Default.nb"]],
  38. Cell[StyleData["Notebook"],
  39. DockedCells->Cell[BoxData @ ToBoxes @ Dynamic[
  40. Row@{
  41. CurrentValue[NotebookSelection[],{"CounterValue","Section"}],
  42. Replace[CurrentValue[NotebookSelection[],{"CounterValue","Subsection"}],{0->Sequence[],n_->Sequence[".",n]}],
  43. ": ",
  44. Replace[Cell[a_,__]:>RawBoxes@Cell[a]] @ With[
  45. {cell=First[Cells[ExpressionUUID->OptionValue[FrontEndExecute@FrontEnd`CellInformation[FrontEnd`SelectionObject],ExpressionUUID]],{}]},
  46. Which[
  47. cell==={},
  48. "",
  49. MemberQ[CurrentValue[cell,CellStyle],"Section"|"Subsection"],
  50. NotebookRead[cell],
  51. True,
  52. NotebookRead[PreviousCell[cell,CellStyle->{"Section","Subsection"}]]
  53. ]
  54. ]
  55. }
  56. ],
  57. TextAlignment->Center
  58. ]
  59. ]
  60. },
  61. StyleDefinitions->"PrivateStylesheetFormatting.nb"
  62. ]
  63. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement