[Tex/LaTex] Suppress newline after macro

line-breaking

How can I suppress a newline that will be inserted afterwards by a macro?
Is there any command that turns off newlines for exactly one time and turns it back on after the skipped one?
Like ignoring that the following macro starts by making a new paragraph before writing out text.
So only the text will be printed, but not the linefeed starting the paragraph.
Is such a command possible?

As requested an example:
writes: "first linebreak spaces foo"
wanted: "first spaces foo"

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{enumitem}
\begin{document}
\begin{itemize}
\item[]{first} \begin{verbatim}             foo
             bar
\end{verbatim} \item[] {second} more text
\end{itemize}
\end{document}

Best Answer

The case of verbatim is “tricky”: by default this environment issues a line break command and typesets its contents on the whole line length (taking into account, here, of being in a list).

You can use facilities from fancyvrb for boxing the verbatim environment:

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

\begin{itemize}
\item[first]
\begin{BVerbatim}[baseline=t]
foo
bar
\end{BVerbatim}

\item[second] more text
\end{itemize}
\end{document}

Notice that you should not indent the contents of a verbatim environment, unless you want indented output.

You usage of \item[] {first} is dubious: the command \item only has an optional argument and no mandatory one, so you get exactly the same output as

\item[] first

I put first as the optional argument; do as you prefer. If you want a labelless itemize, it's easier to say

\begin{itemize}[label={}]

and simply use \item, since you're using enumitem.

enter image description here

Here's the modified list, with no label:

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

\begin{itemize}[label={}]
\item first 
\begin{BVerbatim}[baseline=t]
foo
bar
\end{BVerbatim}

\item second more text
\end{itemize}
\end{document}

enter image description here