dp.sh.Brushes.Tex = function()
{
	this.CssClass = 'dp-tex';
}

dp.sh.Brushes.Tex.prototype	= new dp.sh.Highlighter();
dp.sh.Brushes.Tex.Aliases	= ['tex', 'latex'];

dp.sh.Brushes.Tex.prototype.ProcessRegexList = function()
{
	function push(array, value)
	{
		array[array.length] = value;
	}
	
	var index	= 0;
	var match	= null;
	var regex	= null;

	// Match comments
	// %(.*)$
	this.GetMatches(new RegExp('%(.*)$', 'gm'), 'comments');	
	
	//Match with no attribute
	// \\[a-zA-Z]*\s
	this.GetMatches(new RegExp('\\\\[a-zA-Z]*\\s', 'gm'), 'tag');
		
	//Match tag with two attributes
	// ([a-zA-Z]*)\[(\w*)\]\{(\w*)\}
	regex = new RegExp('([a-zA-Z]*)\\[(\\w*)\\]\\{(\\w*)\\}', 'gm');
	while((match = regex.exec(this.code)) != null) {	
		//preamble tag
		if (match[1] == "usepackage") {
				push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'preamble'));
		}
		else {
			push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'tag'));
		}
		if (match[3] != undefined) {
			push(this.matches, new dp.sh.Match(match[2], match.index + match[0].indexOf(match[2]), 'attribute1'));	
			push(this.matches, new dp.sh.Match(match[3], match.index + match[0].indexOf(match[3]), 'attribute2'));
		}
	}
	
	//Match with one attribute ({})
	// ([a-zA-Z]*[^\]])\{(\w*)\}
	regex = new RegExp('([a-zA-Z]*[^\\]])\\{(\\w*)\\}', 'gm');
	while((match = regex.exec(this.code)) != null) {
		//begin or end tag
		if (match[1] == "begin" || match[1] == "end") {
			push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'begend'));
			push(this.matches, new dp.sh.Match(match[2], match.index + match[0].indexOf(match[2]), 'attribute2'));
		} 
		else {
			if (match[1] == "usepackage") {
				push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'preamble'));
				push(this.matches, new dp.sh.Match(match[2], match.index + match[0].indexOf(match[2]), 'attribute2'));
			}
			else {
				push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'tag'));
				push(this.matches, new dp.sh.Match(match[2], match.index + match[0].indexOf(match[2]), 'attribute2'));
			}
			
		}
	}
}
