diff --git a/article.php3 b/article.php3
index 743516a7afd7fb374a4a3972d9b62e887e0f0304..06549675be810cb0a53d9b013523d5f6941edf50 100644
--- a/article.php3
+++ b/article.php3
@@ -2,7 +2,7 @@
 
 $fond = "article";
 $delais = 24 * 3600;
-
+$xhtml = true;
 include ("inc-public.php3");
 
 ?>
diff --git a/ecrire/inc_texte.php3 b/ecrire/inc_texte.php3
index 1dbf9868ac451fbccfb65327f9113157c3a83f3e..b02cf43e322853935188f4bdb7fdfaabb7973194 100644
--- a/ecrire/inc_texte.php3
+++ b/ecrire/inc_texte.php3
@@ -217,7 +217,7 @@ function echappe_html($letexte, $source, $no_transform=false) {
 		$texte_fin = substr($texte_a_voir, $fin, strlen($texte_a_voir));
 
 		$traiter_math = "image";
-		$traiter_math = "mathml";
+		//$traiter_math = "mathml";
 		
 		if ($traiter_math == "image") {
 			while((ereg("(\\$){2}([^$]+)(\\$){2}",$texte_milieu, $regs))) {
diff --git a/ecrire/inc_tidy.php b/ecrire/inc_tidy.php
index f6411dc2e00b2ee77ae4e5f73701e47cca7b6557..536d48de19e35ceb5d891f2bae7c2679c3d5046b 100644
--- a/ecrire/inc_tidy.php
+++ b/ecrire/inc_tidy.php
@@ -38,9 +38,6 @@ function echappe_xhtml ($letexte) { // oui, c'est dingue... on echappe le mathml
 
 
 function xhtml ($buffer) {
-	$config = array('indent' => TRUE,
-               'output-xhtml' => TRUE,
-               'wrap', 200);
 	if (version_tidy() == "1") {
 		include_ecrire("inc_texte.php3");
 
@@ -48,11 +45,11 @@ function xhtml ($buffer) {
 		$buffer = $retour_echap[0];
 		$les_echap = $retour_echap[1];
 
+		// Options selon: http://tidy.sourceforge.net/docs/quickref.html
 		tidy_set_encoding ("utf8");
 		tidy_setopt('wrap', 0);
 		tidy_setopt('indent-spaces', 4);
 		tidy_setopt('output-xhtml', true);
-		tidy_setopt('add-xml-decl', true);
 		tidy_setopt('indent', 5);
 	
 		$html = tidy_parse_string($buffer);
@@ -74,4 +71,42 @@ function xhtml ($buffer) {
 
 
 
+function xhtml_nettoyer_chaine ($buffer) {
+	if (version_tidy() == "1") {
+		include_ecrire("inc_texte.php3");
+
+		$retour_echap = echappe_xhtml ($buffer);
+		$buffer = $retour_echap[0];
+		$les_echap = $retour_echap[1];
+
+		// Options selon: http://tidy.sourceforge.net/docs/quickref.html
+		tidy_set_encoding ("utf8");
+		tidy_setopt('wrap', 0);
+		tidy_setopt('indent-spaces', 4);
+		tidy_setopt('output-xhtml', true);
+		tidy_setopt('indent', 5);
+		tidy_setopt('show-body-only', true);
+	
+		$html = tidy_parse_string($buffer);
+	    tidy_clean_repair();
+	    $tidy = tidy_get_output();
+	    $tidy = echappe_retour($tidy, $les_echap, "mathml");
+		return $tidy;
+	}
+	else if (version_tidy() == "2") {
+		$config = array('indent' => TRUE,
+			'output-xhtml' => TRUE,
+			'wrap' => 200,
+			'show-body-only' => TRUE);
+		$tidy = tidy_parse_string($buffer, $config, 'UTF8');
+		$tidy->cleanRepair();
+	return $tidy;	
+	}	
+	else return $buffer;
+}	
+
+
+
+
+
 ?>
\ No newline at end of file
diff --git a/inc-admin.php3 b/inc-admin.php3
index 6a5ef7d18293aa674f39743175f9b2892006915f..34865e0431c1e3dd4c5609a0804d56fc79c10a10 100644
--- a/inc-admin.php3
+++ b/inc-admin.php3
@@ -14,7 +14,7 @@ function bouton_admin($titre, $lien) {
 	$link = new Link($lien);
 	$link->delVar('submit');
 	echo $link->getForm('GET');
-	echo "<input type='submit' name='submit' value=\"".attribut_html($titre)."\" class='spip_bouton'>\n";
+	echo "<input type='submit' name='submit' value=\"".attribut_html($titre)."\" class='spip_bouton' />\n";
 	echo "</form>";
 }
 
@@ -53,7 +53,7 @@ function afficher_boutons_admin() {
 	echo $link->getForm('GET');
 	if ($GLOBALS['use_cache']) $pop = " *";
 	else $pop = "";
-	echo "<input type='submit' class='spip_bouton' name='submit' value=\"".attribut_html(_T('admin_recalculer')).$pop."\">";
+	echo "<input type='submit' class='spip_bouton' name='submit' value=\"".attribut_html(_T('admin_recalculer')).$pop."\"></input>";
 	echo "</form>\n";
 
 	if (lire_meta("activer_statistiques") != "non" AND $id_article AND ($GLOBALS['auteur_session']['statut'] == '0minirezo')) {
@@ -64,6 +64,7 @@ function afficher_boutons_admin() {
 	echo "</div>";
 
 	lang_dselect();
+	
 }
 
 
diff --git a/inc-public-global.php3 b/inc-public-global.php3
index 45284fa9a9cd6e852121c30d148e9c2cdfd847fc..38d63ff8f1e04195633fcf5727e7b0710bf8787f 100644
--- a/inc-public-global.php3
+++ b/inc-public-global.php3
@@ -106,11 +106,6 @@ if ($ajout_forum) {
 	ajout_forum();
 }
 
-if ($xhtml){
-	include_ecrire('inc_tidy.php');
-	if (version_tidy() > 0) ob_start("xhtml");
-}
-
 if (!$use_cache) {
 	$lastmodified = time();
 	if (($lastmodified - lire_meta('date_purge_cache')) > 3600) {
@@ -155,6 +150,10 @@ if (!$use_cache) {
 		$page = calculer_page_globale($fond);
 		$timer_b = explode(" ", microtime());
 		if ($page) {
+			if ($xhtml) {
+				include_ecrire("inc_tidy.php");
+				$page = xhtml($page);
+			}
 			$timer = ceil(1000 * ($timer_b[0] + $timer_b[1] - $timer_a[0] - $timer_a[1]));
 			$taille = ceil(strlen($page) / 1024);
 			spip_log("calcul ($timer ms): $chemin_cache ($taille ko, delai: $delais s)");
@@ -202,11 +201,22 @@ else {
 $flag_preserver |= $headers_only;	// ne pas se fatiguer a envoyer des donnees
 if (!$flag_preserver) {
 	if ($xhtml) {
+		// Si Mozilla et tidy actif, passer en "application/xhtml+xml"
+		// extremement risque: Mozilla passe en mode debugueur strict
+		// mais permet d'afficher du MathML directement dans le texte
+		// (et sauf erreur, c'est la bonne facon de declarer du xhtml)
+		include_ecrire("inc_tidy.php");
 		verif_butineur();
-		if ($browser_name == "MSIE")
+		if (version_tidy() > 0) {		
+			if ($browser_name == "MSIE")
+				@Header("Content-Type: text/html; charset=".lire_meta('charset'));
+			else 
+				@Header("Content-Type: application/xhtml+xml; charset=".lire_meta('charset'));
+
+			echo '<'.'?xml version="1.0" encoding="'.lire_meta('charset').'"?'.">\n";
+		} else {
 			@Header("Content-Type: text/html; charset=".lire_meta('charset'));
-		else 
-			@Header("Content-Type: application/xhtml+xml; charset=".lire_meta('charset'));
+		}
 	} else {
 		@Header("Content-Type: text/html; charset=".lire_meta('charset'));
 	}
@@ -230,12 +240,6 @@ if ($var_recherche)
 	fin_surligne($var_recherche, $mode_surligne);
 
 
-if ($xhtml) {
-	include_ecrire('inc_tidy.php');
-	if (version_tidy() > 0)	ob_end_flush();
-}
-
-
 // nettoie
 if ($effacer_cache) @unlink($chemin_cache);
 while (list(, $chemin_cache_supprime) = each($cache_supprimes))