\url 中的驼峰式大小写自动换行

\url 中的驼峰式大小写自动换行

我想打破传递给\url{}宏的驼峰式文本url.sty。解决方案这里不适用于标题中的文本,所以看起来,ans 尤其不适用于\url{}

有没有办法打破驼峰式案例,如:

\documentclass{article}

\usepackage{url}

\begin{document}
\noindent{}Here some text, and
then \url{BreakThisCamelCaseForMeItWasChosenToMakeSomeTasksEasierButAlas.txt},
and then some more text to indicate the text width, showing that
the URL should break earlier.
\end{document}

答案1

在此处输入图片描述

\documentclass{article}

\usepackage{url}

\makeatletter
\g@addto@macro\UrlSpecials{\camelurl}
\def\camelurl{%
\count@`a
\loop
\mathcode\count@"8000
\uccode`\~\count@\uppercase{\edef~{\mathchar\the\count@\noexpand\breakifupper}}%
\ifnum\count@<`\z
\advance\count@\@ne
\repeat}

\def\breakifupper#1{%
\ifcat .\noexpand#1%
\ifnum`#1>40
\ifnum`#1<91
\penalty\z@
\fi\fi\fi
#1%
}

\makeatother


\begin{document}
\noindent{}Here some text, and
then \url{BreakThisCamelCaseForMeItWasChosenToMakeSomeTasksEasierButAlas.txt},
and then some more text to indicate the text width, showing that
the URL should break earlier.
\end{document}

相关内容