diff --git a/Text/TeXMath/Macros.hs b/Text/TeXMath/Macros.hs
--- a/Text/TeXMath/Macros.hs
+++ b/Text/TeXMath/Macros.hs
@@ -44,15 +44,12 @@
 
 -- | Applies a list of macros to a string recursively until a fixed
 -- point is reached.  If there are several macros in the list with the
--- same name, later ones will shadow earlier ones.
+-- same name, earlier ones will shadow later ones.
 applyMacros :: [Macro] -> String -> String
 applyMacros [] = id
-applyMacros ms = iterateToFixedPoint ((2 * length ms) + 1) $
-                  applyMacrosOnce $ reverse ms -- we reverse so that the most recently
-                                               -- defined macros will be applied first
-                                               -- and shadow others with the same name
+applyMacros ms = iterateToFixedPoint ((2 * length ms) + 1) $ applyMacrosOnce ms
 
-------------------------------------------------------------------------------------
+------------------------------------------------------------------------------
 
 iterateToFixedPoint :: Eq a => Int -> (a -> a) -> a -> a
 iterateToFixedPoint 0     _ _ = error $
diff --git a/cgi/texmath-cgi.hs b/cgi/texmath-cgi.hs
--- a/cgi/texmath-cgi.hs
+++ b/cgi/texmath-cgi.hs
@@ -24,7 +24,8 @@
     case parse pMacros "macros" (rawMacros ++ "\n") of
          Left err  -> toJSObject [("success", JSBool False)
                                  ,("error", JSString $ toJSString (show err))]
-         Right ms  -> case texMathToMathML DisplayBlock (applyMacros ms latexFormula) of
+         Right ms  -> case texMathToMathML DisplayBlock
+                               (applyMacros (reverse ms) latexFormula) of
                        Left e  -> toJSObject [("success", JSBool False)
                                              , ("error", JSString $ toJSString e)]
                        Right v -> toJSObject [("success", JSBool True)
diff --git a/texmath.cabal b/texmath.cabal
--- a/texmath.cabal
+++ b/texmath.cabal
@@ -1,5 +1,5 @@
 Name:                texmath
-Version:             0.3.1.4
+Version:             0.3.1.5
 Cabal-version:       >= 1.2
 Build-type:          Custom
 Synopsis:            Conversion of LaTeX math formulas to MathML.
diff --git a/texmath.hs b/texmath.hs
--- a/texmath.hs
+++ b/texmath.hs
@@ -20,7 +20,7 @@
 stripMacroDefs = do
   macros <- many (try $ pSkipSpaceComments >> pMacroDefinition)
   rest <- getInput
-  return (macros, rest)
+  return (reverse macros, rest)  -- reversed so later ones will shadow earlier
 
 main :: IO ()
 main = do
