0

How do I surround a hyperlink with square brackets using \href?

I want something like [Link] with square brackets, in black and "Link" in blue (my default hyper-link color).

2

This way the square brackets are also part of the link, but take the color of the main text (black by default):

\documentclass{article}
\usepackage{xcolor}
\usepackage[hidelinks]{hyperref}
\newcommand\mylink[2]{\href{#1}{[{\color{blue}#2}]}}
\begin{document}
This is a
\mylink{http://www.example.com}{Example} 
web.  
\end{document}
2
\documentclass{article} 
\usepackage[colorlinks=true, urlcolor=blue]{hyperref} 
\let\oldhref\href
\renewcommand\href[2]{[\oldhref{#1}{#2}]}
\begin{document} 
    Here is the \href{https://tex.stackexchange.com/}{Tex Site}. More text ...
\end{document}

Output

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.