GeneralHow to avoid overfull box due to lstinline?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
benowar
Posts: 33
Joined: Mon Aug 06, 2007 2:05 pm

How to avoid overfull box due to lstinline?

Post by benowar »

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
nunolf
Posts: 14
Joined: Wed Jul 18, 2007 1:41 pm

How to avoid overfull box due to lstinline?

Post by nunolf »

Hi

Have you tryed something like:

Code: Select all

bla bla bla \lstinline[breaklines=true]!some source code! bla bla bla
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. ;-)
benowar
Posts: 33
Joined: Mon Aug 06, 2007 2:05 pm

Re: How to avoid overfull box due to lstinline?

Post by benowar »

Thanks, that worked!
benowar
Posts: 33
Joined: Mon Aug 06, 2007 2:05 pm

Re: How to avoid overfull box due to lstinline?

Post by benowar »

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?
benowar
Posts: 33
Joined: Mon Aug 06, 2007 2:05 pm

Re: How to avoid overfull box due to lstinline?

Post by benowar »

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}
g99k
Posts: 1
Joined: Tue Aug 19, 2008 3:34 pm

How to avoid overfull box due to lstinline?

Post by g99k »

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:

Code: Select all

\begin{sloppypar}
Blah blah blah \nolinkurl{javax.management.modelmbean.ModelMBeanNotificationBroadcaster.removeAttributeChangeNotificationListener()} yadda yadda yadda.
\end{sloppypar}
Post Reply