Menu

#517 Hypertext for PDF terminal?

open
nobody
None
5
2020-12-15
2020-12-05
theozh
No

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:

  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").
    --> Like the LaTeX packages pdfcomment, cooltooltips or fancytooltips

  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).
    --> Like the LaTeX package hyperref

  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.
    --> not sure if there is a package or whether LaTeX can do it at all

Discussion

  • Ethan Merritt

    Ethan Merritt - 2020-12-14

    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).

    • If the label text is an actual valid URL, the point associated with the label can be clicked to trigger a request for your default browser to open the URL. As tested here, this works when you are viewing the gnuplot-generated pdf file in okular, firefox, or chrome. This is what the cairo_tag mechanism was intended for so it's not surprising that it works. Example
    set label 1 at graph 0.75, 0.25 point pt 7 ps 4 lc "blue"
    set label 1 "http://gnuplot.info" hypertext
    plot sin(x)
    
    • 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 by pdflatex 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
  • theozh

    theozh - 2020-12-15

    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.

     
    • Bastian Märkisch

      Building on Windows is actually pretty straighforward if you use MSYS2/MingGW64, see [support-requests:#199].

       

      Related

      Support Requests: #199

  • Ethan Merritt

    Ethan Merritt - 2020-12-15

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.