\documentclass[12pt]{article}
\usepackage[height=250mm,width=183mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[upright]{fourier}
\usepackage{amsmath}
\usepackage{colortbl}
\usepackage{fancyvrb}

% On écrit la fonction XCAS qui construit la table

\begin{VerbatimOut}{XCAStablenorm.cxx}
tablenormale(L):={
local pp,pd,j,k,t,T,u,Ti,Tbis,TT,XCAStablenormx,m,s,x;
m:=L[0];s:=L[1];x:=L[2];
tt:=evalf((x-m)/s);
if(tt<0){tp:=-tt}else{tp:=tt};

pp:=trunc(10*(tp));
pd:=round((tp-pp/10)*100);
// on fixe le nombre de chiffres après la virgule, ici 5
DIGITS:=5;
pd:=pd+1;
pp:=pp+1;

T:=[[0,seq(0.00+k*0.01,k=0..9)],seq([0.0+j*0.1,seq(evalf(normal_cdf(j*0.1+m*0.01)),m=0..9)],j=0..29)];
u:=seq("c|",k=0..10);
u[pd]:=">{\\columncolor[gray]{0.7}}c|";
Ti:="";
for(k:=0;k<size(u);k++){Ti:=Ti+u[k]};
 Tbis:=[seq([seq(10,j=0..ncols(T)-1)],nrows(T)-1)];
 Tbis:=for(k:=0;k<nrows(T);k++){Tbis[k]:=[seq(string(T[k,j])+"&",j=0..ncols(T)-2),string(T[k,ncols(T)-1])+if(k
          mod 10 ==0){"\\\\\\hline"}else{" \\\\ "}]};
        Tbis[0]:=subsop(Tbis[0],0="t &");
        Tbis[pp]:=subsop(Tbis[pp],0="\\rowcolor[gray]{0.7}"+Tbis[pp,0]);
        TT:="
        \\setlength{\\parindent}{0pt}
        Voici le tableau donnant $\\Phi(t)=\\mathbb{P}(X<t)$ dans le cas $t\\in[0;2.99]$~:
        {\\small

        \\begin{center}";
        TT:=TT+"\\begin{tabular}{|"+Ti+"}\\hline ";
        for(k:=0;k<=nrows(Tbis)-1;k++){for(j:=0;j<=ncols(Tbis)-1;j++){TT:=TT+Tbis[k,j]}};
        XCAStablenormx:=TT+"\\end{tabular}"+"
        \\end{center}
        }
        \\bigskip

        On   veut   calculer    $\\mathbb{P}(X<"+x+")$   sachant   que   $X\\sim
        \\mathcal{N}("+m+","+s+")$.
        Comme la variable r\\'eduite $T=\\frac{X-"+m+"}{"+s+"}$ suit la loi $\\mathcal{N}(0,1)$ alors $X<"+x+"$
        \\'equivaut \\`a $T<"+latex((x-m)/s)+"$.

        "+
        if(tt<0){"Comme "+tt+" est n\\'egatif, on utilise le fait que $\\Phi(-t)=1-\\Phi(t)$
        On lit dans la table de la loi normale
        $\\mathbb{P}(T<"+latex((x-m)/s)+")\\approx
        1-\\mathbb{P}(T<"+round((tp)*100)/100.0+")\\approx
        "+simplify(1-normal_cdf(round((tp)*100)/100.)) +"$"}
        else{
        "On lit dans la table de la loi normale
        $\\mathbb{P}(T<"+latex((x-m)/s)+")\\approx
        \\mathbb{P}(T<"+round((tp)*100)/100.0+")\\approx
         "+simplify(normal_cdf(round((tp)*100)/100.)) +"$."};

        return(XCAStablenormx);
        }:;
\end{VerbatimOut}


\begin{VerbatimOut}{XCAStablenorm.giac}
        maple_mode(0);
        read("XCAStablenorm.cxx");
        Sortie:=fopen("XCAStablenormex.tex");
        donnees:=read("XCAStablenorm.user");
        Resultat:=expr(cat(donnees));
        fprint(Sortie,Unquoted,Resultat);
        fclose(Sortie);
\end{VerbatimOut}



\newenvironment{XCAStablenorm}
{\VerbatimEnvironment\begin{VerbatimOut}{XCAStablenorm.user}}
{\end{VerbatimOut}
%% si GNU_LINUX ou MAC :
\immediate\write18{giac < XCAStablenorm.giac}
%% si WINDOWS :
% \immediate\write18{giac  XCAStablenorm.giac}
\input{XCAStablenormex}
}

\begin{document}

\begin{XCAStablenorm}
tablenormale([1,0.5,1.96])
\end{XCAStablenorm}

\end{document}
