# How to give \href's different options without macros or global defaults?

I am trying to have the two \href in the code below behave with different options without having to invoke macros or global defaults.

\documentclass{article}
\usepackage{hyperref}

\begin{document}

\end{document}


The idea is that one of them will continue with default and to pass the second one, I believe, the hidelinks = true option: keep clickable property but remove default blue box. I've seen many examples showing how to do this with macros but since I only want to have the non-default behavior very few times, I prefer to have the option scoped to the \href directly.

This is very similar in spirit to the answer given by @CephBirk in How to use different colors for different \href commands? but I can't figure out how to make it work to remove the box instead of changing the color.

The options you pass to \href are passed to a href option group, but the options that handle the link appearance belong to the Hyp option group. If you don't want to keep the interface to the href option group then this is enough:

\documentclass{article}

\usepackage{hyperref}

\makeatletter
\DeclareRobustCommand*{\Myhref}[1][]{% definition copied form hyperref.sty
\begingroup
\setkeys{Hyp}{#1}% Changed href to Hyp
\@ifnextchar\bgroup\Hy@href{\hyper@normalise\href@}%
}
\makeatother

\begin{document}

\end{document}


which prints:

If you are still going to use the standard options to \href then you have to do a little more:

\documentclass{article}

\usepackage{hyperref}

\makeatletter
\DeclareRobustCommand*{\Myhref}[1][]{%
\begingroup
\hypersetup{#1}%
\inner@href % Call an "inner href"
}
\DeclareRobustCommand*{\inner@href}[1][]{%
\setkeys{href}{#1}%
\@ifnextchar\bgroup\Hy@href{\hyper@normalise\href@}%
}
\makeatother

\begin{document}


Then the \Myhref command has two optional arguments:
\Myhref[<Hyp-options>][<href-options>]{<link>}{<text>}

• @ranlot Sorry, I had to leave for a while. 1) If you used the \href command with options (\href[<something>]{}{}), then you need the second approach, otherwise the first will do. 2) You can still use \href normally. The \Myhref just creates a wrapper to change options. 3) That is a completely different question (that I really have no idea about the answer, sorry), so I suggest you ask a new question. Hope this helps :) – Phelype Oleinik Sep 17 '18 at 19:51