diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp
index 8eabbc19ab..ecc4220e5b 100644
--- a/src/output_xhtml.cpp
+++ b/src/output_xhtml.cpp
@@ -143,6 +143,8 @@ void XHTMLStream::writeError(std::string const & s)
bool XHTMLStream::closeFontTags()
{
+ if (tag_stack_.empty())
+ return true;
// first, we close any open font tags we can close
StartTag curtag = tag_stack_.back();
while (html::isFontTag(curtag.tag_)) {