Click here to Skip to main content
15,894,177 members
Articles / Web Development / ASP.NET

Enable Your Users to Write Math Equations in Your Web and Desktop Apps

Rate me:
Please Sign up or sign in to vote.
4.95/5 (81 votes)
30 Jan 2008GPL37 min read 509K   9.4K   182  
This article shows you how you can let your users type mathematical equations in popular TeX format and render them as GIF images in your web and desktop applications with just 10 minutes of coding effort.
using System;
using System.Web;

namespace Astrila.Eq2Img
{
	public class Eq2ImgUrlMapperModule : IHttpModule
	{


		HttpApplication _Application;
		EventHandler _ApplicationBeginRequestEventHandler; 
		public virtual void Init(System.Web.HttpApplication application)
		{
			_Application = application;
			_ApplicationBeginRequestEventHandler = new EventHandler(Application_BeginRequest);
			_Application.BeginRequest += _ApplicationBeginRequestEventHandler;
		}

		private void Application_BeginRequest(Object sender, EventArgs e)
		{
			HttpApplication thisApplication = (HttpApplication)sender;
			string requestUrl = thisApplication.Request.Url.ToString();
			int eqStart = requestUrl.IndexOf("$");
			int eqEnd = requestUrl.IndexOf("$.aspx");
			if (eqEnd > eqStart)
			{
				//transfer the request to http handler
				thisApplication.Context.RewritePath("~/ShowEq.ashx?" + requestUrl.Substring(eqStart+1,eqEnd-eqStart-1));
			}
			else {}; //ignore this request
		}

		public virtual void Dispose()
		{
			_Application.BeginRequest -= _ApplicationBeginRequestEventHandler;
			_Application = null;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Web Developer
United States United States
Shital Shah is a Software Engineer and is passionate about physics, mathematics and learning algorithms. You can reach him through his website and blog.

Comments and Discussions