4
$\begingroup$

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?

$\endgroup$
3
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ 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? $\endgroup$ – Andrea G May 22 '17 at 14:28
  • $\begingroup$ @AndreaG did you save the notebook after adding cell tags? Works fine on Win7 V11.1.1 $\endgroup$ – Kuba May 22 '17 at 15:19
  • $\begingroup$ @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 $\endgroup$ – Andrea G May 22 '17 at 16:37
  • 1
    $\begingroup$ One can use ExpressionCell and skip the box stuff: CellPrint@ExpressionCell[Plot[Sin[x], {x, -2, 2}], "Output", CellTags -> "tag"] $\endgroup$ – Michael E2 May 22 '17 at 17:30

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.