A feature request:
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.
Maybe it is possible for PDF with not too much effort?
Three cases:
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").
--> Like the LaTeX packages pdfcomment
, cooltooltips
or fancytooltips
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).
--> Like the LaTeX package hyperref
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.
--> not sure if there is a package or whether LaTeX can do it at all
Here's what I've been able to figure out.
The only hyper-anything mechanism I have found in cairographics is
cairo_tag_begin (cr, CAIRO_TAG_LINK, "uri='https://somelink.org'");
I can attach the "tag" to a hypertext label in gnuplot output generated by the pdfcairo terminal (attached patch).
In okular, but not in chrome or firefox, the link text pops up in a tooltip box when you hover over it prior to clicking. That's what you wanted, but it doesn't actually seem to work in the web browsers.
If the text is not a valid URL, okular still shows it as a pop up tooltip when you hover over it. Unfortunately but probably to be expected, all three viewers generate an error if you click on it.
If I include the pdf file containing a working URL link in a latex document generated by
set term cairolatex pdf standalone; set out 'foo.tex'
followed bypdflatex foo
the plot looks as you would expect but there is no sign of a hyperlink or tag when I view the processed file. This doesn't mean it would be impossible to put a link in the latex output, but it would have to be via some other mechanism.I'm not sure where this is worth pursuing or not. What do you think?
Last edit: Ethan Merritt 2020-12-14
Ethan, thank you very much for your effort.
Unfortunately, I'm working under Windows and I don't know (yet) how to compile gnuplot from source myself, otherwise might be able to test your patch with different hypertexts.
I guess I need to learn how to compile from source (under Windows), but I haven't yet taken the time to search for good step-by-step instructions.
I took your attached PDF example where you used the hypertext "something not really a URI".
As it could be already expected, different viewers behave differently.
I also created a text file named
'something not really a URI'
in the same directory where I put your demo PDF. But since it has no known extension, Windows probably doesn't know what to do with it.I observe the following:
Acrobat Reader XI 11.0.10:
tooltip appears when hovering with the mouse showing:
file:///C|/user/myPath/whatever/something not really a URI
.When I click on it a security warning will appear something like, "...want's to establish a connection to
file:///C|/user/myPath/whatever/something not really a URI
, with the options "allow | block | cancel".If I allow, no error message and nothing will happen.
SumatraPDF:
Hovering with mouse: displays only
something not really a URI
Clicking on it gives a message: error opening of
C:\user\myPath\whatever\something not really a URI
.TeXStudio internal PDF viewer:
Hoevering with mouse: a big black square will flash and afterwards the tooltip
something not really a URI
will appear.Clicking on it will open an instance of Windows (File) Explorer with the path
C:\user\myPath\whatever
but nothing else will happen.When I include your PDF into a LaTeX document using
\usepackage{pdfpages}
,none of the viewers will show a tooltip anymore.
Apparently, the tooltip information will be lost which is a pity. Maybe there is an option with the package
pdfpages
?!To your question:
well, if you can include this patch it would already be great.
About checking alternative routes to keep the hypertext in a LaTeX PDF, I guess there are other (more important) features waiting...
Thank you for checking this topic.
Building on Windows is actually pretty straighforward if you use MSYS2/MingGW64, see [support-requests:#199].
Related
Support Requests: #199
Meanwhile I've been searching through the PDF standard document (long!) PDF 1.7. Section 12.5 describes another defined structure that's much closer to being a tooltip. It's "annotation", used for things like sticky-note comments attached by reviewers of a previously-created document. Once I saw that I remembered that indeed I had seen and used such a feature in specially prepared PDF documents. The thing is, just because it's in the PDF standard doesn't mean it is supported by the cairographics library.
I'm thinking of sending a feature request their way to see if someone is willing to add it upstream. Even if they like the idea I imagine it would be several years before we could assume it was present in the locally-installed cairo libraries that gnuplot is linked against. It doesn't hurt to ask anyway.