![如何让 \todo{} 注释中的 URL 换行?](https://linux22.com/image/479820/%E5%A6%82%E4%BD%95%E8%AE%A9%20%5Ctodo%7B%7D%20%E6%B3%A8%E9%87%8A%E4%B8%AD%E7%9A%84%20URL%20%E6%8D%A2%E8%A1%8C%EF%BC%9F.png)
我正在寻找一种方法,允许 URL 在由包创建的边注中的任何字符处换行luatodonotes
。我安装了xurl
包,它是允许 URL 在文本中的任何字符处换行的选项之一。
该xurl
包在文本中对我有用,但在\todo{}
注释中却不行。该\todo{}
命令是一个移动参数,因此\url{}
在其中使用会导致错误。\url{}
使用 \protect 作为前缀可以渲染 URL,但仍然没有按预期中断。
有人能提出解决方案吗?下面是最小示例和屏幕截图。
% !TEX TS-program = lualatex
\documentclass[letterpaper,11pt]{memoir}
\usepackage[english]{babel}
\usepackage{xurl}
\usepackage[dvipsnames]{xcolor}
\usepackage{luatodonotes}%
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. %
\todo{this todo note has just plain text}%
%
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. %
\todo{this todo note contains a long URL using the texttt command. It renders fine but does not break: \texttt{http://www.blahblah.com/blah/blah/and-more/and-more/and-more.html}}%
%
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Here is a really long URL in the text block using the \textbackslash url command. It renders and breaks properly (well, almost): \url{http://www.blahblah.com/blah/blah/and-more/and-more/blah/blah/and-more/and-moreblah/blah/and-more/and-more-and-more.html} %
%
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.%
\todo{this todo note contains a long URL using \textbackslash protect\textbackslash url. It renders but does not break: \protect\url{http://www.blahblah.com/blah/blah/and-more/and-more/and-more.html}}%
\end{document}
答案1
我认为它不能与 luatodonotes 一起使用。如果你仔细观察,你会发现它不仅可以防止 url 中断,还可以防止连字符。它只是将所有内容存储在一个 hbox 中,然后将其分成几行。使用 todonotes 它可以工作:
\documentclass[letterpaper,11pt]{memoir}
\usepackage[english]{babel}
\usepackage{xurl}
\usepackage[dvipsnames]{xcolor}
\usepackage{todonotes}%
\urldef\myurl\url{http://www.blahblah.com/blah/blah/and-more/and-more/and-more.html}
\begin{document}
\listoftodos
\bigskip
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.%
\todo{this todo note contains a long URL using \textbackslash urldef. \myurl}%
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.%
\todo{this todo note contains a long URL using \textbackslash protect. \protect\url{http://www.blahblah.com/blah/blah/and-more/and-more/and-more.html}}%
\end{document}