我真的厌倦了它们,一遍又一遍,它们从未停止出现。总是有一些新的 URL 中断并带来新的坏框。如何修复 stackoverflow 链接的这个 url 坏框?
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[hyphens]{url}
% Bad formatting using URLs in bibtex
% https://tex.stackexchange.com/questions/22888/bad-formatting-using-urls-in-bibtex
\usepackage{etoolbox}
% How to avoid overfull error with url package?
% See also the `\usepackage{url}` declarationon the file `basic.tex`.
% Set this to 2mu or 3mu if URL start troubling again.
% https://tex.stackexchange.com/questions/261776/how-to-avoid-overfull-error-with-url-package
\Urlmuskip=0mu plus 1mu
\begin{document}
VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}
\end{document}
基本构建器:运行 pdflatex...完成。
没有错误。没有警告。坏盒子:
D:\temp.tex:25: Overfull \hbox (2.83554pt too wide) in paragraph at lines 25--27\T1/cmtt/m/n/12 30527522 / what -[] are -[] the -[] differences -[] between -[] visual -[] studio -[] code -[] and -[] visual -[] studio$
我不想禁用警告,我希望它不会自动超出页面限制。Latex 能否将它们拆分到下一行,而无需我手动遍历所有新内容并手动找出每种情况的某种手动破解方法?
答案1
方法 1
我发现 URL 是运用 的好地方sloppypar
。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage[a4paper, margin=3.5cm,showframe]{geometry}
\usepackage[hyphens]{url}
% Bad formatting using URLs in bibtex
% https://tex.stackexchange.com/questions/22888/bad-formatting-using-urls-in-bibtex
\usepackage{etoolbox}
% How to avoid overfull error with url package?
% See also the `\usepackage{url}` declarationon the file `basic.tex`.
% Set this to 2mu or 3mu if URL start troubling again.
% https://tex.stackexchange.com/questions/261776/how-to-avoid-overfull-error-with-url-package
\Urlmuskip=0mu plus 1mu
\begin{document}
THIS
VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}
\bigskip
VERSUS THIS
\begin{sloppypar}
VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}
\end{sloppypar}
\end{document}
sloppypar
正如我在下面的评论中提到的那样,对于那些讨厌在每个带有 的段落周围放置环境所带来的打字压力的人来说\url
,一种可能性是在序言中:
\everypar{\tolerance=200\relax\emergencystretch=0pt\relax\hfuzz=0.1pt\relax\vfuzz\hfuzz}
\let\svurl\url
\renewcommand\url{\sloppy\svurl}
理论上,这将使任何使用 的段落\url
变成一个\sloppy
段落。然后,使用 ,\everypar
每个新段落的参数都将重置为 LaTeX 默认值。当然,这会与出于其他原因希望重新定义这些参数的任何其他包发生冲突。
在实践中,这一点还没有经过测试。众所周知,从理论上讲,理论和实践是一样的……但从实践上讲,它们不一样。
方法 2
或者,你可以告诉\url
在任何字母处中断(参考使用 Biblatex 手动换行 URL):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage[a4paper, margin=3.3cm,showframe]{geometry}
\usepackage[hyphens]{url}
% Bad formatting using URLs in bibtex
% https://tex.stackexchange.com/questions/22888/bad-formatting-using-urls-in-bibtex
\usepackage{etoolbox}
% How to avoid overfull error with url package?
% See also the `\usepackage{url}` declarationon the file `basic.tex`.
% Set this to 2mu or 3mu if URL start troubling again.
% https://tex.stackexchange.com/questions/261776/how-to-avoid-overfull-error-with-url-package
\Urlmuskip=0mu plus 1mu
\begin{document}
THIS
VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}
\bigskip
VERSUS THIS
\makeatletter
\g@addto@macro{\UrlBreaks}{%
\do\/\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
VS Code is an Editor while VS is an IDE.
\url{https://stackoverflow.com/questions/30527522/what-are-the-differences-between-visual-studio-code-and-visual-studio}
\end{document}