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 need listing package (\usepackage{listing}) to break at punctuation

namespace::subnamespace::class
           ^             ^

at either these two locations

share|improve this question

1 Answer 1

up vote 2 down vote accepted

This breaks at ::, but puts it :: in the new line.

\lstset{literate={::}{::}{2\discretionary{}{}{}}}

This leaves a hyphenated :: in the old line, but the spacing is terrible.

\lstset{literate={::}{}{0\discretionary{::}{}{::}}}

This monster fixes the spacing:

\def\colonspace{\hspace{0.2em}}%
\lstset{literate={::}{}{0\discretionary{\mbox{:\colonspace:}}{}{\mbox{\colonspace:\colonspace:\colonspace}}}}

Btw, you can also break in the middle of :: ;-)

\lstset{literate={::}{}{0\discretionary{:}{:}{::}}}
share|improve this answer
    
For punctuation in general does that mean I will have to define them one by one? –  aiao Feb 11 '13 at 12:45
    
At least I don't know a better way. –  Sašo Živanović Feb 11 '13 at 12:53

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.