Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 8 down vote accepted

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}
share|improve this answer
    
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?) –  white_gecko Jun 13 '13 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. –  David Carlisle Jun 13 '13 at 12:18
    
Sorry. Its working for me. I was looking at a \texttt{} which didn't wrap the text for obvious reasons. –  white_gecko Jun 13 '13 at 13:38
    
Is there something like that for \texttt ? –  white_gecko Jun 13 '13 at 13:45
    
@white_gecko you can use exactly that but configure url to use tt font (which should be the default) –  David Carlisle Jun 13 '13 at 13:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.