When using a fancyvrb in a ifthenelse environment, I came across the issue where you can't have a verb within something else, but really all I'm looking for is something that will make a code listing with line numbers, preferrably in a code-like font. Is there an alternative?
Are there any other things I need to look out for that I can't include in ifthenelse?
General ⇒ Verbatim-like environment
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Posts: 47
- Joined: Wed Nov 11, 2009 9:30 pm
Re: Verbatim-like environment
But I'm looking for something that works inside ifthenelse.
The basic listings example doesn't work ("Package Listings Warning: Text dropped after begin of listing on input line 19.", compilation stops):
\documentclass[11pt]{article}
\newcounter{thenum}
\setcounter{thenum}{1}
\usepackage{listings}
\usepackage{ifthen}
\begin{document}
\ifthenelse{\arabic{thenum}=1}{
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
\end{lstlisting}
}{}
\end{document}
The basic listings example doesn't work ("Package Listings Warning: Text dropped after begin of listing on input line 19.", compilation stops):
\documentclass[11pt]{article}
\newcounter{thenum}
\setcounter{thenum}{1}
\usepackage{listings}
\usepackage{ifthen}
\begin{document}
\ifthenelse{\arabic{thenum}=1}{
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
\end{lstlisting}
}{}
\end{document}
Verbatim-like environment
You can't use verbatim-like environments inside of macro arguments. Here you must use TeX primitives:
Code: Select all
\documentclass[11pt]{article}
\newcounter{thenum}
\setcounter{thenum}{1}
\usepackage{listings}
\usepackage{ifthen}
\begin{document}
\ifnum\value{thenum}=1
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
\end{lstlisting}
\fi
\end{document}