La macro
\op@divarg
étant très monolithique (JC, si tu me lis, il faudrait peut-être penser à la scinder en sous-macros plus élémentaires), la redéfinir pour qu'elle admette un nouveau booléen
\ifdivfrac
conduit à un code long. Ce booléen sera
false
par défaut (comportement avec
\div
) alors que s'il est spécifié à
true
, la division s'affichera sous forme d'une fraction.
Du fait de la longueur de la macro
\op@divarg
, le code est long, mais très peu de modifications sont faites.
Code : Tout sélectionner
\documentclass{article}
\usepackage{xlop}
\newif\ifdivfrac
\divfracfalse
\makeatletter
\def\op@divarg[#1]#2#3{%
\begingroup
\opset{#1}%
\op@split{#2}{a}%
\op@split{#3}{b}%
% add 20/11/2006
% thanks to Christophe Poulain
\op@cmp{b}{zero}%
\ifopeq
\op@error{divisor must be nonzero}%
{You have to learn some math}%
\fi
% end add
\ifop@error
\op@errorwrite
\else
\ifx\op@style\op@string@display
\op@unzero{a}%
\op@unzero{b}%
\ifx\op@shiftdecimalsep\op@string@none
\xdef\OP@a@i{\OP@a@w}%
\xdef\OP@a@d{0}%
\xdef\OP@b@i{\OP@b@w}%
\xdef\OP@b@d{0}%
\else\ifx\op@shiftdecimalsep\op@string@divisor
\xdef\OP@a@i{\OP@a@w}%
\xdef\OP@a@d{0}%
\xdef\OP@b@i{\OP@b@w}%
\xdef\OP@b@d{0}%
\op@unzero{a}%
\op@unzero{b}%
\else
\edef\op@shift{\op@max{\OP@a@d}{\OP@b@d}}%
\op@mulpowerten{a}{\op@shift}%
\op@mulpowerten{b}{\op@shift}%
\fi\fi
\fi
\ifop@period
\op@div{1}{a}{b}{q}{r}%
\else
\op@div{0}{a}{b}{q}{r}%
\fi
\ifx\op@style\op@string@display
\op@split{#2}{a}%
\op@split{#3}{b}%
\op@copy{q}{qq}%
\op@unzero{a}%
\op@unzero{b}%
\ifx\op@shiftdecimalsep\op@string@none
\def\op@shift{0}%
\op@count@v=\OP@a@d
\advance\op@count@v by-\OP@b@d\relax
\ifnum\op@count@v>0
\op@divpowerten{qq}{\the\op@count@v}%
\else
\op@count@v=-\op@count@v
\op@mulpowerten{qq}{\the\op@count@v}%
\fi
\else\ifx\op@shiftdecimalsep\op@string@divisor
\edef\op@shift{\OP@a@d}%
\op@count@v=\OP@a@d
\advance\op@count@v by-\OP@b@d\relax
\ifnum\op@count@v>0
\op@divpowerten{qq}{\the\op@count@v}%
\else
\op@count@v=-\op@count@v
\op@mulpowerten{qq}{\the\op@count@v}%
\fi
\edef\op@shift{\OP@b@d}%
\op@split{#2}{a}%
\ifx\op@strikedecimalsepsymbol\empty
\op@unzero{a}%
\else
\op@count@z=\OP@a@w
\fi
\op@mulpowerten{a}{\OP@b@d}%
\ifx\op@strikedecimalsepsymbol\empty\else
\advance\op@count@z by-\OP@a@d
\op@format{\the\op@count@z}{\OP@a@d}{a}%
\fi
\xdef\OP@b@i{\OP@b@w}%
\xdef\OP@b@d{0}%
\ifx\op@strikedecimalsepsymbol\empty
\op@unzero{b}%
\fi
\else
\edef\op@shift{\op@max{\OP@a@d}{\OP@b@d}}%
\ifx\op@strikedecimalsepsymbol\empty
\op@unzero{a}%
\op@unzero{b}%
\else
\op@count@z=\OP@a@w
\op@count@i=\OP@b@w
\fi
\op@mulpowerten{a}{\op@shift}%
\op@mulpowerten{b}{\op@shift}%
\ifx\op@strikedecimalsepsymbol\empty\else
\advance\op@count@z by-\OP@a@d
\op@format{\the\op@count@z}{\OP@a@d}{a}%
\advance\op@count@i by-\OP@b@d
\op@format{\the\op@count@i}{\OP@b@d}{b}%
\fi
\fi\fi
\ifx\op@country\op@string@french
\op@divdisplayone
\else \ifx\op@country\op@string@american
\op@divdisplayone
\else \ifx\op@country\op@string@russian
\op@divdisplayone
\else
\op@error{Country \op@country\space isn't recognize}
{For now, only `french', `american' and
`russian' are valid}%
\fi\fi\fi
\else
\ifnum\OP@a@s=\OP@b@s\else
\xdef\OP@q@s{1}%
\fi
\mathsurround=\z@\relax
\ifop@deletezero
\op@unzero{a}%
\op@unzero{b}%
\op@unzero{q}%
\fi
\op@unsplit{a}{@a}%
\op@unsplit{b}{@b}%
\op@unsplit{q}{@q}%
\ifdivfrac
$\displaystyle\frac\Op@@a\Op@@b$%
\else
\ifnum\OP@a@s=1\relax
\ifx\op@parenthesisnegative\op@string@all
$(\Op@@a)$%
\else
$\Op@@a$%
\fi
\else
$\Op@@a$%
\fi
$\>$\nobreak\op@divsymbol$\>$\penalty\binoppenalty
\ifnum\OP@b@s=1\relax
\ifx\op@parenthesisnegative\op@string@all
$(\Op@@b)$%
\else \ifx\op@parenthesisnegative\op@string@last
$(\Op@@b)$%
\else
$\Op@@b$%
\fi\fi
\else
$\Op@@b$%
\fi
\fi
\op@cmp{zero}{r}%
\ifopeq
$\;$\nobreak\op@equalsymbol$\;$\penalty\relpenalty
\setbox0=\hbox{\Op@@q}%
\else
\ifop@period
$\;$\nobreak\op@equalsymbol$\;$\penalty\relpenalty
\setbox0=\hbox{%
\Op@@q
\setbox1=\hbox{0}%
\begingroup
\opcolumnwidth=\wd1
\ophline(-\op@lengthperiod,\op@vruleperiod){\op@lengthperiod}%
\endgroup
\op@afterperiodsymbol
}%
\else
$\;$\nobreak\op@approxsymbol$\;$\penalty\relpenalty
\setbox0=\hbox{\Op@@q}%
\fi
\fi
\ifnum\OP@q@s=1\relax
\ifx\op@parenthesisnegative\op@string@all
$(\box0)$%
\else
$\box0$%
\fi
\else
$\box0$%
\fi
\fi
\fi
\endgroup
}
\makeatother
\begin{document}
\opdiv[period,style=text]{150}{7}% comportement par défaut
\divfractrue% afficher les divisions sou forme de fractions
\opdiv[period,style=text]{150}{7}
\end{document}
PS : vu la capture d'écran, il doit y avoir des espaces parasites quelque part dans le code de xlop, mais j'ai la flemme de chercher où.