# Why \texttt and \verb giving errors when using with LaTeX commands inside their input

On latest version of MikTeX, following works:

\begin{align*}
\int sinxdx && \texttt{test line 1}\\
\int{sinx}dx && \texttt{test line 2}\\
\end{align*}


But the following gives error:

\begin{align*}
\int sinxdx && \texttt{\int sinxdx}\\
\int{sinx}dx && \texttt{\int{sinx}dx}\\
\end{align*}


The error:

Underfull \hbox (badness 10000) in paragraph at lines 94--102
[2] [3]
Overfull \hbox (40.0189pt too wide) detected at line 168
\OML/cmm/m/it/10.95 a=c \OMS/cmsy/m/n/10.95


When using \verb, the following is also giving a similar error:

\begin{align*}
\int sinxdx && \verb|test line 1|\\
\int{sinx}dx && \verb|test line 2|\\
\end{align*}

• Why are you doing \texttt{\int sinxdx}? \texttt puts you in text-mode so \int will obviouly produce an error, since it needs math mode; besides, use \sin x and not sin x. – Gonzalo Medina Jul 21 '15 at 16:12
• Try \mathtt instead of \texttt. Also, use \sin x instead of sinx---however, doing so will place "sin" back in the default math font. – Steven B. Segletes Jul 21 '15 at 16:13
• @GonzaloMedina, I need to show the math display on the left and the corresponding syntax on the right as shown in Steve's response. – nam Jul 22 '15 at 2:21

## 2 Answers

To get verbatim content inside the align* environments, my verbatimbox package can help.

\documentclass{article}
\usepackage{amsmath,verbatimbox}
\begin{document}
\begin{myverbbox}{\lineA}\int \sin x\,dx\end{myverbbox}
\begin{myverbbox}{\lineB}\int{\sin x}\,dx\end{myverbbox}
\begin{align*}
\int \sin x\,dx && \lineA\\
\int{\sin x}\,dx && \lineB\\
\end{align*}
\end{document}


For the other issue of \texttt, try \mathtt instead, which processes its argument in math mode.

ADDENDUM

The OP asks if this can be done without an additional package. Perhaps this would suffice:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\int \sin x\,dx && \texttt{\string\int~\string\sin~x\string\,dx}\\
\int{\sin x}\,dx && \texttt{\string\int\string{\string\sin~x\string}\string\,dx}
\end{align*}
\end{document}


• Is there a work around to accomplish this without using extra packages. I'm using amsmath package. The \mathtt will not work since I would like to show the syntax in the text mode exactly as you are showing on the right in your image above. – nam Jul 21 '15 at 22:49
• @nam Please see ADDENDUM. – Steven B. Segletes Jul 22 '15 at 1:50
• thanks. Your ADDENDUM works. I was just reading this post when I received your response. – nam Jul 22 '15 at 1:58
• @nam I just revised my addendum to get the braces and backslash in a tt font. – Steven B. Segletes Jul 22 '15 at 1:58

You can't use \verb inside align*, just like in the argument to any other command; align is a special environment that reads its contents before starting typesetting and this has the consequence that \verb is not allowed. If you want to make examples of input and output, you can use array:

\documentclass{article}
\usepackage{array,booktabs}

\begin{document}

$\begin{array}{>{\displaystyle}ll} \int \sin x \, dx & \verb|\int \sin x \, dx| \\ \addlinespace \int \cos x \, dx & \verb|\int \cos x \, dx| \end{array}$

\end{document}


Please, note the correct TeX notation; the spaces are optional (except the one between \sin and x.