diff --git a/Text/TeXMath/Macros.hs b/Text/TeXMath/Macros.hs
--- a/Text/TeXMath/Macros.hs
+++ b/Text/TeXMath/Macros.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE RankNTypes #-}
 {-
 Copyright (C) 2010 John MacFarlane <jgm@berkeley.edu>
 
@@ -31,15 +32,19 @@
 import Control.Monad
 import Text.ParserCombinators.Parsec
 
-newtype Macro = Macro { macroParser :: Parser String }
+data Macro = Macro { macroDefinition :: String
+                   , macroParser :: forall st . GenParser Char st String }
 
+instance Show Macro where
+  show m = "Macro " ++ show (macroDefinition m)
+
 -- | Parses a @\\newcommand@ or @\\renewcommand@ macro definition and
 -- returns a 'Macro'.
-pMacroDefinition :: Parser Macro
+pMacroDefinition :: GenParser Char st Macro
 pMacroDefinition = newcommand
 
 -- | Skip whitespace and comments.
-pSkipSpaceComments :: Parser ()
+pSkipSpaceComments :: GenParser Char st ()
 pSkipSpaceComments = spaces >> skipMany (comment >> spaces)
 
 -- | Applies a list of macros to a string recursively until a fixed
@@ -77,7 +82,7 @@
                     res <- many1 letter <|> count 1 anyChar
                     return $ '\\' : res
 
-newcommand :: Parser Macro
+newcommand :: GenParser Char st Macro
 newcommand = try $ do
   char '\\'
   optional $ try $ string "re"
@@ -97,7 +102,11 @@
                    Nothing -> numargs
   pSkipSpaceComments
   body <- inbraces
-  return $ Macro $ try $ do
+  let defn = "\\newcommand{" ++ name ++ "}" ++
+             (if numargs > 0 then ("[" ++ show numargs ++ "]") else "") ++
+             case optarg of { Nothing -> ""; Just x -> "[" ++ x ++ "]"} ++
+             "{" ++ body ++ "}"
+  return $ Macro defn $ try $ do
     char '\\'
     string name'
     when (all isLetter name') $
@@ -121,17 +130,17 @@
 apply args (x:xs) = x : apply args xs
 apply _ "" = ""
 
-skipComment :: Parser ()
+skipComment :: GenParser Char st ()
 skipComment = skipMany comment
 
-comment :: Parser ()
+comment :: GenParser Char st ()
 comment = do
   char '%'
   skipMany (notFollowedBy newline >> anyChar)
   newline
   return ()
 
-numArgs :: Parser Int
+numArgs :: GenParser Char st Int
 numArgs = option 0 $ do
   pSkipSpaceComments
   char '['
@@ -141,13 +150,13 @@
   char ']'
   return $ read [n]
 
-optArg :: Parser (Maybe String)
+optArg :: GenParser Char st (Maybe String)
 optArg = option Nothing $ (liftM Just $ inBrackets)
 
-escaped :: String -> Parser String
+escaped :: String -> GenParser Char st String
 escaped xs = try $ char '\\' >> oneOf xs >>= \x -> return ['\\',x]
 
-inBrackets :: Parser String
+inBrackets :: GenParser Char st String
 inBrackets = try $ do
   char '['
   pSkipSpaceComments
@@ -155,14 +164,14 @@
           (try $ pSkipSpaceComments >> char ']')
   return $ concat res
 
-inbraces :: Parser String
+inbraces :: GenParser Char st String
 inbraces = try $ do
   char '{'
   res <- manyTill (skipComment >> (inbraces' <|> count 1 anyChar <|> escaped "{}"))
     (try $ skipComment >> char '}')
   return $ concat res
 
-inbraces' :: Parser String
+inbraces' :: GenParser Char st String
 inbraces' = do
   res <- inbraces
   return $ '{' : (res ++ "}")
diff --git a/texmath.cabal b/texmath.cabal
--- a/texmath.cabal
+++ b/texmath.cabal
@@ -1,5 +1,5 @@
 Name:                texmath
-Version:             0.3.1.5
+Version:             0.4
 Cabal-version:       >= 1.2
 Build-type:          Custom
 Synopsis:            Conversion of LaTeX math formulas to MathML.
