5

I would like to adapt the following instructions How to create a Hyperlink within the current Notebook? to have a hyperlink to an output of a simple plot such as

Plot[x,{x,0,1}]

How to deal with the fact that the target is not a text but a graphics?

C. E.
  • 70,533
  • 6
  • 140
  • 264
Andrea G
  • 759
  • 3
  • 19

1 Answers1

4

The following syntax works:

CellPrint[Cell[
   BoxData[ToBoxes[Plot[Sin[x], {x, -2, 2}]]],
   "Output", 
   CellTags -> {"target"}]
]]

It is documented under Cell -> Scope.

Hyperlink["link", {EvaluationNotebook[], "target"}]
(* Out: hyperlink pointing to the plot *)

MichaelE2 points out in a comment that ExpressionCell can be used:

CellPrint@ExpressionCell[
Plot[Sin[x], {x, -2, 2}], "Output", CellTags -> "tag"
]

Note that you can also add tags manually through the drop down menu that you get by right-clicking on cells:

How to add tags

C. E.
  • 70,533
  • 6
  • 140
  • 264
  • 1
    I have noticed that when I close my notebook I lose all the Cell Tags added manually from the drop down menu. Is there any way to leave them permanent? – Andrea G May 22 '17 at 14:28
  • @AndreaG did you save the notebook after adding cell tags? Works fine on Win7 V11.1.1 – Kuba May 22 '17 at 15:19
  • @Kuba I was pretty sure to have done it. However, I just redid it and it worked. I may have done some mistake. If I notice something weird next time I open the notebook I will let you know – Andrea G May 22 '17 at 16:37
  • 1
    One can use ExpressionCell and skip the box stuff: CellPrint@ExpressionCell[Plot[Sin[x], {x, -2, 2}], "Output", CellTags -> "tag"] – Michael E2 May 22 '17 at 17:30