<commit_before>(function () {

	function getLatexURL() {
		// Todo: better way of getting the LaTeX address.
		tex = $('#modal_latex_input').text();
		url = 'http://localhost:5000/i.png?c=' + encodeURIComponent(tex);
		return url;
	}

	function LatexHead() {
		this.position = new Point(0, 0);
		this.stage = 0;
		// 0 - text input
		// 1 - placement
		modalOpen('.modal_latex');
		$('#modal_latex_input').text('\sqrt{a^2 + b^2} = c');
		$('#modal_latex_input').show();
		$('#modal_latex_positionable').hide();
	}

	LatexHead.prototype.onMove = function(p) {
		this.position = new Point(p.x, p.y);
		$('#modal_latex_positionable').css('left', p.x);
		$('#modal_latex_positionable').css('top', p.y);
	}

	LatexHead.prototype.onRelease = function() {
		// do nothing...
	}

	LatexHead.prototype.onModalConfirm = function() {
		if (this.stage == 1) {
			console.log('LaTeX confirmed');
			sendPaintEvent('image', {
				position: this.position,
				url: getLatexURL()
			});
			this.onModalCancel();
		}
		if (this.stage == 0) {
			this.stage = 1;
			$('#modal_latex_input').hide();
			$('#modal_latex_image').hide();
			$('#modal_latex_positionable').show();
		}
	}

	LatexHead.prototype.onModalCancel = function() {
		modalClose('.modal_latex');
	}

	var latex_get_timeout = null;

	$(document).ready(function() {
		// When a key is pressed, update the image to reflect the code.
		$('#modal_latex_input').keydown(function() {
			if (latex_get_timeout != null) {
				window.clearTimeout(latex_get_timeout);
			}
			latex_get_timeout = window.setTimeout(
				function() {
					console.log('Updating LaTeX preview:', getLatexURL());
					$('#modal_latex_image').attr('src', getLatexURL());
					$('#modal_latex_positionable').attr('src', getLatexURL());
				}
			, 400);
		});
	});

	makeTool({
		name: 'latex',
		buttonImage: 'button_maths.png',
		buttonImageSelected: 'button_maths_selected.png',
		onButtonClick: function() {
			console.log('LaTeX!');
			return true;
		},
		makeToolHead: function() {
			return new LatexHead();
		},
		drawFull: function(data) {
			// This should never happen.
			// Draw calls should be routed to the image tool.
			console.error('Called drawFull on LaTeX tool.');
		}
	});

})();<commit_msg>LaTeX url has the same domain as the page<commit_after>(function () {

	function getLatexURL() {
		// Todo: better way of getting the LaTeX address.
		tex = $('#modal_latex_input').text();
		url = 'http://' + document.domain + ':5000/i.png?c=' + encodeURIComponent(tex);
		return url;
	}

	function LatexHead() {
		this.position = new Point(0, 0);
		this.stage = 0;
		// 0 - text input
		// 1 - placement
		modalOpen('.modal_latex');
		$('#modal_latex_input').text('\sqrt{a^2 + b^2} = c');
		$('#modal_latex_input').show();
		$('#modal_latex_positionable').hide();
	}

	LatexHead.prototype.onMove = function(p) {
		this.position = new Point(p.x, p.y);
		$('#modal_latex_positionable').css('left', p.x);
		$('#modal_latex_positionable').css('top', p.y);
	}

	LatexHead.prototype.onRelease = function() {
		// do nothing...
	}

	LatexHead.prototype.onModalConfirm = function() {
		if (this.stage == 1) {
			console.log('LaTeX confirmed');
			sendPaintEvent('image', {
				position: this.position,
				url: getLatexURL()
			});
			this.onModalCancel();
		}
		if (this.stage == 0) {
			this.stage = 1;
			$('#modal_latex_input').hide();
			$('#modal_latex_image').hide();
			$('#modal_latex_positionable').show();
		}
	}

	LatexHead.prototype.onModalCancel = function() {
		modalClose('.modal_latex');
	}

	var latex_get_timeout = null;

	$(document).ready(function() {
		// When a key is pressed, update the image to reflect the code.
		$('#modal_latex_input').keydown(function() {
			if (latex_get_timeout != null) {
				window.clearTimeout(latex_get_timeout);
			}
			latex_get_timeout = window.setTimeout(
				function() {
					console.log('Updating LaTeX preview:', getLatexURL());
					$('#modal_latex_image').attr('src', getLatexURL());
					$('#modal_latex_positionable').attr('src', getLatexURL());
				}
			, 400);
		});
	});

	makeTool({
		name: 'latex',
		buttonImage: 'button_maths.png',
		buttonImageSelected: 'button_maths_selected.png',
		onButtonClick: function() {
			console.log('LaTeX!');
			return true;
		},
		makeToolHead: function() {
			return new LatexHead();
		},
		drawFull: function(data) {
			// This should never happen.
			// Draw calls should be routed to the image tool.
			console.error('Called drawFull on LaTeX tool.');
		}
	});

})();
{'fraction_non_alphanumeric': 0.182688028482421, 'fraction_numerical': 0.0075656430796617715, 'mean_word_length': 3.7921108742004264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2057355', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1582, 'n_words': 300}