diff --git a/Text/TeXMath/Parser.hs b/Text/TeXMath/Parser.hs
--- a/Text/TeXMath/Parser.hs
+++ b/Text/TeXMath/Parser.hs
@@ -260,10 +260,10 @@
 
 subSup :: Maybe Bool -> Exp -> TP Exp
 subSup limits a = try $ do
-  symbol "_"
-  b <- expr1
-  symbol "^"
-  c <- expr
+  let sub1 = symbol "_" >> expr1
+  let sup1 = symbol "^" >> expr1
+  (b,c) <- try (do {m <- sub1; n <- sup1; return (m,n)})
+       <|> (do {n <- sup1; m <- sub1; return (m,n)})
   return $ case limits of
             Just True  -> EUnderover a b c
             Nothing | isConvertible a -> EDownup a b c
diff --git a/tests/subsup.omml b/tests/subsup.omml
new file mode 100644
--- /dev/null
+++ b/tests/subsup.omml
@@ -0,0 +1,52 @@
+<?xml version='1.0' ?>
+<m:oMathPara>
+  <m:oMathParaPr>
+    <m:jc m:val="center" />
+  </m:oMathParaPr>
+  <m:oMath>
+    <m:sSubSup>
+      <m:e>
+        <m:r>
+          <m:rPr />
+          <m:t>x</m:t>
+        </m:r>
+      </m:e>
+      <m:sub>
+        <m:r>
+          <m:rPr />
+          <m:t>a</m:t>
+        </m:r>
+      </m:sub>
+      <m:sup>
+        <m:r>
+          <m:rPr />
+          <m:t>b</m:t>
+        </m:r>
+      </m:sup>
+    </m:sSubSup>
+    <m:r>
+      <m:rPr />
+      <m:t>=</m:t>
+    </m:r>
+    <m:sSubSup>
+      <m:e>
+        <m:r>
+          <m:rPr />
+          <m:t>x</m:t>
+        </m:r>
+      </m:e>
+      <m:sub>
+        <m:r>
+          <m:rPr />
+          <m:t>b</m:t>
+        </m:r>
+      </m:sub>
+      <m:sup>
+        <m:r>
+          <m:rPr />
+          <m:t>a</m:t>
+        </m:r>
+      </m:sup>
+    </m:sSubSup>
+  </m:oMath>
+</m:oMathPara>
diff --git a/tests/subsup.tex b/tests/subsup.tex
new file mode 100644
--- /dev/null
+++ b/tests/subsup.tex
@@ -0,0 +1,1 @@
+x_a^b = x^a_b
diff --git a/tests/subsup.xhtml b/tests/subsup.xhtml
new file mode 100644
--- /dev/null
+++ b/tests/subsup.xhtml
@@ -0,0 +1,23 @@
+<?xml version='1.0' ?>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta content="application/xhtml+xml; charset=UTF-8" http-equiv="Content-Type" />
+  </head>
+  <body>
+    <math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
+      <mrow>
+        <msubsup>
+          <mi>x</mi>
+          <mi>a</mi>
+          <mi>b</mi>
+        </msubsup>
+        <mo>=</mo>
+        <msubsup>
+          <mi>x</mi>
+          <mi>b</mi>
+          <mi>a</mi>
+        </msubsup>
+      </mrow>
+    </math>
+  </body>
+</html>
diff --git a/texmath.cabal b/texmath.cabal
--- a/texmath.cabal
+++ b/texmath.cabal
@@ -1,5 +1,5 @@
 Name:                texmath
-Version:             0.6.0.4
+Version:             0.6.0.5
 Cabal-Version:       >= 1.6
 Build-type:          Custom
 Synopsis:            Conversion of LaTeX math formulas to MathML or OMML.
@@ -59,7 +59,8 @@
                      tests/sphere_volume.tex, tests/sphere_volume.xhtml, tests/sphere_volume.omml,
                      tests/unicode.tex, tests/unicode.xhtml, tests/unicode.omml,
                      tests/ensuremath.tex, tests/ensuremath.xhtml, tests/ensuremath.omml,
-                     tests/macros.tex, tests/macros.xhtml, tests/macros.omml
+                     tests/macros.tex, tests/macros.xhtml, tests/macros.omml,
+                     tests/subsup.tex, tests/subsup.xhtml, tests/subsup.omml
 
 Source-repository head
   type:              git
