3

This question is posted as a requested follow-on from options for appearance of links in hyperref , to clear up some odd behaviour in hyperref.

In the snippet below, the two \usepackage commands both work, but linkcolor=. throws an error when combined with colorlinks=true (error text shown at end of post).

\documentclass{article}

\usepackage[colorlinks=true,linkcolor=]{hyperref}
%\usepackage[linkcolor=.]{hyperref}

\begin{document}

See Figure~\ref{fig}

\begin{figure}
        \caption{This is an empty figure \label{fig}}
\end{figure}
\end{document}

If I use the line

\usepackage[colorlinks=true,linkcolor=.]{hyperref}

(note the dot), I get error text:

LaTeX Error: Undefined color

and the error comes immediately after the closing brace of \ref{}

The effect I wanted to achieve was to remove boxes around links and leave all links text color except actual URLs, so when I used this command I also had urlcolor=blue in the options, but that was not needed to reproduce the error. But the following line did work, in that all links but URLs were invisible:

\usepackage[colorlinks=true,urlcolor=blue,linkcolor=]{hyperref}

Using MiKTeX-pdfTeX 2.9.6959 (1.40.20) (MiKTeX 2.9.6960) on Windows 10

AndréC
  • 24,137
Dr Darren
  • 179
  • 1
    Add \usepackage{xcolor}. – Ulrike Fischer Mar 04 '19 at 23:36
  • Of course you get an error with linkcolor=. as this is setting the colour to ., which is a non-existent colour. SImialrly, with linkcolor= you are remving all colour so the lins are invisible. Doesn't \usepackage[colorlinks=true,linkcolor=black]{hyperref} give what you want? –  Mar 04 '19 at 23:38
  • Thank you for your advice to add xcolor. Perhaps hyperref should be loading it? I did not want to assume text was black. linkcolor=. is supposed to match the current text colour. See the discussion linked in the question for context. linkcolor=. works under some circumstances. The dot on its own is not necessarily an error. – Dr Darren Mar 04 '19 at 23:56

2 Answers2

5

linkcolor=. causes hyperref to issue \color{.}

which produces

LaTeX Error: Undefined color `.'

as there is no colour of that name using the standard color package as loaded by hyperref.

You are possibly thinking of the xcolor package syntax wher . means the current color

\usepackage{xcolor}
\usepackage[colorlinks=true,linkcolor=.]{hyperref}

works, although specifying coloured links this way seems slightly strange choice rather than just specifying the link border to have width 0.

David Carlisle
  • 757,742
  • Strange to you. Seemed reasonable to me, with my lack of experience. I didn't want a border, so saying 'colour it instead' and then making the colour like the text seemed reasonable to me. – Dr Darren Mar 04 '19 at 23:53
  • 2
    @DrDarren there is some cost to adding a colour, the resulting pdf will have code to push a colour on to the stack and restore it, just using the current colour, conversely a pdf link always has a border attribute so setting its width to 0 (pdfborder= 0 0 0) is a far more direct and lightweight way of specifyng this – David Carlisle Mar 05 '19 at 00:01
  • Thank you for that advice. All I can say is that I did what I did as a naïve user and to me it seemed logical. It is great to have so much expertise out there, and people willing to give their expertise. I wanted one kind of link to be blue and the rest invisible. Many thanks. – Dr Darren Mar 05 '19 at 22:47
0

To sum up, as noted above, adding

\usepackage{xcolor}

fixes the problem with using the dot in the hyperref options. There are other ways of getting the result I wanted that also do not throw errors; thanks to other posters.

Perhaps hyperref should load xcolor instead of color?

Dr Darren
  • 179