--- app/helpers/application_helper.rb.orig	2006-12-21 16:53:54.000000000 -0600
+++ app/helpers/application_helper.rb	2006-12-21 16:54:37.000000000 -0600
@@ -23,7 +23,7 @@
         if element.last != selected
           options << "<option value=\"#{element.last}\">#{element.first}</option>"
         else
-          options << "<option value=\"#{element.last}\" selected>#{element.first}</option>"
+          options << "<option value=\"#{element.last}\" selected=\"selected\">#{element.first}</option>"
         end
       else
         options << ((element != selected) ? "<option>#{element}</option>" : "<option selected>#{element}</option>")
--- app/controllers/application.rb.orig	2006-12-21 16:48:49.000000000 -0600
+++ app/controllers/application.rb	2006-12-21 23:43:04.000000000 -0600
@@ -48,6 +48,7 @@
     '.pdf' => 'application/pdf',
     '.png' => 'image/png',
     '.txt' => 'text/plain',
+    '.tex' => 'text/plain',
     '.zip' => 'application/zip'
   } unless defined? FILE_TYPES
 
@@ -114,7 +114,7 @@
 
   def rescue_action_in_public(exception)
     render :status => 500, :text => <<-EOL
-      <html><body>
+      <html xmlns="http://www.w3.org/1999/xhtml"><body>
         <h2>Internal Error</h2>
         <p>An application error occurred while processing your request.</p>
         <!-- \n#{exception}\n#{exception.backtrace.join("\n")}\n -->
@@ -145,8 +146,10 @@
   def set_content_type_header
     if %w(rss_with_content rss_with_headlines).include?(action_name)
       @response.headers['Content-Type'] = 'text/xml; charset=UTF-8'
+    elsif %w(tex).include?(action_name)
+      @response.headers['Content-Type'] = 'text/plain; charset=UTF-8'
     else
-      @response.headers['Content-Type'] = 'text/html; charset=UTF-8'
+      @response.headers['Content-Type'] = 'application/xhtml+xml; charset=UTF-8'
     end
   end
 
--- app/views/admin/create_system.rhtml.orig	2006-12-21 16:58:18.000000000 -0600
+++ app/views/admin/create_system.rhtml	2006-12-21 17:07:39.000000000 -0600
@@ -7,7 +7,7 @@
 </p>
 
 <%= form_tag({ :controller => 'admin', :action => 'create_system'},
-             {'id' => 'setup', 'method' => 'post', 'onSubmit' => 'return validateSetup()'})
+             {'id' => 'setup', 'method' => 'post', 'onsubmit' => 'return validateSetup()'})
 %>
 <ol class="setup">
   <li>
@@ -21,9 +21,9 @@
     </div>
     <div class="inputBox">
       Name: <input type="text" id="web_name" name="web_name" value="Wiki" 
-            onChange="proposeAddress();" onClick="this.value == 'Wiki' ? this.value = '' : true" /> 
+            onchange="proposeAddress();" onclick="this.value == 'Wiki' ? this.value = '' : true" /> 
       &nbsp;&nbsp;
-      Address: <input type="text" id="web_address" name="web_address" onChange="cleanAddress();"
+      Address: <input type="text" id="web_address" name="web_address" onchange="cleanAddress();"
                value="wiki" />
     </div>
   </li>
--- app/views/file/import.rhtml.orig	2006-12-21 17:01:04.000000000 -0600
+++ app/views/file/import.rhtml	2006-12-21 17:01:25.000000000 -0600
@@ -13,7 +13,7 @@
   <p>
     <input type="submit" value="Update" /> as 
     <input type="text" name="author" id="authorName" value="<%= @author %>" 
-        onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" />
+        onclick="this.value == 'AnonymousCoward' ? this.value = '' : true" />
 	<% if @page %>
       | <%= link_to 'Cancel', :web => @web.address, :action => 'file'%> <small>(unlocks page)</small>
     <% end %>
--- app/views/textile_help.rhtml.orig	2006-12-21 17:01:49.000000000 -0600
+++ app/views/textile_help.rhtml	2006-12-21 17:02:17.000000000 -0600
@@ -1,4 +1,4 @@
-<h3>Textile formatting tips (<a href="http://hobix.com/textile/quick.html" onClick="quickRedReference(); return false;">advanced</a>)</h3>
+<h3>Textile formatting tips (<a href="http://hobix.com/textile/quick.html" onclick="quickRedReference(); return false;">advanced</a>)</h3>
 <table cellspacing="0" cellpadding="0">
   <tr><td>_your text_</td><td class="arrow">&rarr;</td><td><em>your text</em></td></tr>
   <tr><td>*your text*</td><td class="arrow">&rarr;</td><td><strong>your text</strong></td></tr>
--- app/views/wiki/rollback.rhtml.orig	2006-12-21 17:03:24.000000000 -0600
+++ app/views/wiki/rollback.rhtml	2006-12-21 17:11:14.000000000 -0600
@@ -7,7 +7,7 @@
 <%= "<p style='color:red'>Please correct the error that caused this error in rendering:<br/><small>#{@params["msg"]}</small></p>" if @params["msg"] %>
 
 <%= form_tag({:web => @web.address, :action => 'save', :id => @page.name},
-      {:id => 'editForm', :method => 'post', :onSubmit => 'cleanAuthorName();'})
+      {:id => 'editForm', :method => 'post', :onsubmit => 'cleanAuthorName();'})
 %>
 <p>
   <textarea name="content" style="font-size: 12px; width: 450px; height: 500px"><%= @revision.content %></textarea>
@@ -15,7 +15,7 @@
 <p>
     <input type="submit" value="Update" accesskey="u" /> as 
     <input type="text" name="author" id="authorName" value="<%= @author %>" 
-        onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" />
+        onclick="this.value == 'AnonymousCoward' ? this.value = '' : true" />
     | 
     <% link_to('Cancel', 
          {:web => @web.address, :action => 'cancel_edit', :id => @page.name},
--- app/views/admin/create_web.rhtml.orig	2006-12-21 17:05:29.000000000 -0600
+++ app/views/admin/create_web.rhtml	2006-12-21 17:08:05.000000000 -0600
@@ -6,7 +6,7 @@
 </p>
 
 <%= form_tag({ :controller => 'admin', :action => 'create_web'},
-             {'id' => 'setup', 'method' => 'post', 'onSubmit' => 'cleanAddress(); return validateSetup()'})
+             {'id' => 'setup', 'method' => 'post', 'onsubmit' => 'cleanAddress(); return validateSetup()'})
 %>
 
 <ol class="setup">
@@ -19,9 +19,9 @@
       The address can only consist of letters and digits.
     </div>
     <div class="inputBox">
-      Name: <input type="text" id="web_name" name="name" onChange="proposeAddress();" />
+      Name: <input type="text" id="web_name" name="name" onchange="proposeAddress();" />
       &nbsp;&nbsp;
-      Address: <input type="text" id="web_address" name="address" onChange="cleanAddress();" />
+      Address: <input type="text" id="web_address" name="address" onchange="cleanAddress();" />
     </div>
   </li>
 </ol>
--- app/views/wiki/edit.rhtml.orig	2006-12-21 17:09:16.000000000 -0600
+++ app/views/wiki/edit.rhtml	2006-12-21 17:09:39.000000000 -0600
@@ -10,7 +10,7 @@
 </div>
 
 <%= form_tag({ :action => 'save', :web => @web.address, :id => @page.name},
-             {'id' => 'editForm', 'method' => 'post', 'onSubmit' => 'cleanAuthorName()'})
+             {'id' => 'editForm', 'method' => 'post', 'onsubmit' => 'cleanAuthorName()'})
 %>
 
 <p>
--- app/views/layouts/default.rhtml.orig	2006-12-22 22:07:07.000000000 -0600
+++ app/views/layouts/default.rhtml	2006-12-22 22:08:18.000000000 -0600
@@ -1,6 +1,4 @@
-<!DOCTYPE html
-PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd" >
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
   <title>
--- app/views/markdownMML_help.rhtml.orig	2006-12-22 23:42:06.000000000 -0600
+++ app/views/markdownMML_help.rhtml	2006-12-22 23:40:39.000000000 -0600
@@ -0,0 +1,13 @@
+<h3>Markdown + itex2MML  formatting tips (<a target="_new" href="http://daringfireball.net/projects/markdown/syntax">advanced</a>)</h3>
+<table cellspacing="0" cellpadding="0">
+  <tr><td>_your text_</td><td class="arrow">&rarr;</td><td><em>your text</em></td></tr>
+  <tr><td>**your text**</td><td class="arrow">&rarr;</td><td><strong>your text</strong></td></tr>
+  <tr><td>`my code`</td><td class="arrow">&rarr;</td><td><code>my code</code></td></tr>
+  <tr><td>* Bulleted list<br />* Second item</td><td class="arrow">&rarr;</td><td>&#8226; Bulleted list<br />&#8226; Second item</td></tr>
+  <tr><td>1. Numbered list<br />1. Second item</td><td class="arrow">&rarr;</td><td>1. Numbered list<br />2. Second item</td></tr>
+  <tr><td>[link name](URL)</td><td class="arrow">&rarr;</td><td><a href="URL">link name</a></td></tr>
+  <tr><td>***</td><td class="arrow">&rarr;</td><td>Horizontal ruler</td></tr>
+  <tr><td>&lt;http://url><br />&lt;email@add.com></td><td class="arrow">&rarr;</td><td>Auto-linked</td></tr>
+  <tr><td>![Alt text](URL)</td><td class="arrow">&rarr;</td><td>Image</td></tr>
+</table>
+<p>For a complete list of LaTeX commands supported here, see the <a href="http://golem.ph.utexas.edu/~distler/blog/itex2MMLcommands.html">itex2MML Commands Summary</a>.</p>
--- lib/bluecloth_tweaked.rb.orig	2006-12-23 01:18:19.000000000 -0600
+++ lib/bluecloth_tweaked.rb	2006-12-23 01:19:22.000000000 -0600
@@ -1112,7 +1112,7 @@
 
 	### Return a copy of +str+ with angle brackets and ampersands HTML-encoded.
 	def encode_html( str )
-		str.gsub( /&(?!#?[x]?(?:[0-9a-f]+|\w{1,8});)/i, "&amp;" ).
+		str.gsub( /&(?!#?[x]?(?:[0-9a-f]+|\w+);)/i, "&amp;" ).
 			gsub( %r{<(?![a-z/?\$!])}i, "&lt;" )
 	end
 
--- app/views/wiki/new.rhtml.orig	2006-12-21 17:10:16.000000000 -0600
+++ app/views/wiki/new.rhtml	2006-12-21 17:10:31.000000000 -0600
@@ -10,7 +10,7 @@
 </div>
 
 <%= form_tag({ :action => 'save', :web => @web.address, :id => @page_name},
-             {'id' => 'editForm', 'method' => 'post', 'onSubmit' => 'cleanAuthorName();'})
+             {'id' => 'editForm', 'method' => 'post', 'onsubmit' => 'cleanAuthorName();'})
 %>
 
 <p>
--- app/views/admin/edit_web.rhtml.orig	2006-12-21 16:59:46.000000000 -0600
+++ app/views/admin/edit_web.rhtml	2006-12-21 22:54:27.000000000 -0600
@@ -1,7 +1,7 @@
 <% @title = "Edit Web" %>
 
 <%= form_tag({ :controller => 'admin', :action => 'edit_web', :web => @web.address },
-             {'id' => 'setup', 'method' => 'post', 'onSubmit' => 'cleanAddress(); return validateSetup()'})
+             {'id' => 'setup', 'method' => 'post', 'onsubmit' => 'cleanAddress(); return validateSetup()'})
 %>
 
   <h2 style="margin-bottom: 3px">Name and address</h2>
@@ -13,9 +13,9 @@
 
   <div class="inputBox">
     Name: <input type="text" id="name" name="name" class="disableAutoComplete" value="<%= @web.name %>" 
-                 onChange="proposeAddress();" /> &nbsp;&nbsp;
+                 onchange="proposeAddress();" /> &nbsp;&nbsp;
     Address: <input type="text" class="disableAutoComplete" id="address" name="address" value="<%= @web.address %>" 
-                    onChange="cleanAddress();" />
+                    onchange="cleanAddress();" />
     <small><em>(Letters and digits only)</em></small>
   </div>
 
@@ -23,7 +23,7 @@
   <div class="inputBox">
     Markup:
     <select name="markup">
-      <%= html_options({'Textile' => :textile, 'Markdown' => :markdown, 'Mixed' => :mixed, 
+      <%= html_options({'Textile' => :textile, 'Markdown' => :markdown, 'Markdown+itex2MML' => :markdownMML, 'Mixed' => :mixed, 
               'RDoc' => :rdoc }, @web.markup) %>
     </select>
 
@@ -62,7 +62,7 @@
     </p>
 
     <a href="#" 
-       onClick="document.getElementById('additionalStyle').style.display='block';return false;">
+       onclick="document.getElementById('additionalStyle').style.display='block';return false;">
     Stylesheet tweaks &gt;&gt;</a>
     <small><em>
     - add or change styles used by this web; styles defined here take precedence over 
@@ -118,7 +118,7 @@
 
 <%= form_tag({:controller => 'admin', :web => @web.address, :action => 'remove_orphaned_pages'},
         {:id => 'remove_orphaned_pages', 
-         :onSubmit => "return checkSystemPassword(document.getElementById('system_password_orphaned').value)"
+         :onsubmit => "return checkSystemPassword(document.getElementById('system_password_orphaned').value)"
         })
 %>
   <p align="right">
--- app/views/layouts/tex.rhtml.orig	1969-12-31 18:00:00.000000000 -0600
+++ app/views/layouts/tex.rhtml	2006-12-26 14:59:13.000000000 -0600
@@ -0,0 +1 @@
+<%= @content_for_layout %>
--- app/views/wiki/tex.rhtml.orig	2006-12-26 13:05:05.000000000 -0600
+++ app/views/wiki/tex.rhtml	2006-12-26 13:12:25.000000000 -0600
@@ -1,12 +1,12 @@
 \documentclass[12pt,titlepage]{article}
 
-\usepackage[danish]{babel}      %danske tekster
+\usepackage{amsmath}
+\usepackage{amsfonts}
 \usepackage[OT1]{fontenc}       %rigtige danske bogstaver...
-\usepackage{a4}
 \usepackage{graphicx}
 \usepackage{ucs}
 \usepackage[utf8x]{inputenc}
-\input epsf 
+\usepackage{hyperref}
 
 %-------------------------------------------------------------------
 
--- app/views/wiki/page.rhtml.orig	2006-12-26 13:23:51.000000000 -0600
+++ app/views/wiki/page.rhtml	2006-12-26 13:25:00.000000000 -0600
@@ -37,7 +37,7 @@
     <%= link_to('Print',
             { :web => @web.address, :action => 'print', :id => @page.name },
             { :accesskey => 'p', :name => 'view_print' }) %>
-  <% if defined? RedClothForTex and RedClothForTex.available? and @web.markup == :textile %>
+  <% if defined? RedClothForTex and RedClothForTex.available? and @web.markup == :textile or @web.markup == :markdownMML %>
     | 
     <%= link_to 'TeX', {:web => @web.address, :action => 'tex', :id => @page.name}, 
             {:name => 'view_tex'} %>
--- lib/chunks/engines.rb.orig	2006-12-21 22:32:47.000000000 -0600
+++ lib/chunks/engines.rb	2007-01-13 02:06:22.000000000 -0600
@@ -40,6 +40,13 @@
     end
   end
 
+  class MarkdownMML < AbstractEngine
+    def mask
+      require_dependency 'maruku'
+      Maruku.new(@content.delete("\r")).to_html
+    end
+  end
+
   class Mixed < AbstractEngine
     def mask
       require_dependency 'redcloth'
@@ -57,6 +64,6 @@
     end
   end
 
-  MAP = { :textile => Textile, :markdown => Markdown, :mixed => Mixed, :rdoc => RDoc }
+  MAP = { :textile => Textile, :markdown => Markdown, :markdownMML => MarkdownMML, :mixed => Mixed, :rdoc => RDoc }
   MAP.default = Textile
 end
--- app/controllers/wiki_controller.rb.orig	2006-12-26 01:49:25.000000000 -0600
+++ app/controllers/wiki_controller.rb	2007-01-13 02:19:11.000000000 -0600
@@ -8,7 +8,7 @@
   caches_action :show, :published, :authors, :recently_revised, :list
   cache_sweeper :revision_sweeper
 
-  layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex,  :export_tex, :export_html]
+  layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :pdf, :export_tex, :export_html]
 
   def index
     if @web_name
@@ -279,8 +279,12 @@
   end
 
   def tex
+    if @web.markup == :markdownMML
+      @tex_content = Maruku.new(@page.content).to_latex
+    else
     @tex_content = RedClothForTex.new(@page.content).to_tex
   end
+  end
 
   protected
   
@@ -305,8 +309,12 @@
   end
 
   def export_page_to_tex(file_path)
-    tex
-    File.open(file_path, 'w') { |f| f.write(render_to_string(:template => 'wiki/tex', :layout => nil)) }
+    if @web.markup == :markdownMML
+      @tex_content = Maruku.new(@page.content).to_latex
+    else
+      @tex_content = RedClothForTex.new(@page.content).to_tex
+    end
+    File.open(file_path, 'w') { |f| f.write(render_to_string(:template => 'wiki/tex', :layout => 'tex')) }
   end
 
   def export_pages_as_zip(file_type, &block)
@@ -392,7 +400,11 @@
 
   def render_tex_web
     @web.select.by_name.inject({}) do |tex_web, page|
+      if  @web.markup == :markdownMML
+        tex_web[page.name] = Maruku.new(page.content).to_latex
+      else
       tex_web[page.name] = RedClothForTex.new(page.content).to_tex
+      end
       tex_web
     end
   end
--- public/stylesheets/instiki.css.orig	2007-01-13 02:33:09.000000000 -0600
+++ public/stylesheets/instiki.css	2007-01-13 02:31:51.000000000 -0600
@@ -81,3 +81,8 @@
 
 /* Affects the display of "category: ..." */
 .property { color: #999; font-size: 80%; }
+
+merror {display:inline;font-size:1em;}
+math[display=block] {overflow:auto;}
+math { white-space: nowrap }
+.eqno {float:right}
