![在 hyperref 中,使用带有管道参数分隔符的 \url?](https://linux22.com/image/311616/%E5%9C%A8%20hyperref%20%E4%B8%AD%EF%BC%8C%E4%BD%BF%E7%94%A8%E5%B8%A6%E6%9C%89%E7%AE%A1%E9%81%93%E5%8F%82%E6%95%B0%E5%88%86%E9%9A%94%E7%AC%A6%E7%9A%84%20%5Curl%EF%BC%9F.png)
基本上,我有一个像这样的 bibtex 字段,其中bibtex 连接#
与 bibtex 字符串变量一起使用:
@String {mylink = "http://tex.stackexchange.com"}
...
note = "At link " # mylink,
现在,我想将其包装在中\url
,因此我尝试:
note = "At link \url{" # mylink # "}",
...并且在使用 biblatex+biber 处理时,似乎括号的存在使得参数mylink
无法被替换。
通过阅读texdoc url
,我了解到\url
实际上还有另一种调用形式\url|...|
,其中我可以使用管道作为“参数分隔符”而不是括号 - 事实上这可以通过 biblatex + biber 正确扩展:
note = "At link \url|" # mylink # "|",
...但不幸的是,hyperref
的\url
命令不支持使用管道符的这种语法 - 并且url
的\url
排版仅是纯文本(PDF 中不是可点击的链接)。
那么,有什么方法可以将\url|...|
其“理解”为url
's \url
(即管道代表参数分隔符) - 但执行为hyperref
's \url
?(带有可点击的链接和所有内容)?
以下是仅显示方面内容的 MWE \url
(不含参考书目):
\documentclass{article}
\usepackage[showframe]{geometry}
% \PassOptionsToPackage{hyphens}{url}
\usepackage[hyphens]{url}
\let\origurl\url % same as \HyOrg@url (from hyperref)
\usepackage[breaklinks]{hyperref}
\hyphenation{some-folder-with-a-very-long-name}% doesn't work
% \hyphenation{http://testing.org/firstlevelsubdirectory/some-folder-with-a-very-long-name/2008010817502377777777/}% '! Not a letter.' for the ':'
% cannot use \hyphenation to break urls; so make it break link at each letter!
% https://tex.stackexchange.com/questions/3033/forcing-linebreaks-in-url
\let\origUrlBreaks\UrlBreaks
\makeatletter
\g@addto@macro{\UrlBreaks}{\UrlOrds}
\let\oldUrlBreaks\UrlBreaks
\g@addto@macro{\UrlBreaks}{%
\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
\do\Y\do\Z}
\makeatother
\let\newUrlBreaks\UrlBreaks
% copy of "\Url@y read arguments delimited like |...|, passing to \Url@z" from hyperref.sty; nowork - makes \end{document} be skipped!
\makeatletter
\def\turl#1{\catcode`{11 \catcode`}11\obeyspaces\obeylines
\def\@tempa##1#1{\url{##1}}\@tempa}
\makeatother
\begin{document}
\section{Section 1}
Testing this URL here: \url{http://testing.org/firstlevelsubdirectory/somefolderwithaverylongname/2008010817502377777777/}
Testing this URL here: \origurl|http://testing.org/firstlevelsubdirectory/somefolderwithaverylongname/2008010817502377777777/|
Testing this URL here: \url|http://testing.org/firstlevelsubdirectory/somefolderwithaverylongname/2008010817502377777777/|
% Testing this URL here: \turl|http://testing.org/firstlevelsubdirectory/somefolderwithaverylongname/2008010817502377777777/| % nowork - makes \end{document} be skipped!
\end{document}
输出:
我只想简单地写\url|...|
,并将链接输出/排版为该 MWE 的第一行(而现在,我必须写\origurl|...|
,它将输出为第二行 - 没有链接区域)。