![阻止 hyperref 断行](https://linux22.com/image/367158/%E9%98%BB%E6%AD%A2%20hyperref%20%E6%96%AD%E8%A1%8C.png)
\url 和 \href 的不同行为已在此处讨论。今天我注意到 href 会在我不希望的地方引入换行符。有没有什么方法可以防止这种情况发生?
标有 \url 的内容似乎可以顺利地延续到右边距。
通常我不希望在边缘添加链接,但就这一种情况而言,项目经理有要求,所以需要添加。
下面,输出的第 4 行和第 6 行有相同的句子,唯一的区别是一个链接是 \url,一个是 \href。
口粮:
\documentclass[12pt,english]{article}
\usepackage{lmodern}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
\usepackage{babel}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false]
{hyperref}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{url}
\makeatother
\begin{document}
I want to insert a hyperlink, but using \textbackslash{}href uses
the hyphenation features from hyperref and I want to disable them.
\urlstyle{rm}
URL that nicely does not break:
This is a line with a URL at the end of it: \url{http://pj.freefaculty.org/scraps/some-thing-here}
Href that does break and I wish it did not:
This is a line with a URL at the end of it: \href{http://pj.freefaculty.org/scraps/some-thing-here}{http://pj.freefaculty.org/scraps/some-thing-here}
OK to write in margin, \textbackslash{}url does:
I do not mind going into the margin a little bit. \url{http://pj.freefaculty.org/scraps/some-thing-here}
A linebreak I wish I did not have:
I don't want the hyperref to spread this across lines, as you see
next.
I do not mind going into the margin a little bit. \href{http://pj.freefaculty.org/scraps/some-thing-here}{http://pj.freefaculty.org/scraps/some-thing-here}
\end{document}