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*}
4
  • 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. Commented Jul 21, 2015 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. Commented Jul 21, 2015 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
    Commented Jul 22, 2015 at 2:21
  • Special case of tex.stackexchange.com/q/24574/250119 -- in this case align environment are "special" that they grab argument as input.
    – user202729
    Commented May 7, 2022 at 4:49

2 Answers 2

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

4
  • 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
    Commented Jul 21, 2015 at 22:49
  • @nam Please see ADDENDUM. Commented Jul 22, 2015 at 1:50
  • thanks. Your ADDENDUM works. I was just reading this post when I received your response.
    – nam
    Commented Jul 22, 2015 at 1:58
  • @nam I just revised my addendum to get the braces and backslash in a tt font. Commented Jul 22, 2015 at 1:58
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .