 
 	# Searches for the first latex block in the given string
 	find_latex: (str) ->
-		unless str.length and (opening_delimiter_match = @find_opening_delimiter str)?
-			return null
-		
-		match = @get_latex_boundaries str, opening_delimiter_match
+		start = 0
+		while (opening_delimiter_match = @find_opening_delimiter str, start++)?
 
-		match?.options = opening_delimiter_match.options
+			match = @get_latex_boundaries str, opening_delimiter_match
 
-		return match
+			if match?.inner.extract(str).trim().length
+				match.options = opening_delimiter_match.options
+				return match
+
+		return null
 
 	# Breaks a message to what comes before, after and to the content of a
 	# matched latex block

		before = str.substr 0, match.outer.start
		after  = str.substr match.outer.end

		latex = str.substr match.inner.start, match.inner.length()
		latex = s.unescapeHTML latex

		return { before: before, latex : latex, after : after }

			rendered =  "<div class=\"katex-error katex-#{display_mode}-error\">"
			rendered += 	"#{e.message}"
			rendered += "</div>"

		return rendered

	# Takes a string and renders all latex blocks inside it
	render: (str) ->
		result = ''

		loop

			# Find the first latex block in the string
			match = @find_latex str

			unless match?
				result += str
				break
