Sebastian,
I believe what you want for this is \emergencystretch
, for example \emergencystretch=3em
. This allows TeX a bit more flexibility when it applies its line-breaking algorithm.
Here is a simple example, followed by a picture. Try it out with different values between 0em
(the LaTeX default) and 5em
and let us know if that works for you.
\documentclass{article}
\usepackage{amsmath}
\setlength{\topmargin}{-1.3in}
\setlength{\textheight}{11in}
\begin{document}
\newcommand{\composers}{\noindent
A short list of famous composers includes Bach (1685--1750),
Beethoven (1770--1827), Brahms (1833--1897), Chopin (1810--1849),
Elgar (1857--1934), Handel (1685--1759), Haydn (1732--1809),
Holst (1874--1934), Gustav (1860--1911), Mendelssohn (1809--1847),
Mozart (1756--1791), Scarlatti (1685--1757), Schubert (1797--1828),
Schumann (1810--1856), Shostakovich (1906--1975), Sibelius (1865--1957),
Tchaikovsky (1840--1893), and Vivaldi (1678--1741).\par}
\emergencystretch=3em
\composers\narrower\composers\narrower\composers\narrower\composers
\narrower\composers\narrower\composers\narrower\composers
\end{document}
And here's how that looks — no more overfull or underfull boxes. :) It's not perfect, but it may just do the trick for the text you are typesetting. How wide/narrow are your margins? This sample output below progresses through several narrowings:
TeX would linebreak (hyphenate) the camel case words, but perhaps not where you wish eg
cre-a-te-Un-spec-i-fiedNodeEr-ror-Marker
shows the default hyphenation points (using the default US English hyphenation)
It wasn't clear if you wanted hyphens at the break points. I have assumed not. If you do then change \penalty2
to \-
.
This boxes the parts between capital letters so they don't break, and puts a small penalty before capitals so they can break.
As with anything using catcode changes (like \verb
it will not work in the argument to another command)
\documentclass{scrartcl}
\showhyphens{createUnspecifiedNodeErrorMarker}
\makeatletter
\def\zzz{\leavevmode\begingroup
\let\ifcase\iftrue
\def\or##1{%
\catcode`##1\active\uccode`\~`##1\uppercase{%
\def~{\egroup\penalty2\hbox\bgroup\string##1}}}%
\@Alph{}%
\@zzz}
\def\@zzz#1{\textbf{\hbox\bgroup#1\egroup}\endgroup}
\makeatother
\begin{document}
\section{Test}
And another example the show must go on, but we have too less text (\zzz{createUnspecifiedNodeWarningMarker} and
\zzz{createUnspecifiedNodeErrorMarker}, sdjklashjksa \zzz{createUnspecifiedLinkWarningMarker} and
\zzz{createUnspecifiedLinkErrorMarker}).
\end{document}
Best Answer
I suggest you use the
\discretionary
command for hyphens.Use
\discretionary{}{\underscore}{\underscore}
instead if you wish the underscore to be placed on the next line, or\discretionary{\underscore}{\underscore}{\underscore}
to get the character both before and after the line break.\discretionary
is the hook in to TeX's hyphenation scheme. In some languages, including German, words can change spelling when they are hyphenated, and this command was introduced by Knuth to help cover such situations.\discretionary{a}{b}{c}
printsc
if there is no linebreak, otherwise it printsa
before the linebreak andb
after.If you want to limit this to one particular type of phrase then I suggest you use
and write
\resource{XMLResource.OPTION\_RECORD\_UNKNOWN\_FEATURE}
in your text. (I have removed the\textsc
from your example as it had no effect.)If you wish to use it in one section of the document, then you can similarly define an environment which inserts these definitions at the start, e.g.
used as