Wikini

ActionLatexHTML

PagePrincipale :: DerniersChangements :: DerniersCommentaires :: ParametresUtilisateur :: Vous êtes ec2-18-191-195-110.us-east-2.compute.amazonaws.com
  FormulesTeXDansWikini
  • >>


Action Latex HTML


1/ Description :


Nom de la contribution : ActionLatexHTML
Description : Permet aux utilisateurs d'afficher des formule mathematique
Type de contribution : Action
Fonctionne avec : WikiNi 0.4.3
Intégration technique : placez le code dans './actions'
Mainteneur : GulP?
Licence : GPL
Dernière version : 0.0.1(beta)
Dernière livraison : 23/12/2004
Accès au code et mise en oeuvre :
Démonstration : http://gu.ziro.free.fr/wikini/wakka.php?wiki=BacASable
Intégration au projet WikiNi :

Bugs de l'action Latex HTML :


2/ Présentation :




3/ Syntaxe et mode d'emploi


La syntaxe et le mode d'emploi sont précisés et très bien détaillés dans la page de notre wiki à la page : ActionMath

Voici un bref récapitulatif de la syntaxe mis en place :


A venir : flèches, limites, matrices, accolades,

Pour tester l'action, vous pouvez aller dans notre .


4/ Le code de l'action ( première version 0.0.1 ) :


A titre indicatif, ( code brute ) le code ci-dessous n'est là que pour montrer la structure de l'action attention il n'y a pas de commentaires.
ceci est mon premier scripte il ne faut donc pas chercher de coherence


<?php


//########fonction_Math##########


$mathtex '' ;

    if(!
function_exists("lit_analyse_cmd"))
        {
        include (
$_SERVER['DOCUMENT_ROOT'].'/wikini/math_fonction.php');
        }
    
// Contrôle pour être sûr que l'action est bien appelée par WikiNi
if (!defined("WIKINI_VERSION"))
{
  die (
"accès direct interdit");
}
else
{
    
/* Récupération des paramètres et initialisation des variables globals*/
    
$chaine $this->GetParameter("latex");

    
$compt 0;//compteur dans le nombre total des charactaires de la chaine
    
$longueur strlen($chaine);
    
    if (!
$this->GetParameter("latex"))
    {
            echo 
$this->Format("//Les param&ecirc;tres sont manquant.//");
    }

// script de l'action math

// Sinon on execute le code tex
    
else
    {
            
        while(
$compt+<= $longueur)
        {
            
            
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<td>';
            
$compt $compt lit_analyse_cmd(substr($chaine$compt, (strlen($chaine) - $compt)));
            
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td>';
        }
    
$mathtexf ='<table><tr>'$GLOBALS['mathtex'] . '</tr></table>';    
    echo(
"${mathtexf}");
    
$GLOBALS['mathtex'] = "";
}
}
//{{math latex="e^i"}}
//{{math latex="e^{ipi}"}}
//{{math latex="e^{ipi}_h"}}
//{{math latex="\int_i^j f"}}
//{{math latex="\sum_0^N {\int_i^j f}"}}
//echo"cool";
?>

<?php
//fonctions de l'action math



function structure_integral($nom$bas$haut$millieu)
{    
    
    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<table style="vertical-align : middle;"><tr><td rowspan="3" >';
    switch (
$nom)
    {
    case 
'int' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/integrale.png" alt="integrale"  />';
    break;
    case 
'iint' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/integrale2.png" alt="integrale2"  />';
    break;
    case 
'iiint' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/integrale3.png" alt="integrale3"  />';
    break;
    case 
'iiiint' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/integrale4.png" alt="integrale4"  />';
    break;
    case 
'oint' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/integralecurvi.png" alt="integralecurviligne"  />';
    break;
    case 
'oiint' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/integralecurvi2.png" alt="integralecurvi2"  />';
    break;
    default:
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/integrale.png" alt="integrale"  />';
        
    }
    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td><td>';
    
lit_analyse_cmd($haut);
    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td><td></td></tr><tr><td></td><td>';
    
lit_analyse_cmd($millieu);
    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td></tr><tr><td>';
    
lit_analyse_cmd($bas);
    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td><td></td></tr></table>';
}


function 
structure_somme($nom$bas$haut$millieu)
{

    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<table style="vertical-align : middle;"><tr><td>';
    
lit_analyse_cmd($haut);
    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td><td></td></tr><tr><td>';
    switch (
$nom)
    {
    case 
'sum':
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/somme.png" alt="somme"   />';
    break;
    case 
'prod':
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/produit.png" alt="produit"   />';
    break;
    case 
'coprod':
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/produit2.png" alt="produit des inverses"  />';
    break;
    case 
'bigcup' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/union.png" alt="union"   />';
    break;
    case 
'bigcap' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/intersection.png" alt="intersection"  />';
    break;
    case 
'bigsqcup' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/bigsqcup.png" alt="intersection"  />';
    break;
    case 
'bigvee' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/bigvee.png" alt="intersection"  />';
    break;
    case 
'bigwedge' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/prodvectoriel.png" alt="Produit vectoriel"  />';
    break;
    case 
'bigoplus' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/sommedirect.png" alt="somme direct"  />';
    break;
    case 
'bigotimes' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/proddirect.png" alt="produit direct"  />';
    break;
    case 
'bigodot' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/operadirect.png" alt="rond point"  />';
    break;
    case 
'biguplus' :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/unionsomme.png" alt="somme union"  />';
    break;
    default :
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<img src="./images_math/somme.png" alt="somme"  />';
        
    }
    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td><td>';
    
lit_analyse_cmd($millieu);
    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td></tr><tr><td>';
    
lit_analyse_cmd($bas);
    
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td><td></td></tr></table>';
}

function 
structure_acolade($nom,$para_millieu$para)
{
    
    if(
$nom == 'overbrace')
        {
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<table style="vertical-align : middle;"><tr><td>';
        
lit_analyse_cmd($para);
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td></tr><tr><td  ><img src="./images_math/overbrace.png" alt="accolade haut" />';
        
lit_analyse_cmd($para_millieu);
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td></tr></table>';
        }
    elseif(
$nom == 'underbrace')
        {
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<table style="vertical-align : middle;"><tr><td>';
        
lit_analyse_cmd($para_millieu);
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td></tr><tr><td  ><img src="./images_math/underbrace.png" alt="accolade bas" />';
        
lit_analyse_cmd($para);
        
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td></tr></table>';
        }
    else
        {}
}

    
function 
structure_fraction($bas$haut)    
{

$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<table style="vertical-align : middle;"><tr><td>';
lit_analyse_cmd($haut);
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td></tr><tr><td  ><img src="./images_math/fraction.png" alt="fraction" />';
lit_analyse_cmd($bas);
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</td></tr></table>';
}


function 
recupere_block($chaine_block$compte)
{
    
$debut $compte 1;
    
$para;
    
    if (
$chaine_block[$compte] != '{')//pas d'accolade bloc = 1 caractère
    
{
        
    return(
$chaine_block[$compte]);
    }
    else
//recupere le bloc entre accolades
    
{    
        
$ok false
        
$compte ++ ;
        
$nomb ;
        while (
$ok != true)//permet de prendre tout le bloc meme si }
        
{
            
            if (
$chaine_block[$compte] == '{')
                {
$nomb++;}
            elseif(
$chaine_block[$compte] == '}')
                {
$nomb--;}
            if (
$nomb == 0)
                {
$ok true ;}
            
            
$compte ++ ;    
        }
        
$para substr($chaine_block$debut$compte-$debut-1);
        
    }
    return 
$para ;
}




function 
lit_analyse_cmd($chaine_cmd)
{

$compte 0;//compteur dans le nombre total de charactaire ds le block cmd
$compte_para 0;
$nom;

$para_bas="";
$para_haut="";
$para_millieu="";
while (
$compte <= strlen($chaine_cmd))
{
    
    if(
$chaine_cmd[$compte] != "\\")//écris jusqu'a une cmd
    
{
        
        if(
$chaine_cmd[$compte] == '^')//crée les block d'indice 
            
{
            
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<sup>';
            
$compte ++ ;
            
$bloc recupere_block($chaine_cmd$compte);
            
lit_analyse_cmd($bloc);
                if(
strlen($bloc) >= 2)
                {
$compte = ($compte strlen($bloc) + 2);}
                else
                {
$compte = ($compte strlen($bloc));} 
            
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</sup>';
            
            }
        elseif(
$chaine_cmd[$compte] == '_')//crée les block d'exposant
            
{
            
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '<sub>';
            
$compte ++ ;            
            
$bloc recupere_block($chaine_cmd$compte);
            
lit_analyse_cmd($bloc);
                if(
strlen($bloc) >= 2)
                {
$compte = ($compte strlen($bloc) + 2);}
                else
                {
$compte = ($compte strlen($bloc));} 
            
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . '</sub>';
            }
        else
//écris normalement
            
{
            if(
$chaine_cmd[$compte-1] == '}' && $chaine_cmd[$compte+1] == '}')
                {
$compte++;}
            else
                {
                
$GLOBALS['mathtex'] = $GLOBALS['mathtex'] . $chaine_cmd[$compte];
                
$compte++;
                }
            }
    
    }
    
    else
//gère les commandes
    
{
        if(
substr($GLOBALS['mathtex'], strlen($GLOBALS['mathtex'])-4) == '<td>')//permet de creer un bloc avant une commande pour l'alignementdu texte
        
{}
        else
        {
            
$j=1;
            while(
substr($GLOBALS['mathtex'], strlen($GLOBALS['mathtex'])-4-$j) != '<td>')
                {
                
$j++;
                }
            
$fin substr($GLOBALS['mathtex'], strlen($GLOBALS['mathtex'])-$j$j );
            
$debut substr($GLOBALS['mathtex'],,strlen($GLOBALS['mathtex'])-$j-1);
            
$GLOBALS['mathtex'] = $debut '<table style="vertical-align : middle;"><tr><td>' $fin '</td></tr></table></td><td>';
        }
        
        
    
$compte ++ ;
        while(
$chaine_cmd[$compte] != "_" && $chaine_cmd[$compte] != "^" && $chaine_cmd[$compte] != " " && $chaine_cmd[$compte] != "{")//identifie le nom de la comande
        
{
        
$compte_para ++ ;
        
$compte ++ ;
        }
        
    
$nom=substr($chaine_cmd, ($compte $compte_para), $compte_para);
    
    if(
$nom == 'sum' || $nom == 'prod' || $nom == 'coprod' || $nom == 'bigcap' || $nom == 'bigcup' || $nom == 'bigsqcup' || $nom == 'bigvee' || $nom == 'bigwedge' || $nom == 'bigoplus' || $nom == 'bigotimes' || $nom == 'bigodot' || $nom == 'biguplus')
    {
        for(
$i=;$i<=;$i ++)
        {
        if(
$chaine_cmd[$compte] == '_' )
            {
            
$compte ++ ;
            
$para_bas recupere_block($chaine_cmd$compte);
                if(
strlen($para_bas) <= 1)
                    {
$compte $compte strlen($para_bas);}
                else
                    {
$compte $compte strlen($para_bas) + ;}
            }
        elseif(
$chaine_cmd[$compte] == '^' )
            {
            
$compte ++ ;
            
$para_haut recupere_block($chaine_cmd$compte);
                if(
strlen($para_haut) <= 1)
                    {
$compte $compte strlen($para_haut);}
                else
                    {
$compte $compte strlen($para_haut) + 2;}
            }
        elseif(
$chaine_cmd[$compte] == ' ' )
            {
            
$compte ++ ;
            
$para_millieu recupere_block($chaine_cmd$compte);
                if(
strlen($para_millieu) <= 1)
                    {
$compte $compte strlen($para_millieu);}
                else
                    {
$compte $compte strlen($para_millieu) + 2;}
            }
        else
            {
/*echo"Les param&ecirc;tres sont manquant.";*/}
        }
            
        
structure_somme($nom$para_bas$para_haut$para_millieu) ;
    
    }
    elseif(
$nom == 'int' || $nom == 'iint' || $nom == 'iiint' || $nom == 'iiiint' || $nom == 'oint' || $nom == 'oiint')
    {
        for(
$i=;$i<=;$i ++)
        {
        if(
$chaine_cmd[$compte] == '_' )
            {
            
$compte ++ ;
            
$para_bas recupere_block($chaine_cmd$compte);
                if(
strlen($para_bas) <= 1)
                    {
$compte $compte strlen($para_bas);}
                else
                    {
$compte $compte strlen($para_bas) + ;}
            }
        elseif(
$chaine_cmd[$compte] == '^' )
            {
            
$compte ++ ;
            
$para_haut recupere_block($chaine_cmd$compte);
                if(
strlen($para_haut) <= 1)
                    {
$compte $compte strlen($para_haut);}
                else
                    {
$compte $compte strlen($para_haut) + 2;}
            }
        elseif(
$chaine_cmd[$compte] == ' ' )
            {
            
$compte ++ ;
            
$para_millieu recupere_block($chaine_cmd$compte);
                if(
strlen($para_millieu) <= 1)
                    {
$compte $compte strlen($para_millieu);}
                else
                    {
$compte $compte strlen($para_millieu) + 2;}
            }
        else
            {
/*echo"Les param&ecirc;tres sont manquant.";*/}
        }
            
        
structure_integral($nom$para_bas$para_haut$para_millieu) ;
    
    }
    elseif(
$nom == 'frac')
    {
        
        if(
$chaine_cmd[$compte] == ' ' )
                {
                
$compte ++ ;
                
$para_haut recupere_block($chaine_cmd$compte);
                    if(
strlen($para_haut) <= 1)
                        {
$compte $compte strlen($para_haut);}
                    else
                        {
$compte $compte strlen($para_haut) + 2;}
                }
        if(
$chaine_cmd[$compte] == ' ' )
                {
                
$compte ++ ;
                
$para_bas recupere_block($chaine_cmd$compte);
                    if(
strlen($para_bas) <= 1)
                        {
$compte $compte strlen($para_bas);}
                    else
                        {
$compte $compte strlen($para_bas) + 2;}
                }
        
        
structure_fraction($para_bas$para_haut);
    
    }
    elseif(
$nom == 'underbrace' || $nom == 'overbrace' )
    {
        if(
$chaine_cmd[$compte] == '{' )
            {
                
$para_millieu recupere_block($chaine_cmd$compte);
                if(
strlen($para_millieu) <= 1)
                    {
$compte $compte strlen($para_millieu);}
                else
                    {
$compte $compte strlen($para_millieu) + 2;}
            }
        if(
$chaine_cmd[$compte] == '_' || $chaine_cmd[$compte] == '^')
            {
                
$compte ++;
                
$para_bas recupere_block($chaine_cmd$compte);
                if(
strlen($para_bas) <= 1)
                    {
$compte $compte strlen($para_bas);}
                else
                    {
$compte $compte strlen($para_bas) + 2;}
            }
            
        
structure_acolade($nom,$para_millieu$para_bas);
        
    }
    
    else
    {
    echo
"//La cmd est non definie.//";
    }
    return(
$compte);
}
}
return(
$compte-1);

}
?>



Vos commentaires :

Il vaudrait mieux faire un formatter et utiliser $...$ ou $$...$$
ça serait nettement plus simple d'utilisation qu'une action...
et en plus il n'y aurait pas de risque avec les accolades (à la fois dans le code LaTeX et dans la définition de l'action).
-- SebCls?

C'est vrai que c'est entre balise $ qu'en plus est utilisé le Latex dans des sites comme mathematiques.net
L'utilisation serait plus simple et peut être qu'il faudrait travailler dessus. Mais avant de faire quelque modification que ce soit, je pense qu'il vaudrait mieux terminer l'action ( qui ne fait pas encre tableaux et matrices ), et résoudre ses derniers bugs. Toutefois c'est peut-être une solution à retenir pour l'avenir.
-- OrpheeWiki

L'action est omni présente maintenant sur Gu Wiki Ziro est il n'y a pas de bug notoir à signaler. Certaines pages sont surchargé de cette fonction et cela tourne sans aucun problème. ;)



Par : OrpheeWiki GulP?

voir aussi : ListeActions
Commentaires [Cacher commentaires/formulaire]