1
votes

Is there any way to add hypertext or tags into PDFs via gnuplot?

According to the manual (gnuplot 5.4.0) it's not possible:

Some terminals (wxt, qt, svg, canvas, win) allow you to attach hypertext to specific points on the graph or elsewhere on the canvas. When the mouse hovers over the anchor point, a pop-up box containing the text is displayed. Terminals that do not support hypertext will display nothing.

Actually, there are 3 desires:

  1. add hypertext into PDF, when hoovering with mouse over the point the text will appear, like in the above terminals (also known as "tool tip" or "bubble help").
  2. add hyperlinks into PDF, when clicked on them it will be redirected to an URL, e.g. www.gnuplot.info or if possible to an other local file (with absolute or relative path).
  3. add some tags or labels which could be used further (when this PDF is included into a LaTeX document) to link to a different chapter, section or figure. This is probably more a question for tex.stackexchange. Of course, you can include a gnuplot graph (PNG, PDF) into LaTeX document and then you can probably define areas on the graph for links etc. within LaTeX. However, everytime the graph changes you would have to redefine all positions in LaTeX again and again. That's why I would like to do it automatically in gnuplot.

Maybe other plotting packages can do this, e.g. pgfplots or tikz or others, but since I feel comfortable with gnuplot I wanted to avoid to use yet another package and check whether nevertheless there might be a way with gnuplot.

I'm aware that this is beyond gnuplot's focus of plotting, but maybe somebody knows about a workaround with gnuplot?

Code:

### hypertext in PDF???
reset session
set term pdfcairo size 29.7cm, 21.0cm  font ",20" # A4 landscape
set output "Test.pdf"

$Data <<EOD
"Go here"            0.5  0.8
"Go there"           0.5  0.2
"Go left"            0.2  0.5
"Go right"           0.8  0.5
"www.gnuplot.info"   0.5  0.5
EOD

do for [i=1:|$Data|] {
    set label i word($Data[i],1) at screen word($Data[i],2), screen word($Data[i],3) hypertext point pt 6 ps 10
}

plot cos(x)
set output
### end of code

Result: (PNG screenshot of PDF just for illustration, of course there will be no hypertext).

enter image description here

1
I suggest submitting this as a feature request on the gnuplot project tracker. My current understanding is that it would be possible to add hyperlink "tag" information into pdf output, but it is entirely up to the eventual viewing program what to do with that information. I do not know whether embedding such a pdf file in a LaTeX document would preserve the accesssibility of such tag information. - Ethan
Thank you Ethan, I will file a feature request asap. I know that the LaTeX package hyperref can create hyperlinks and (I guess) links to local files in a PDF. Yes, probably LaTeX might not be able to look into an included PDF to extract information when creating a new PDF. - theozh

1 Answers

1
votes

If using LaTeX (with set term cairolatex or epslatex or tikz in non-standalone mode) is a valid solution, I would outsource the creation of hyperlinks and hypertexts to hyperref and put the corresponding LaTeX code as a title or label in the plot:

set label '\href{http://www.gnuplot.info}{click me!}' ...
plot ... title 'see \autoref{section:methods} and read Ref.\autocite{bib:John_Smith_2002}'

Single quotes are mandatory, or else all special characters have to be escaped when using double quotes.