Math & Scienceverbatim inside align

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

verbatim inside align

Post by jaybz »

How can I place verbatim inside a align environment?
When I compile with Latex I get errors. When I use DVI->PS then PS->PDF the verbatim has no effect. I also tried: \verb

Code: Select all

\documentclass[a4paper,25pt]{article}
\usepackage[top=1in, bottom=.2in, left=1in, right=1in]{geometry} 
\usepackage{verbatim}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x &= 2 \\
\begin{verbatim}
\int
\end{verbatim}
z &= 4 \\
\end{align*}
\end{document}
Last edited by jaybz on Sun Nov 14, 2010 7:56 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

verbatim inside align

Post by Stefan Kottwitz »

Hi jaybz,

you could use the examplep package, for instance:

Code: Select all

\documentclass{article}
\usepackage{examplep}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x &= 2 \\
\PVerb{\int}
z &= 4 \\
\end{align*}
\end{document}
Stefan
LaTeX.org admin
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

verbatim inside align

Post by jaybz »

Thank you, this will work but I've noticed some strange behavior in the examplep package. For instance in my code below it keeps white space between the "x" and the "&" Also between the "=" and "2" but ignores the space between the \int and \theta.

Code: Select all

\documentclass{article}
\usepackage{examplep}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x &= 2 \qquad \PVerb{code:  x &= 2 \int  \theta  \\} \\
z &= 4 \\
\end{align*}
\end{document}
Last edited by jaybz on Sun Nov 14, 2010 7:55 am, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

verbatim inside align

Post by Stefan Kottwitz »

Yes, spaces can get lost. Some explanation can be found inside the documentation, just scan for space or spaces in the pdf.
There are options for spaces, commands to produce visible and invisible spaces and further verbatim commands with different behavior and quoting, so it should work somehow.

Stefan
LaTeX.org admin
Lii
Posts: 1
Joined: Tue Mar 05, 2013 12:06 pm

Re: verbatim inside align

Post by Lii »

If what you want to have is to get the fixed with font you have in verbatim inside a math context (that's what I wanted when I found this post) you can use the \mathtt{...} command.
Post Reply