Hi,
I am using the lstinline command to show java class names in a special font. Now, this seems to produce overfull boxes. So in some cases the class name is shown in the margins of the page, rather then breaking to the next line.
Is there any way to avoid this? One easy solution would be to have hypenation, but I dont think thats very good practice.
Thanks for helping,
Ben
General ⇒ How to avoid overfull box due to lstinline?
How to avoid overfull box due to lstinline?
Hi
Have you tryed something like:
By default, the line breaking is deactivated.
Cheers,
Nuno
P.S. Next time, please refer to which package belongs the command you're in trouble. Though its straightforward for some people (not my case), it may help other users (my case) to quickly get synchronized with the problem context.
Have you tryed something like:
Code: Select all
bla bla bla \lstinline[breaklines=true]!some source code! bla bla bla
Cheers,
Nuno
P.S. Next time, please refer to which package belongs the command you're in trouble. Though its straightforward for some people (not my case), it may help other users (my case) to quickly get synchronized with the problem context.

Re: How to avoid overfull box due to lstinline?
Thanks, that worked!
Re: How to avoid overfull box due to lstinline?
Hm, I am still having a problem if the contents in the lstinline is a single word. In some cases the word is simply overlapping the right margin of the text. I wonder if this is a bug in the listings package? I would expect it to be good enough to wrap to the next line if the contents exceed the width of the paragraph. Any ideas?
Re: How to avoid overfull box due to lstinline?
Actually I am now using {\ttfamily} instead of listings. Its the same output for classnames anyways and supports hyphens, e.g.
{\ttfamily Null\-Pointer\-Exception}
{\ttfamily Null\-Pointer\-Exception}
How to avoid overfull box due to lstinline?
The sloppypar command enforces precise margins at the cost of less consistency in word spacing. If a long class name spills into the margins or even off the page, word spacing is clearly the lesser problem.
http://en.wikibooks.org/wiki/LaTeX/Form ... ween_Words
This solves the problem for long variable or class names. They will not be broken up, but put into the next line instead of having them spill over.
The mentioned breaklines option for lstinline does not seem to work with dots. If you have a long concatenation using dot syntax and want the expression to break at the dots, you can instead mark it with the nolinkurl command. Technically, it's code and not a URL, but both are displayed in typewriter by default.
Here's an example:
http://en.wikibooks.org/wiki/LaTeX/Form ... ween_Words
This solves the problem for long variable or class names. They will not be broken up, but put into the next line instead of having them spill over.
The mentioned breaklines option for lstinline does not seem to work with dots. If you have a long concatenation using dot syntax and want the expression to break at the dots, you can instead mark it with the nolinkurl command. Technically, it's code and not a URL, but both are displayed in typewriter by default.
Here's an example:
Code: Select all
\begin{sloppypar}
Blah blah blah \nolinkurl{javax.management.modelmbean.ModelMBeanNotificationBroadcaster.removeAttributeChangeNotificationListener()} yadda yadda yadda.
\end{sloppypar}