3

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*}
lockstep
  • 250,273
nam
  • 1,105
  • 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 02:21
  • Special case of https://tex.stackexchange.com/q/24574/250119 -- in this case align environment are "special" that they grab argument as input. – user202729 May 07 '22 at 04:49

2 Answers2

3

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}

enter image description here

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}

enter image description here

2

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.

enter image description here

egreg
  • 1,121,712