我正在使用fontspec
和xurl
包。我发现该命令\url
删除了Numbers=SlashedZero
OpenType 功能。显然,我希望斜线零能够正常工作,即使在排版 URL 时也是如此。
我提供了一个 MWE,其中我用三种不同的等宽字体演示了这个问题。
\documentclass{article}
\usepackage{fontspec}
%These fonts are available for free on Google Fonts.
%\setmonofont{Source Code Pro}[Numbers=SlashedZero]
%\setmonofont{JetBrains Mono}[Numbers=SlashedZero]
\setmonofont{Fira Mono}[Numbers=SlashedZero]
\usepackage{url}
%\usepackage{xurl}
\begin{document}
\texttt{01234567890123456789}
\par
\url{01234567890123456789}
\end{document}
编辑:2023-02-09。我做了一些测试,发现 der_herr_g 的建议解决了 Slashed Zero 问题,但也阻止了在 Slashed Zero 处换行。我提供了一个 MWE 来演示该问题。如果我注释掉\makeatletter\makeatother
,则换行可以正常工作,但没有 Slashed Zero。
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{fontspec}
%These fonts are available for free on Google Fonts.
\setmonofont{Source Code Pro}[Numbers=SlashedZero]
%\setmonofont{JetBrains Mono}[Numbers=SlashedZero]
%\setmonofont{Fira Mono}[Numbers=SlashedZero]
%\usepackage{url}
\usepackage{xurl}
\makeatletter
\g@addto@macro\UrlSpecials{%
\do\0{\mbox{\UrlFont\char`\0}}%
}
\makeatother
\begin{document}
%\texttt{01234567890123456789}
%\par
%\url{01234567890123456789}
%\par
\texttt{000000000000000000000000000000000000000000000000000000000000000000000000000000000000}%70 zeroes
\par
\url{000000000000000000000000000000000000000000000000000000000000000000000000000000000000}%70 zeroes
\end{document}
答案1
这似乎对我有用:
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{fontspec}
\setmonofont{Fira Mono}[Numbers=SlashedZero]
\usepackage{xurl}
% ADD THIS (edited; see below)
\makeatletter
\g@addto@macro\UrlSpecials{%
\do\0{\allowbreak\mbox{\UrlFont0}}%
}
\makeatother
\begin{document}
% Original test case
\texttt{01234567890123456789} \par
\url{01234567890123456789} \par
% Breaking a URL on a slashed zero
\texttt{000000000000000000000000000000000000000000000000000000000000000000000000000000000000} \par
This is looking fine:
\url{000000000000000000000000000000000000000000000000000000000000000000000000000000000000} \par
Here we still have a problem (line breaks a bit too late): \par
\url{000000000000000000000000000000000000000000000000000000000000000000000000000000000000}
\end{document}
所有功劳都应该归于这个问题以及 ArTourter 的评论。
编辑(2023-02-10):在许多情况下,添加一个简单的\allowbreak
似乎可以解决换行问题。[此外,\UrlFont0
的效果与 一样好\UrlFont\char`\0
。] 不过,有些极端情况下换行会有点太晚。