在LaTeX参考文献中插入超链接
借助hyperlink
宏包可以较好地解决参考文献中插入链接的问题。
不借助宏包的帮助在LaTeX文档中插入链接是一件很麻烦的事情,因为网址的结构往往很复杂且带有各种符号,容易编译的时候容易出错。特别是遇到下划线、百分号这些符号。此外,在文档中插入一大堆乱七八糟的符号也不是很美观。使用hyperlink
宏包可以较好地解决这个问题。
基本配置
在文档中添加如下代码:
1 | \usepackage{hyperref} % 使用宏包 |
- 如果不想让链接变成其他颜色可以将
colorlinks
设置为false - 链接样式还有很多可以自定义的项目,详情如下表1:
Linking style options
Option | Default value | Description |
---|---|---|
hyperindex |
true | Makes the page numbers of index entries into hyperlinks |
linktocpage |
false | Makes the page numbers instead of the text to be link in the Table of contents. |
breaklinks |
false | Allows links to be broken into multiple lines. |
colorlinks |
false | Colours the text for links and anchors, these colours will appear in the printed version |
linkcolor |
red | Colour for normal internal links |
anchorcolor |
black | Colour for anchor (target) text |
citecolor |
green | Colour for bibliographical citations |
filecolor |
cyan | Colour for links that open local files |
urlcolor |
magenta | Colour for linked URLs |
frenchlinks |
false | Use small caps instead of colours for links |
PDF-specific options
Option | Default value | Description |
---|---|---|
bookmarks |
true | Acrobat bookmarks are written, similar to the table of contents. |
bookmarksopen |
false | Bookmarks are shown with all sub-trees expanded. |
citebordercolor |
0 1 0 | Colour of the box around citations in RGB format. |
filebordercolor |
0 .5 .5 | Colour of the box around links to files in RGB format. |
linkbordercolor |
1 0 0 | Colour of the box around normal links in RGB format. |
menubordercolor |
1 0 0 | Colour of the box around menu links in RGB format. |
urlbordercolor |
0 1 1 | Colour of the box around links to URLs in RGB format. |
pdfpagemode |
empty | Determines how the file is opened. Possibilities are UseThumbs (Thumbnails), UseOutlines (Bookmarks) and FullScreen. |
pdftitle |
Sets the document title. | |
pdfauthor |
Sets the document Author. | |
pdfstartpage |
1 | Determines on which page the PDF file is opened. |
hyperlink
宏包包含对很多LaTeX命令的重新定义,因此应当尽可能晚地加载,否则可能导致一些排版异常。当然也有一些宏包(如cleveref
等)需要在hyperlink
之后加载2。
插入链接
有两种插入链接的方式:
1 | \href{https://www.google.com}{Google} |
对于邮箱地址,可以在链接前面加上mailto:
,这样点击链接就会自动唤起系统默认邮件应用。
上面的代码排版效果如下:
点击链接即可跳转。
在参考文献中插入链接
如果使用BibTeX生成参考文献列表,可以在.bib文件中对应项的合适位置加上上面超链接:
1 | % file: main.tex |
上面的代码排版效果如下:
参考资料
[1] Hyperlinks - Overleaf, Online LaTeX Editor
[2] Which packages should be loaded after hyperref instead of before? - TeX - LaTeX Stack Exchange