As with overfull boxes in general, you have a bunch of options:
- Manually rewrite the paragraph until the output is fine,
- Add
\usepackage{microtype}
(often works magic),
- Allow more hyphenation (something you said you don't want here),
- Allow breaks in more places (something you said you don't want here),
- Increase
\tolerance
and \emergencystretch
a little (e.g. with \sloppy
or sloppypar
),
- Increase
\emergencystretch
a lot,
- Allow just that one line to be ragged-right (what you're asking for here),
- Give up on justified typesetting entirely, and use ragged-right typesetting.
Here are a examples of a few of these options:
Option 2: microtype
Doesn't always solve everything, but it's really easy to do with very little downsides.
\documentclass{article}
\usepackage{microtype}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sit amet ornare eros. Vivamus ac bibendum sapien. Morbi efficitur iaculis elit et pellentesque. Maecenas fermentum augue non tortor rutrum, vel malesuada nunc venenatis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer fringilla. Suspendisse ac scelerisque tortor \texttt{1937294810383219482}. Pellentesque at iaculis risus. Curabitur porta ante non nunc eleifend, sit amet porta enim congue. Nullam semper fringilla suscipit. Nam ac elementum eros. Vivamus sed quam fringilla, tristique odio a, pretium lacus.
\end{document}

Option 5: Use \sloppy
or sloppypar
What: Use \sloppy
or the environment sloppypar
, to increase \tolerance
, \hfuzz
and \emergencystretch
a little; see here for what \sloppy
does.
Pros: Not the worst typesetting. Will avoid overfull lines in most cases.
Cons: Worse typesetting than usual. Not guaranteed not to prevent overfull lines.
\documentclass{article}
\begin{document}
\begin{sloppypar}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sit amet ornare eros. Vivamus ac bibendum sapien. Morbi efficitur iaculis elit et pellentesque. Maecenas fermentum augue non tortor rutrum, vel malesuada nunc venenatis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer fringilla. Suspendisse ac scelerisque tortor \texttt{1937294810383219482}. Pellentesque at iaculis risus. Curabitur porta ante non nunc eleifend, sit amet porta enim congue. Nullam semper fringilla suscipit. Nam ac elementum eros. Vivamus sed quam fringilla, tristique odio a, pretium lacus.
\end{sloppypar}
\end{document}

Option 6: Increase \emergencystretch
a lot
What: Increase \emergencystretch
to a ridiculously large value.
Pros: If at all it is possible to have things fit on a line (e.g. no unbreakable text longer than a line's width), this will do it.
Cons: That line will look ugly, with lots of stretching.
\documentclass{article}
\begin{document}
{\emergencystretch=\maxdimen
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sit amet ornare eros. Vivamus ac bibendum sapien. Morbi efficitur iaculis elit et pellentesque. Maecenas fermentum augue non tortor rutrum, vel malesuada nunc venenatis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer fringilla. Suspendisse ac scelerisque tortor \texttt{1937294810383219482}. Pellentesque at iaculis risus. Curabitur porta ante non nunc eleifend, sit amet porta enim congue. Nullam semper fringilla suscipit. Nam ac elementum eros. Vivamus sed quam fringilla, tristique odio a, pretium lacus.
}
\end{document}

Option 7: Allow ragged-right line breaks just before the texttt
(What you asked for here: I think the output is questionable, but decide for yourself.)
This can be done with the right sequence of boxes, glue and penalties: first, a glue with stretch X, then a penalty (to allow a break), then a glue with stretch -X. This way, if the break is not taken, the glues cancel, while if the break is taken, you have added X amount of stretchability to the line.
\documentclass{article}
% Like \texttt, but allows the previous line to end early if it won't fit.
\newcommand{\ttbreakbefore}[1]{%
\hskip 0pt plus 1fil\relax
\penalty0
\hskip 0pt plus -1fil\relax
\texttt{#1}%
}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sit amet ornare eros. Vivamus ac bibendum sapien. Morbi efficitur iaculis elit et pellentesque. Maecenas fermentum augue non tortor rutrum, vel malesuada nunc venenatis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer fringilla. Suspendisse ac scelerisque tortor \ttbreakbefore{1937294810383219482}. Pellentesque at iaculis risus. Curabitur porta ante non nunc eleifend, sit amet porta enim congue. Nullam semper fringilla suscipit. Nam ac elementum eros. Vivamus sed quam fringilla, tristique odio a, pretium lacus.
\end{document}

In practice you can probably make the added stretch smaller (which will mean less awkward stretching on the earlier line): for example with 13pt
instead of (the infinite) 1fil
, one gets:

and you can increase the value as appropriate, to trade-off between the stretching the spaces, and leaving blank space at the end.
\emergencystretch=\textwidth
(or some really large value), the cost of which is that spaces will be really stretched out on those lines. (2) Use ragged-right typesetting, the cost of which will be giving up on justified paragraphs. (3) Have just those lines be ragged-right, with some clever tricks. This seems to be what you're asking, but I think the output will actually be confusing. – ShreevatsaR Mar 22 '18 at 19:15\texttt
isn't involved, I think it does a great job at typesetting what I wrote. And yes, none of my numbers are longer than a line. They all are 64 bit two's complement numbers, so the longest they get is 20 characters (including the potential negative sign). – UTF-8 Mar 22 '18 at 19:26