(La)TeX – Exemples / Solution retournée

Solution retournée

En cliquant sur l'image ci-dessous vous obtiendrez le fichier PDF dont elle est issue. Le code provient d'une discussion entre Christophe Poulain et Jean-Côme Charpentier sur la liste syracuse.

Cet exemple embarque une petite application de xlop: le calcul de l'un des côtés d'un triangle rectangle.

Le fichier xlopsqrt.tex utilisé ici pour l'extraction des racines carrées est à consulter à la suite de l'exemple.

fichesolinverse.tex [ retoursource ]

Conversion au format PDF de fichesolinverse.tex
%@Auteur: Christophe Poulain 
%@Date: 23 mai 2006 
\documentclass[12pt,a4paper]{article} 
\usepackage[latin1]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage[frenchb]{babel} 
\usepackage{fourier} 
\parindent0pt 
\usepackage[dvips,margin=1.5cm]{geometry} 
\usepackage{graphicx} 
\usepackage{calc} 
\usepackage{multicol} 
\usepackage{xlop} 
\usepackage{ifthen} 
\newsavebox\zouliboite 
 
\newenvironment{Solution} 
    { 
     \begin{lrbox}{\zouliboite} 
     \begin{minipage}{\linewidth-2\fboxsep-2\fboxrule} 
     \hbox to5cm{\hrulefill}\par 
     {\bf{\em Solution de l'exercice}}\par 
    } 
    { 
     \par\hbox to5cm{\hrulefill} 
     \end{minipage}% 
     \end{lrbox} 
     \par\noindent % c'est plus sûr 
     %\fbox{ 
     \rotatebox{180}{\usebox{\zouliboite}}%} 
    } 
 
\newboolean{exact} 
\setboolean{exact}{true} 
\input{xlopsqrt} 
 
%% mise en scène d'un calcul 
\newcommand{\pythadroit}[5]{ 
    \opset{decimalsepsymbol={,}} 
    \opcopy{#4}{A1} 
    \opcopy{#5}{A2} 
    Dans le triangle $#1#2#3$ rectangle en $#2$, le théorème de 
    Pythagore permet d'écrire: 
    \begin{eqnarray*} 
 #1#3^2&=#1#2^2+#2#3^2\% 
 \opprint{A1}^2&=#1#2^2+\opprint{A2}^2\% 
 \opmul*{A1}{A1}{a1}\opprint{a1}&=#1#2^2+\opmul*{A2}{A2}{a2}\opprint{a2}\% 
 #1#2^2&=\opmul*{A1}{A1}{a1}\opprint{a1}-\opmul*{A2}{A2}{a2}\opprint{a2}\% 
 #1#2^2&=\opsub*{a1}{a2}{a3}\opprint{a3}\% 
 #1#2&=\sqrt{\opprint{a3}}\% 
 \ifthenelse{\boolean{exact}}% 
  {#1#2&=\opsqrt[maxdivstep=3]{a3}{a4}\opunzero{a4}\opprint{a4}}% 
  {#1#2&\approx\opsqrt[maxdivstep=3]{a3}{a4}\opround{a4}{2}{a4}\opunzero{a4}\opprint{a4}} 
    \end{eqnarray*} 
    } 
 
 
\pagestyle{empty} 
 
\begin{document} 
\textbf{Exercice} ---  Sur un cercle de centre $O$ et de diamètre $[AB]$ tel que $AB=10$~cm, 
place un point $C$ tel que l'angle $\widehat{ABC}=50\degres$. 
\begin{enumerate} 
\item Montre que le triangle $ABC$ est rectangle. 
\item Calcule les longueurs $BC$ et $AC$. (On donnera les valeurs 
arrondies au millimètre.) 
\end{enumerate} 
\begin{Solution} 
    \begin{enumerate} 
 \item Comme $C$ appartient au cercle de diamètre $[AB]$ alors le 
 triangle $ABC$ est rectangle en $C$. 
 \item 
     \begin{multicols}{2} 
      Dans le triangle $ABC$ rectangle en $C$, on a : 
  \begin{eqnarray*} 
      \cos\widehat{ABC}&=\frac{BC}{AB}\% 
      \cos50&=\frac{BC}{10}\% 
      BC&=10\times\cos50\% 
      BC&\approx6,4~\mbox{cm} 
  \end{eqnarray*} 
  \par\columnbreak\setboolean{exact}{false}\pythadroit ACB{10}{6,4} 
     \end{multicols} 
    \end{enumerate} 
\end{Solution} 
\end{document} 
 

xlopsqrt.tex [ retoursource ]

\makeatletter 
\op@split{0}{@zero} 
\op@split{1}{@one} 
\op@split{2}{@two} 
\op@split{3}{@three} 
\op@split{4}{@four} 
\op@split{5}{@five} 
\op@split{6}{@six} 
\op@split{7}{@seven} 
\op@split{8}{@height} 
\op@split{9}{@nine} 
\op@split{10}{@ten} 
 
\newcommand \opsqrt[3][nil] 
{% 
  \begingroup 
  \opset{#1}% 
  \opcmp{0}{#2}% 
  \ifopeq 
    \op@copy{@zero}{U}% 
    \let\op@savemaxdivstep\op@maxdivstep 
  \else 
    \op@split{#2}{z}% 
    \count@=\OP@z@i 
    \divide\count@ by2 
    \edef\op@savemaxdivstep{\op@maxdivstep}% 
    \count@i=\op@maxdivstep 
    \advance\count@i by\count@ 
    \advance\count@i by1 
    \edef\op@maxdivstep{\the\count@i}% 
    \ifodd\OP@z@i 
      \xdef\op@initsqrt{\@nameuse{OP@z@\OP@z@w}}% 
    \else 
      \count@=\OP@z@w 
      \xdef\op@initsqrt{\@nameuse{OP@z@\the\count@}}% 
      \advance\count@ by-1 
      \xdef\op@initsqrt{\op@initsqrt\@nameuse{OP@z@\the\count@}}% 
    \fi 
    \ifnum\op@initsqrt<1 
      \op@copy{@zero}{u}% 
    \else\ifnum\op@initsqrt<3 
      \op@copy{@one}{u}% 
    \else\ifnum\op@initsqrt<7 
      \op@copy{@two}{u}% 
    \else\ifnum\op@initsqrt<13 
      \op@copy{@three}{u}% 
    \else\ifnum\op@initsqrt<21 
      \op@copy{@four}{u}% 
    \else\ifnum\op@initsqrt<31 
      \op@copy{@five}{u}% 
    \else\ifnum\op@initsqrt<43 
      \op@copy{@six}{u}% 
    \else\ifnum\op@initsqrt<57 
      \op@copy{@seven}{u}% 
    \else\ifnum\op@initsqrt<73 
      \op@copy{@height}{u}% 
    \else\ifnum\op@initsqrt<91 
      \op@copy{@nine}{u}% 
    \else 
      \op@copy{@ten}{u}% 
    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi 
    \count@ii=\OP@z@i 
    \advance\count@ii by1 
    \divide\count@ii by2 
    \advance\count@ii by-1 
    \op@lshift{\the\count@ii}{u}% 
    \count@=\OP@z@w 
    \advance\count@ by1 
    \edef\op@@maxdivstep{\op@maxdivstep}% 
    \loop 
      \op@mul{u}{u}{U}% 
      \op@add{U}{z}{U}% 
      \op@mul{u}{@two}{D}% 
      \edef\op@maxdivstep{\the\count@}% 
      \op@div{0}{U}{D}{U}{r}% 
      \multiply\count@ by2 
      \ifnum\count@>\op@@maxdivstep 
        \count@=\op@@maxdivstep 
      \fi 
      \op@cmp{u}{U}% 
    \ifopneq 
      \op@copy{U}{u}% 
    \repeat 
  \fi 
  \op@unsplit{U}{#3}% 
  \opround{#3}{\op@savemaxdivstep}{#3}% 
  \endgroup 
} 
 
\newcommand \opgfsqrt[2][nil]{% 
  \begingroup 
  \edef\op@saveparindent{\the\parindent}% 
  \parindent=0pt 
  \opset{#1}% 
  \op@split{#2}{sq}% 
  \opsqrt{#2}{@sqrt}% 
  \op@split{@sqrt}{sqrt}% 
  \op@split{\op@initsqrt}{init}% 
  \count@=\OP@sqrt@w 
  \op@split{\@nameuse{OP@sqrt@\the\count@}}{atosub}% 
  \op@mul{atosub}{atosub}{tosub}% 
  \setbox1=\hbox{\kern\opcolumnwidth 
    \op@display{operandstyle.1}{sq}}% 
  \setbox2=\vtop{% 
    \hbox{\ophline(-0.5,-0.25){\OP@sqrt@w.5}% 
      \op@display{resultstyle}{sqrt}}% 
    \hbox{\op@display{intermediarystyle.1}{atosub}% 
      \hbox to\opcolumnwidth{\hss\op@mulsymbol\hss}% 
      \op@display{intermediarystyle.1}{atosub}% 
      \hbox to\opcolumnwidth{\hss\op@equalsymbol\hss}% 
      \op@display{operandstyle.2}{tosub}}% 
  } 
  \op@sub{init}{tosub}{rest}% 
  \count@ii=\OP@init@w 
  \count@iii=\count@ii 
  \advance\count@iii by1 
  \setbox1=\hbox{\hsize=\count@iii\opcolumnwidth\vtop{% 
      \box1 
      \hbox{% 
        \op@makebox{\the\count@iii}{0}% 
        {operandstyle.2}{tosub}% 
        \box0}}}% 
  \op@unzero{rest}% 
  \op@copy{@zero}{cursqrt}% 
  \op@copy{@zero}{digitmul}% 
  \count@i=\OP@sq@w 
  \advance\count@i by-\OP@init@w 
  \count@iv=2 
  \loop 
  \ifnum\count@>1 
    \op@lshift{2}{rest}% 
    \ifnum\count@i>0 % here! 
      \@namexdef{OP@rest@2}{\@nameuse{OP@sq@\the\count@i}}% 
      \advance\count@i by-1 
      \ifnum\count@i>0 % here! 
        \@namexdef{OP@rest@1}{\@nameuse{OP@sq@\the\count@i}}% 
        \advance\count@i by-1 
      \fi 
    \fi 
    \count@ii=\count@iii 
    \advance\count@ii by-\OP@tosub@w 
    \advance\count@ii by-1 
    \advance\count@iii by2 
    \setbox1=\hbox{\hsize=\count@iii\opcolumnwidth 
      \vtop{% 
        \hbox{\box1}% 
        \hbox{% 
          \oplput(\count@ii,0.75){\ophline(0,0){1}}% 
          \oplput(\count@ii,0.75){\ophline(1,0){\OP@tosub@w}}% 
          \advance\count@iv by-1 
          \op@makebox{\the\count@iii}{0}% 
          {remainderstyle.\the\count@iv}{rest}% 
          \advance\count@iv by1 
          \oplput(\count@ii,1.5){$-$}% 
          \box0}% 
      }}% 
    \op@multen{cursqrt}% 
    \@namexdef{OP@cursqrt@1}% 
    {\@nameuse{OP@sqrt@\the\count@}}% 
    \advance\count@ by-1 
    \op@mul{cursqrt}{@two}{atosub}% 
    \op@unzero{atosub}% 
    \op@multen{atosub}% 
    \@namexdef{OP@atosub@1}% 
    {\@nameuse{OP@sqrt@\the\count@}}% 
    \@namexdef{OP@digitmul@1}% 
    {\@nameuse{OP@sqrt@\the\count@}}% 
    \op@mul{atosub}{digitmul}{tosub}% 
    \op@unzero{tosub}% 
    \setbox2=\hbox{\vtop{% 
        \hbox{\box2}% 
        \hbox{\vrule width0pt height0pt 
          depth\oplineheight}% 
        \hbox{% 
          \op@display 
          {intermediarystyle.\the\count@iv}{atosub}% 
          \hbox to\opcolumnwidth{\hss\op@mulsymbol\hss}% 
          \op@display 
          {intermediarystyle.\the\count@iv}{digitmul}% 
          \hbox to\opcolumnwidth{\hss\op@equalsymbol\hss}% 
          \advance\count@iv by1 
          \op@display{operandstyle.\the\count@iv}{tosub}% 
        }% 
      }}% 
    \op@sub{rest}{tosub}{rest}% 
    \op@unzero{rest}% 
    \advance\count@iv by1 
    \setbox1=\hbox{\hsize=\count@iii\opcolumnwidth 
      \vtop{% 
        \hbox{\box1}% 
        \hbox{% 
          \op@makebox{\the\count@iii}{0}% 
          {operandstyle.\the\count@iv}{tosub}% 
          \box0}}}% 
    \repeat 
    \count@ii=\count@iii 
    \advance\count@ii by-\OP@tosub@w 
    \advance\count@ii by-1 
    \setbox1=\hbox{\hsize=\count@iii\opcolumnwidth 
      \vtop{% 
        \hbox{\box1}% 
        \hbox{% 
          \oplput(\count@ii,0.75){% 
            \ophline(0,0){1}}% 
          \oplput(\count@ii,0.75){% 
            \ophline(1,0){\OP@tosub@w}}% 
          \op@makebox{\the\count@iii}{0}% 
          {remainderstyle.\the\count@iv}{rest}% 
          \oplput(\count@ii,1.5){$-$}% 
          \box0}% 
      }% 
    }% 
    \parindent=\op@saveparindent 
    \leavevmode\hbox{% 
      \box1 
      \kern0.5\opcolumnwidth 
      \vrule 
      \kern0.5\opcolumnwidth 
      \box2}% 
    \endgroup 
  } 
  \makeatother

 

Validation CSS Validation XHTMLJean-Michel Sarlat — Dernière modification : 24 mai 2006 (0.06s - 3818501 - lundi 1 décembre 2008) vers le haut