8

I would like to break camel case text that is handed to the \url{} macro of url.sty. The solution here does not work for text in captions, so it seems, ans in particular does not work for \url{}.

Is there a way to break the camel case as in:

\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 Answer 1

9

enter image description here

\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}
6
  • This doesn't seam to work for me. Do I have to use \camelurl{} instead of url or should it work for \url automatically. (BTW: I'm using XeLaTeX could this be the reason, because the character range is hard coded in \breakifupper?) Jun 13, 2013 at 11:55
  • @white_gecko the answer as posted works for me with pdflatex and xelatex it is true that it only allows a break point after a-z but really non ascii characters in URL ought to be %ab encoded anyway. The loop could of course be modified to cover other ranges than a-z similary the test for a following uppercase is assuming code point values in range 40-91. Jun 13, 2013 at 12:18
  • Sorry. Its working for me. I was looking at a \texttt{} which didn't wrap the text for obvious reasons. Jun 13, 2013 at 13:38
  • Is there something like that for \texttt ? Jun 13, 2013 at 13:45
  • @white_gecko you can use exactly that but configure url to use tt font (which should be the default) Jun 13, 2013 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .