[Tex/LaTex] Prevent LaTeX from inserting a new line

line-breakingverbatim

How do I prevent LaTeX from inserting a new line?

Here's the code:

bla bla bla
\begin{verbatim}C:\Program Files\Product Name\Some other extensions\mail box name\end{verbatim} 

The output is:

bla bla bla
 
C:\Program Files\Product Name\Some other extensions\mail box name

That's my problem: I'm unable to prevent LaTeX from inserting a new line after "bla".

Is my problem somewhat related with the fact that I'm using verbatim?

Best Answer

Your question together with your comment

I must use verbatim not \verb

is a bit confusing. You apparently want inline verbatim material yet not want to use the command that produces it. Unless you can explain why \verb (or listings' \lstinline or minted's \mint or ...) doesn't work for you you're unlikely to get a better answer than what I already said in the comments.

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}

\noindent
Some inline verbatim \verb|&%$_^| and some displayed material:
\begin{verbatim}
 &%$_^
\end{verbatim}
Some text after to show the spacing

\end{document}

enter image description here

If you insist in using an environment for inline verbatim material you could use fancyvrb's BVerbatim environment which puts its contents in a TeX box. It might still not be what you're looking for when you need more than one line, though:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}

\begin{document}

Some text before
\begin{BVerbatim}[gobble=1]
 &%$_^ 
\end{BVerbatim}
\ Some text after to show the spacing

\bigskip

text
\begin{BVerbatim}
 two
 lines 
\end{BVerbatim}
\ text

\bigskip

bla bla bla
\begin{BVerbatim}
C:\Program Files\Product Name\Some other extensions\mail box name
\end{BVerbatim}

\end{document}

enter image description here

Note that the last example will cause an overfull \hbox.

Related Question