I'm typesetting some technical documentation that includes identifiers with very long names. It is unacceptable to break or hyphenate these names because that would look confusingly like juxtaposed identifiers or subtraction and make the output PDF not searchable. It is also unacceptable if a name extends outside the physical page. It's ok to have the occasional overfull hbox, allowing the identifiers to extend into the right margin, as long as they remain inside the page.
Within these constraints, I of course want the output to look as nice possible. However, I can't afford to spend time fine-tuning each paragraph to add \sloppy
or \raggedright
or similar declarations. In some parts of the document, I simply cannot do it because the LaTeX code is generated by a tool that does not allow me to inject arbitrary LaTeX inside the text. It's up to TeX to find the right method from the parameters I set once and for all.
The tools I've found to solve the basic problem are \sloppy
, \raggedright
, and \RaggedRight
from ragged2e
. None of them work well for me.
MWE:
\documentclass{article}
\usepackage{ragged2e}
\usepackage[vmargin=0in]{geometry}
\pagestyle{empty}
\newcommand{\mytext}[2]{
\subsubsection*{#1}
{ #2 %
Some libraries define extremely long names such as
\texttt{AVAssetResourceLoadingContentInformationRequest} or
\texttt{UIViewControllerTransitionCoordinatorContext} or even
\texttt{MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification}
(yeech!). It is unacceptable to hyphenate these very long names or for them to
disappear off the side of the page. Beyond that, the output should not
look too ugly: there should be no extra-long white spaces, and long text
paragraphs tend to look bad without right justification.
\par
}
}
\begin{document}
\mytext{Default}{}
\mytext{Sloppy}{\sloppy}
\mytext{Ragged right}{\raggedright}
\mytext{Ragged2e RaggedRight}{\RaggedRight}
\mytext{Ragged2e RaggedRight + sloppy}{\RaggedRight\sloppy}
\end{document}
\sloppy
meets the hard constraints but allows spaces to stretch a lot which reduces readability. \raggedright
also meets the hard constraints but the white space on the right is huge (waste of paper) and uneven (ugly). \RaggedRight
fails to make everything fit on the physical page. \RaggedRight
plus \sloppy
is my best bet, but it's markedly inferior to normal left-and-right justification for long stretches of text.
How can I both meet the hard constraints (fit some ridiculously long words without breaking), and get good-looking output (especially in paragraphs with no long identifiers)? For example, in the sample paragraph above, I'd like the output from “Default”, but with a line break after “even”.
\texttt
? if so, it might be possible to precede them with an explicit local encouragement to break. also, is your default paper lettersize or a4?\texttt
. These are whole documents so I could redefine\texttt
if that helps. (I also have handwritten documents, and possibly in the near future other code generators which might generate\verb
or something else.) My default paper size is a4, why does it matter?\raggedright
.