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.

This question has developed from How to deal with very long lstinline-phrases like long class names?.

That question is about line breaking inside a \lstinline phrase. I have provided an answer which automatically hyphenates on capital letters, and then, in a comment, I realized it could sometimes be useful to have automatic hyphenation on underscores _ as well.

I managed to implement this, but one glitch remains: I would like to prevent automatic _-hyphenation at the start of the name (in Python, for example, this is common situation, as by convention, internal names start with an underscore (or two)).

\documentclass{article}
\usepackage[paperwidth=10cm,paperheight=5cm]{geometry}
\pagestyle{empty}
\usepackage{lstdoc}
\lstMakeShortInline[literate={\_}{\_}{1\discretionary{\_}{}{}}]|

\begin{document}
\textbf{Good line break:} in this paragraph the line break in the
python's variable |a_python_style_name| is good!

\textbf{Bad line break:} the internal variable |_internal_python_name|
is not hyphenated very nicely in this paragraph.
\end{document}

A good and a bad line-break in <code>\listinline</code>

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.