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

1 Answer 1

4
$\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$
4
  • 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
    Commented May 22, 2017 at 14:28
  • $\begingroup$ @AndreaG did you save the notebook after adding cell tags? Works fine on Win7 V11.1.1 $\endgroup$
    – Kuba
    Commented May 22, 2017 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
    Commented May 22, 2017 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
    Commented May 22, 2017 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.