Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

alltt causes a line break (newline). How do i suppress this? I want something to the effect of \verb+HELLO+ in that it does what \begin{verbatim} \end{verbatim} does except doesn't cause the line to break.

 \documentclass{article}
 \usepackage{alltt}

 \begin{document}

 The line will break HERE: \alltt{a}

 \end{document}
share|improve this question
2  
alltt should be used as an environment. You probably want \texttt{a}. –  egreg Sep 8 '12 at 7:53
    
Can you make a real example of usage? –  egreg Sep 8 '12 at 8:03
add comment

1 Answer

up vote 5 down vote accepted

Package alltt defines an environemnt alltt that uses a list environment internally. Therefore it cannot be used the same way as \verb or \texttt.

The main point of package alltt is the unchanged use of \, { and }. The following macro \textalltt sets verbatim catcodes for its argument except for the three characters.

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

\makeatletter
\newcommand*{\textalltt}{}
\DeclareRobustCommand*{\textalltt}{%
  \begingroup
    \let\do\@makeother
    \dospecials
    \catcode`\\=\z@
    \catcode`\{=\@ne
    \catcode`\}=\tw@
    \verbatim@font\@noligs
    \@vobeyspaces
    \frenchspacing
    \@textalltt
}
\newcommand*{\@textalltt}[1]{%
    #1%
  \endgroup
}
\makeatother

\begin{document}
Verbatim text: \textalltt{Hello \textbf{\textsl{world}}}.
\end{document}

Result

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.