GeneralVerbatim-like environment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

Verbatim-like environment

Post by CoolnessItself »

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?

Recommended reading 2024:

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

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

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Verbatim-like environment

Post by phi »

Hello,

for code listings try the listings, minted or texments package.
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

Re: Verbatim-like environment

Post by CoolnessItself »

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}
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Verbatim-like environment

Post by phi »

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}
Post Reply