It used to be possible to add hyperlinks to ConTeXt documents in the style of the LaTeX hyperref package. Minimal formerly-working example:

    attr{/C [1 0 0] /Border [0 0 1]}
    user{/Subtype /Link /A << /Type /Action /S /URI /URI
    (#1) >>}\ifsecondargument #2\else #1\fi\pdfendlink}

Here is a \href [http://tex.stackexchange.com] [link] to
my favourite web site.


But it doesn't work with recent ConTeXt installations! As far as I can tell, the \pdfstartlink and pdfendlink commands are either silently ignored or treated as some sort of switch in/out of a verbatim mode. My guess is that something has changed in luaTeX.

What can I change in my old ConTeXt source files to make them compilable with current ConTeXt? I do know about the esoteric alternatives in the wiki but that's not what I'm asking.

  • Any particular reason you don't want to use useURL? – Aditya Aug 24 '16 at 12:29
  • @Aditya I like the coloured-on-screen (but non-printing) borders that the hyperref style used to give me. – user31316 Aug 24 '16 at 12:31
  • So you want borders around the links, not necessarily the user interface similar to href? – Aditya Aug 24 '16 at 12:32
  • @Aditya Yes, exactly. It's useful for hyperlinks to be visible on a screen but there's no point in making them visible on a piece of paper. I probably plagiarised the literal pdf stuff from the hyperref package and translated it into a ConTeXtesqe user interface. – user31316 Aug 24 '16 at 12:35
  • 1
    Having link as a square-bracketed argument is counter-intuitive. Typeset material is usually given in curly braces in ConTeXt, e.g. \goto{link}[anchor]. – Henri Menke Aug 24 '16 at 14:08

Metafox's solution explains how to add borders around links. I'll explain why your old macros stopped working.

There has been a change in the luatex backend. Lot of the \pdf... series of commands introduced by pdfTeX are now available as \pdfextension. To be backward compatible, macro packages are supposed to define:

\protected\def\pdfstartlink             {\pdfextension startlink }
\protected\def\pdfendlink               {\pdfextension endlink\relax}

ConTeXt does so in syst-ini.mkiv. However, then redefines these to \relax in back-ini.mkiv. The explanation is:

%D Because we do a lot in \LUA\ and don't want interferences, we nil most of the
%D \PDFTEX\ primitives. Of course one can always use the \type {\pdfvariable},
%D \type {\pdfextension} and \type {\pdffeedback} primitives but it will probably
%D have bad side effects.

%D These are no-ops and don't even intercept what comes next. Maybe some day
%D I'll write a parser that maps onto \CONTEXT.

That is the reason that your macro is not working. So, you will either have to add

\unexpanded\def\pdfstartlink             {\pdfextension startlink }
\unexpanded\def\pdfendlink               {\pdfextension endlink\relax}

or use \pdfextension startlink attr {....} ... \pdfextension endink\relax in your definition.

|improve this answer|||||
  • I'm accepting the answer from Aditya because it's splendidly educational and easy to apply to old source files by means of a sed script; but @Metafox gets a vote too, for supplying the orthodox ConTeXt MkIV solution for use hereafter. – user31316 Aug 24 '16 at 14:01

You can add borders to references with the references.border directive, the default color for the frame is black but you can change it to another color.



Here is a \goto{link}[url(http://tex.stackexchange.com)] to my favourite web site.

To remove the style of the link you have change the style and color values with the \setupinteraction command.

Framed hyperlink with ConTeXt

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy