diff --git a/libempathy-gtk/empathy-theme.c b/libempathy-gtk/empathy-theme.c
index b1afa51..e659045 100644
--- a/libempathy-gtk/empathy-theme.c
+++ b/libempathy-gtk/empathy-theme.c
@@ -31,6 +31,9 @@
 #include "empathy-theme.h"
 #include "empathy-smiley-manager.h"
 
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include <libempathy/empathy-debug.h>
+
 /* Number of seconds between timestamps when using normal mode, 5 minutes. */
 #define TIMESTAMP_INTERVAL 300
 
@@ -241,7 +244,47 @@ theme_insert_text_with_emoticons (GtkTextBuffer *buf,
 	}
 	g_slist_free (smileys);
 }
+          
+static GdkPixbuf*
+empathy_chat_view_get_formula_pixbuf (const gchar *tex_formula)
+{
+    GdkPixbuf *pixbuf;
+	gchar     *command;
+	gchar     *filename;
+	gchar     *formula;
+	gchar     *convert;
+	gchar     *latex;
+
+	convert = g_find_program_in_path ("convert");
+	latex = g_find_program_in_path ("latex");
+	if (!convert || !latex) {
+		DEBUG("Failed to find latex or convert. Please, install latex and/or ImageMagick");
+		g_free (convert);
+		g_free (latex);
+		return NULL;
+	}
+	g_free (convert);
+	g_free (latex);
+
+	formula = g_strndup (tex_formula + 2, strlen (tex_formula) - 4);
+	filename = g_build_filename (g_get_tmp_dir (), "empathy-formula.png", NULL);
+	command = g_strdup_printf ("empathy-tex2im -o %s \"%s\"", filename, formula);
+	g_free (formula);
+
+	g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL);
+	pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
+	g_free (command);
+	g_free (filename);
+
+	if (pixbuf) {
+		g_object_set_data_full (G_OBJECT (pixbuf), "formula",
+					g_strdup (tex_formula),
+					g_free);
+	}
 
+	return pixbuf;
+}          
+                      
 void
 empathy_theme_append_text (EmpathyTheme        *theme,
 			  EmpathyChatView     *view,
@@ -261,6 +304,7 @@ empathy_theme_append_text (EmpathyTheme        *theme,
 	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
 
 	gtk_text_buffer_get_end_iter (buffer, &start_iter);
+	
 	mark = gtk_text_buffer_create_mark (buffer, NULL, &start_iter, TRUE);
 
 	start = g_array_new (FALSE, FALSE, sizeof (gint));
@@ -294,19 +338,30 @@ empathy_theme_append_text (EmpathyTheme        *theme,
 			tmp = empathy_substring (body, s, e);
 
 			gtk_text_buffer_get_end_iter (buffer, &iter);
-			if (!link_tag) {
-				gtk_text_buffer_insert (buffer, &iter,
-							tmp, -1);
-			} {
-				gtk_text_buffer_insert_with_tags_by_name (buffer,
+			
+            if (g_str_has_prefix (tmp, "$$") &&
+			    g_str_has_suffix (tmp, "$$")) {
+			    	GdkPixbuf *pixbuf;
+			    	
+				pixbuf = empathy_chat_view_get_formula_pixbuf (tmp);
+				if (pixbuf) {
+					gtk_text_buffer_insert_pixbuf (buffer,
+								       &iter,
+								       pixbuf);
+					g_object_unref (pixbuf);
+				} else {
+            		theme_insert_text_with_emoticons (buffer, &iter, body, priv->smiley_manager);
+				}
+			} else {
+			   gtk_text_buffer_insert_with_tags_by_name (buffer,
 									  &iter,
 									  tmp,
 									  -1,
 									  link_tag,
 									  "link",
 									  NULL);
-			}
-
+               
+            }
 			g_free (tmp);
 
 			last = e;
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index 3762b89..d7dc808 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -101,6 +101,10 @@ regex_init (void)
 				"(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9]"
 				"[a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+";
 			break;
+		case EMPATHY_REGEX_LATEX:
+			expression =
+				"\\$\\$.+\\$\\$";
+			break;
 		case EMPATHY_REGEX_OTHER:
 			expression =
 				"news:[-A-Z\\^_a-z{|}~!\"#$%&'()*+,./0-9;:=?`]+"
diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h
index 92ba44a..d146095 100644
--- a/libempathy/empathy-utils.h
+++ b/libempathy/empathy-utils.h
@@ -48,6 +48,7 @@ typedef enum {
 	EMPATHY_REGEX_APT,
 	EMPATHY_REGEX_EMAIL,
 	EMPATHY_REGEX_OTHER,
+	EMPATHY_REGEX_LATEX,
 	EMPATHY_REGEX_ALL,
 } EmpathyRegExType;
 
diff --git a/src/Makefile.am b/src/Makefile.am
index dc87087..765ebec 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,8 @@ bin_PROGRAMS =			\
 	empathy-accounts	\
 	empathy-logs
 
+bin_SCRIPTS = empathy-tex2im
+
 empathy_SOURCES =							\
 	empathy.c							\
 	bacon-message-connection.c bacon-message-connection.h		\
