2

I am typing up a sentence which contains code, and \verb's ignorance of line breaks is annoying me. This code is very short, and it does not make sense to give it its own line, but I also do not think that it would be good to break it up over multiple lines like texttt would do. Is there a standard way to format code in a LaTeX document which plays nicely with the newlines in a paragraph? Here is an image of the effect to which I am referring: enter image description here

  • Packages fancyvrb, listings perhaps? – user31729 Jul 1 '16 at 18:21
  • tex.stackexchange.com/a/14347/92620 ? – SAM Jul 1 '16 at 18:23
  • 1
    If you don't want to break it, and you don't want it hanging off the edge, they you probably want \sloppy of \raggedright, or at least \linebreak[3]. – John Kormylo Jul 1 '16 at 22:22
  • Can you squeeze an elephant in a suitcase? – egreg Jul 1 '16 at 23:02
  • @egreg My father's turn of phrase was a bit more colorful, questioning whether one could squeeze 2 pounds of, ahem, "manure" into a 1-pound sack. – Steven B. Segletes Jul 6 '16 at 10:37
1

This is possible with the listings package using its \lstinline (listings equivalent of \verb) with the option breaklines:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}

This is my sentence which has some code a little bit later but
\lstinline[breaklines]+RIGHT HERE IN THE LINE+ which is overflowing and does
not seem to want to obey my margin constraints, so I am not entirely sure what
to do with it.

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.