Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
3  
Welcome to TeX.sx! Please expand your code to a full minimal working example (MWE). If you're not loading any packages, this is just natural, because -- as the message says -- there is no code environment. –  doncherry Jan 16 '12 at 17:28
add comment

1 Answer

up vote 8 down vote accepted

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}
share|improve this answer
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
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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