LaTeX 使用 bib 管理参考文献时,引用网络资源 URL 导致排版难看的问题

本文介绍了一种方法,通过调整LaTeX的url包,将默认的Adobe Courier字体更改为较小的等宽字体,以提高文档中URL的可读性和美观度。此外,文章还讨论了如何解决在BibTeX引用中出现的“%”符号问题,并解释了为何在BibTeX条目中使用url会导致非便携式的bibliography。

Example usage

In the preamble:

\usepackage{url}

%% Define a new 'leo' style for the package that will use a smaller font.
\makeatletter
\def\url@leostyle{%
  \@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\small\ttfamily}}}
\makeatother
%% Now actually use the newly defined style.
\urlstyle{leo}

In a BibTeX entry:

@misc{
    c.elmohamed,
    author = "Saleh Elmohamed",
    title = "Examples in {H}igh {P}erformance {F}ortran",
    howpublished = "Website",
    year = {1996},
    note = {\url{http://www.npac.syr.edu/projects/
                    cpsedu/summer98summary/ examples/hpf/hpf.html}}
}


Result, before

'Before' screenshot

Result, after

'After' screenshot

Things to watch out for

I tweak the default url style to use a smaller version of the typewriter font because I otherwise find that the Adobe Courier font I use (see also the Using Courier tip) displays a bit too large for my tastes, but also because the larger font still causes more spacing ugliness (in terms of underfull hboxes), as illustrated by the following screenshot:

'After'
screenshot

If strange ‘%’ signs start appearing in the list of references in the bibliography section, this is because BibTeX inserts those when it encounters a line it feels is too long:

'After'
screenshot

This is purely a BibTeX thing: inside a URL being handled by the url package, the line won't actually be too long — after all the whole idea is for url to be responsible for splitting it. The solution, as shown in the listing given earlier, is to add some stray whitespace to the long url. BibTeX will then no longer think the line is too long, and \url{} ignores all whitespace anyway, so it will not appear in the output.

The biggest problem with the url package is that you do not use it in your LaTeX source file, but in your BibTeX source files, thus making your bibliographies non-portable: once you start using \url{} in your BibTeX entries, you will be forced to include the url package in all your LaTeX files that use that bibliography file.



 

LaTeX使用 BibTeX 管理参考文献,正文中的文献编号出现乱序问题通常由以下几个原因引起: 1. **未正确编译流程**:BibTeX引用处理依赖于多次编译以确保所有引用标记和参考文献列表同步。通常需要依次运行 `latex`(或 `xelatex`/`pdflatex`)→ `bibtex` → `latex` → `latex`。如果跳过其中任何一步,可能会导致编号不一致。[^2] 2. **参考文献数据库(`.bib` 文件)条目重复或冲突**:如果 `.bib` 文件中存在多个相同作者和年份的条目且未使用 `key` 或 `crossref` 字段明确区分,可能导致 BibTeX 无法正确识别引用顺序。[^1] 3. **使用不兼容的引用样式(`.bst` 文件)**:某些 `.bst` 样式文件可能对排序方式有特殊定义,如按作者名排序而非引用顺序排序。建议使用 `unsrt` 样式来确保按引用顺序编号。 示例配置: ```latex \bibliographystyle{unsrt} \bibliography{references} ``` 4. **编辑器配置或缓存问题**:某些编辑器(如 TeXstudio、VS Code)可能缓存 `.aux` 或 `.bbl` 文件,导致旧数据干扰。尝试手动删除 `.aux`, `.bbl`, `.blg`, `.log` 文件后重新编译。[^2] 5. **使用 `natbib` 或 `biblatex` 等高级引用配置不当**:这些包提供了更灵活的引用机制,但若未正确设置排序选项,也可能导致编号乱序。例如,在 `biblatex` 中应使用以下设置以保持引用顺序: ```latex \usepackage[backend=biber,style=numeric,sorting=none]{biblatex} \addbibresource{references.bib} ``` ### 示例完整 LaTeX 代码 ```latex \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[backend=biber,style=numeric,sorting=none]{biblatex} \addbibresource{references.bib} \begin{document} This is a citation \cite{example1} and another one \cite{example2}. \printbibliography \end{document} ``` ### 解决步骤总结 - 确保完整的编译流程(LaTeXBibTeXLaTeXLaTeX)。 - 检查 `.bib` 文件是否存在重复条目。 - 使用 `unsrt` 样式或 `biblatex` 的 `sorting=none` 选项。 - 清理缓存文件并重新编译。 - 验证是否因特定宏包(如 `natbib`)引入的排序逻辑冲突。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值