4

Why do I get ! LaTeX Error: Environment code undefined. when I use:

\documentclass[10pt,a4wide]{article}
\usepackage{a4wide}
\usepackage[utf8]{inputenc}
\usepackage[portuguese]{babel}
\usepackage{graphicx}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

\begin{document}
\begin{minipage}{7cm}  

\begin{code}  

module Dir where

import TeX
import Data.List

\end{code}

\end{minipage}\hfill
\begin{minipage}{7cm}

\begin{code}

module DirV where

import TeX
import Data.List

\end{code}

\end{minipage}

With code

With verbatim

1
7

You don't have an environment called code. If you are trying to print code, you might be interested in the verbatim environment, or other pretty-printing environments/packages. See Print programs with its proper syntax.

Wrapping your code snippet into a minimal compiling document using verbatim, it produces the following output:

enter image description here

\documentclass{article}
\begin{document}
\begin{minipage}{7cm}%
\begin{verbatim}
module Dir where

import TeX
import Data.List
\end{verbatim}
\end{minipage}\hfill
\begin{minipage}{7cm}%
\begin{verbatim}
module DirV where

import TeX
import Data.List
\end{verbatim}
\end{minipage}
\end{document}
6
  • 2
    The listings package should also be mentioned here. It provides syntax highlighting and a lot of other features for code. – Martin Scharrer Jan 16 '12 at 17:36
  • It doesnt have the same format of \begin{code} but it works just fine, thanks for the tip mate – seph Jan 16 '12 at 17:40
  • @MartinScharrer: I've referenced Print programs with its proper syntax which provides a host of code formatting packages, including listings. – Werner Jan 16 '12 at 17:40
  • @seph: What "format of \begin{code}" are you referring to? If you could post an image of the format you're after, one might be able to provide a duplicate environment that suits your needs. You can do so via an edit to your post. – Werner Jan 16 '12 at 17:42
  • @seph: The verbatim environment seems to match your specification on p 4, while that of p 1 is something entirely different. – Werner Jan 16 '12 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.