 	class Boundary
 		length: () ->
 			return @end - @start
+
+		extract: (str) ->
+			return str.substr @start, @length()
 
 	# Returns the outer and inner boundaries of the latex block starting
 	# at the given opening delimiter

			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 = ''

		while true

			# Find the first latex block in the string
			match = @find_latex str
			unless match?
				result += str
				break

		{ opener: '$'  , closer: '$'  , displayMode: false },
	]

	# Searches for the first opening delimiter in the string from a given position
	find_opening_delimiter: (str, start) -> # Search the string for each opening delimiter
		matches = ({options: o, pos: str.indexOf(o.opener, start)} for o in @delimiters_map)
		positions = (m.pos for m in matches when m.pos >= 0)

		# No opening delimiters were found
