Is there a way in ConTeXt to change background color of PDF hyperlinks?

Edit: By hyperlinks, I mean external (via \useURL), internal (\goto) and footnote links. I can't easily change all those to custom commands; I'm searching for such a setup-like command instead. And from Jairo A. del Rio's answer below, I know of text backgrounds; but I couldn't figure out how to put that in all those commands or in \setupinteraction.

I know one can change text color with \setupinteraction: color for external links or links to another page, contrastcolor for links to same page, being green and red their defaults. I tried using style key as below, without success. Following MWE:

\setupinteraction [state=start,
                   style={backgroundcolor=yellow}]  % relevant line; doesn't work

% code below just for testing
\setuppapersize [default]
\useURL[aurl][https://wiki.contextgarden.net][][ConTeXt Garden]
Testing links to same page via a note\footnote{This should create link to same page.},
a figure like \goto{figure~1}[figure1]
and an external link: \from[aurl].

\startplacefigure[title={Figure for testing},reference=figure1]{\externalfigure[cow][width=1\textwidth]}\stopplacefigure

generates document below. Note that, as style accepts just one command (I guess), it happens to insert "backgroundcolor=yellow" before actual link.

Generated document from MWE above.


PREAMBLE: ConTeXt mailing lists are better places to make questions and answers wrt ConTeXt. Consider joining :)

Your example won't work because AFAIK style doesn't accept tables as arguments. A workaround consists of defining a text background, which inherits a lot of settings of framed but is able to break across lines and paragraphs, and then apply it to the fourth argument of useurl. The only disadvantage is you'll have to manually include \MyUrl every time you set a URL.

I'm not sure whether or not you're asking for footnotes too, so just in case...

EDIT: Wolfgang Schuster suggested bars instead:

%Style and color are customizable here
%Suggestion by Wolfgang Schuster

%For highlighting footnote marks
%Comment these two lines if you don't need them
\def\myfootnote#1{\setbar[urlbackground]{\high{#1}}} % Text superscripts
\setupfootnotes[textcommand=\myfootnote] % Highlight in footnote marks
% code below just for testing
\setuppapersize [default]
\useURL[aurl] [https://wiki.contextgarden.net] [] [\MyUrl{ConTeXt Garden}]
Testing links to same page\footnote{This should create links to same page} and an external link: \from[aurl].

enter image description here

  • Thank you! Unfortunately, I'm not able to change all occurrences of \useURL: I'm using ConTeXt via Pandoc, which generates a .tex file based on a template. I can change all \setups and \defines, but not actual commands used in text. (In fact, I can write a Pandoc filter in Lua to do that, but it'd be a little cumbersome.) Is there a way to put \MyURL in before key of a command that setups links? Oct 21 '20 at 21:09
  • I'm sorry: in fact, my problem doesn't involve only \useURL, but also \goto: \useURL is used by Pandoc to external links, and \goto to internal links. I will clarify that in the question. Thank you, anyway. Oct 22 '20 at 4:32
  • 1
    @JosédeMattosNeto \setupinteraction [state=start,style={\MyUrl}] does quite what you need, but sometimes it doesn't work well with line breaks. Oct 22 '20 at 8:55
  • I tried your last suggestion, and you're right: it fails when link needs to break across lines... Almost... Thank you. Oct 23 '20 at 4:40
  • @JosédeMattosNeto See edited answer. Oct 24 '20 at 22:14

Your Answer

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

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