# URLs containing Chinese clickable but not working

As you can convince yourself by pasting it to the address bar, the URL

https://baike.baidu.com/item/三转一响

Is fine . Below comes a working tex code containing it as a clickable URL. The urlfont is for displaying the Chinese characters in fonts properly.

\documentclass{article}

\usepackage{hyperref}
\usepackage{fontspec}

\begin{document}
\newfontfamily\urlfontfamily{FandolSong-Regular.otf}
\def\UrlFont{\urlfontfamily}

\url{https://baike.baidu.com/item/三转一响}

\href{https://baike.baidu.com/item/三转一响}{https://baike.baidu.com/item/三转一响}

\end{document}


This is the output:

The URLs are clickable, but redirect to an error page of baike.baidu, suggesting the Chinese part is not passed to the browser. \href does not even display properly, while \url does.

• I experience no problems with the \url directive if I execute the instruction \usepackage[hyphens,spaces,obeyspaces]{url} prior to loading hyperref. – Mico Jul 31 '17 at 21:00
• Are you considering using the colorlinks option when loading the hyperref package? That's make the "boundaries issue" disappear -- literally! – Mico Jul 31 '17 at 21:08
• To get a correct print out from \href you should either select the font first, or use \nolinkurl: \href{baike.baidu.com/item/三转一响}{\nolinkurl{baike.baidu.com/item/三转一响}} . The links works for ok for me with xelatex but fails with lualatex. – Ulrike Fischer Jul 31 '17 at 21:12
• With colorlinks it looks perfect, but still redirects to the error page. – Ludi Jul 31 '17 at 21:19

## 2 Answers

With lualatex you will have to input the link percent encoded (you can get it online). The current implementation of hyperref (the internal escapestring command) looses non-ascii input. Pay attention that the slashes are verbatim and not encoded.

\documentclass{article}

\usepackage{hyperref}
\usepackage{fontspec}

\begin{document}
\newfontfamily\urlfontfamily{FandolSong-Regular.otf}
\def\UrlFont{\urlfontfamily}

\href{https://baike.baidu.com/item/%E4%B8%89%E8%BD%AC%E4%B8%80%E5%93%8D}{\nolinkurl{https://baike.baidu.com/item/ 三转一响}}

\end{document}


The Link will look okay in a current pdf viewer:

• This works! Could you share how to get the per cent encoded link? I copied it in an app on my iPad, but I don't know why that has the desired result. – Ludi Jul 31 '17 at 21:48
• I googled for a service (and replaced the %2F by slashes manually). I think you can also do it with firefox. Perhaps there is also some lua library built it... – Ulrike Fischer Jul 31 '17 at 21:56

I experience no problems with XeLaTeX if I (a) load fontspec before hyperref, (b) load the url package before hyperref as well, (c) load the hyperref package with the option colorlinks, and (d) use the \nolinkurl directive, as mentioned by Ulrike in her comment, to encase the second argument of \href. (And, just like Ulrike, I also find that this approach does not work under LuaLaTeX.)

% !TeX program = xelatex
\documentclass{article}
\usepackage{fontspec}
\usepackage[spaces,obeyspaces,hyphens]{url}
\usepackage[colorlinks,urlcolor=blue]{hyperref}
\newfontfamily\urlfontfamily{FandolSong-Regular.otf}
\def\UrlFont{\urlfontfamily}

\begin{document}
\url{https://baike.baidu.com/item/三转一响}

\href{https://baike.baidu.com/item/三转一响}{\nolinkurl{https://baike.baidu.com/item/三转一响}}
\end{document}