diff --git a/doc/sphinx/conf.py.in b/doc/sphinx/conf.py.in
index cdabf7ef2c71042410d937ca4bea0c192c0b450a..42e3c79bb2b9116bd1b8fa3bb5738ead730a4900 100644
--- a/doc/sphinx/conf.py.in
+++ b/doc/sphinx/conf.py.in
@@ -12,6 +12,7 @@
 # serve to show the default.
 
 import sys, os
+from sphinx import version_info as sphinx_version
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
@@ -23,7 +24,8 @@ sys.path = [os.path.abspath('@CMAKE_SOURCE_DIR@/src')]+sys.path
 
 # Add any Sphinx extension module names here, as strings. They can be extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.pngmath']
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo']
+extensions.append('sphinx.ext.pngmath' if sphinx_version < (1, 4) else 'sphinx.ext.imgmath')
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']