diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/expl3/l3calc.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/expl3/l3calc.dtx | 305 |
1 files changed, 217 insertions, 88 deletions
diff --git a/Master/texmf-dist/source/latex/expl3/l3calc.dtx b/Master/texmf-dist/source/latex/expl3/l3calc.dtx index f00c2941940..842e68864c7 100644 --- a/Master/texmf-dist/source/latex/expl3/l3calc.dtx +++ b/Master/texmf-dist/source/latex/expl3/l3calc.dtx @@ -31,25 +31,21 @@ %% prior consultation with the LaTeX Project Team. %% %% ----------------------------------------------------------------------- -%<package>\RequirePackage{l3names} -%<*dtx> +%<*driver|package> +\RequirePackage{l3names} +%</driver|package> %\fi -\def\GetIdInfo$Id: #1.dtx #2 #3-#4-#5 #6 #7$#8{% - \def\fileversion{#2}% - \def\filedate{#3/#4/#5}% - \ProvidesFile{#1.dtx}[#3/#4/#5 v#2 #8]% -} -%\iffalse -%</dtx> -%\fi -\GetIdInfo$Id: l3calc.dtx 573 2006-08-21 20:59:37Z morten $ +\GetIdInfo$Id: l3calc.dtx 621 2007-09-01 20:14:19Z morten $ {L3 Experimental calc module} -% \iffalse +%\iffalse %<*driver> +%\fi +\ProvidesFile{\filename.\filenameext} + [\filedate\space v\fileversion\space\filedescription] +%\iffalse \documentclass{l3doc} - \begin{document} -\DocInput{l3calc.dtx} +\DocInput{\filename.\filenameext} \end{document} %</driver> % \fi @@ -70,14 +66,23 @@ % \begin{itemize} % \item The calc expression is expanded fully, which means there are % no problems with unfinished conditionals. However, the contents of -% |\widthof| etc.\ is not expanded at all. +% |\widthof| etc.\ is not expanded at all. This includes uses in +% traditional \LaTeX\ as in the \textsf{array} package, which tries +% to do an |\edef| several times. The code used in \textsf{l3calc} +% provides self-protection for these cases. % \item Muskip registers are supported although they can only be used % in |\ratio| if already evaluating a muskip expression. For the % other three register types, you can use points. % \item All results are rounded, not truncated. More precisely, the -% primitive \TeX\ operations |\divide| and |\multiply| are not used. +% primitive \TeX\ operations |\divide| and |\multiply| are not +% used. The only instance where one will observe an effect is when +% dividing integers. % \end{itemize} % +% This version of \textsf{l3calc} is a now a complete replacement for +% the original \textsf{calc} package providing the same functionality +% and will prevent the original \textsf{calc} package from loading. +% % \begin{function}{ % \calc_int_set:Nn | % \calc_int_gset:Nn | @@ -179,6 +184,8 @@ % We start by ensuring that the required packages are loaded. % \begin{macrocode} %<*package> +\ProvidesExplPackage + {\filename}{\filedate}{\fileversion}{\filedescription} \RequirePackage{l3int} \RequirePackage{l3skip} \RequirePackage{l3box} @@ -246,39 +253,41 @@ % % % -% \begin{macro}{\calc_assign_generic:NNNNNn} +% \begin{macro}{\calc_assign_generic:NNNNnn} % The generic function. |#1| is a number denoting which type we are % doing. (0=int, 1=dim, 2=skip, 3=muskip), |#2| = temp register A, % |#3| = temp register B, |#4| is a function acting on |#5| which is -% the register to be set. |#6| is the calc expression. This version -% relies on |\real| and |\ratio| having our definitions. +% the register to be set. |#6| is the calc expression. We do a +% little extra work so that |\real| and |\ratio| can still be used +% by the user. % \begin{macrocode} -\def_long_new:Npn \calc_assign_generic:NNNNNn#1#2#3#4#5#6{ - \let:NN\g_calc_A_register#2\let:NN\l_calc_B_register#3 +\def_long_new:Npn \calc_assign_generic:NNNNnn#1#2#3#4#5#6{ + \let:NN\g_calc_A_register#2 + \let:NN\l_calc_B_register#3 \int_set:Nn \l_calc_current_type_int {#1} - \tlp_set:Nx\l_calc_expression_tlp{#6} - \exp_after:NN\calc_open:w\exp_after:NN(\l_calc_expression_tlp! + \group_begin: + \let:NN \real \calc_real:n + \let:NN \ratio\calc_ratio:nn + \tlp_set:Nx\l_calc_expression_tlp{#6} + \exp_after:NN + \group_end: + \exp_after:NN\calc_open:w\exp_after:NN(\l_calc_expression_tlp ! \pref_global:D\g_calc_A_register\l_calc_B_register \group_end: - #4#5\l_calc_B_register + #4{#5}\l_calc_B_register } % \end{macrocode} -% One could lift these restrictions by defining |\calc_generic:NNNNNn| -% like this: +% A simpler version relying on |\real| and |\ratio| having our +% definition is % \begin{verbatim} -% \def_long_new:Npn \calc_assign_generic:NNNNNn#1#2#3#4#5#6{ +% \def_long_new:Npn \calc_assign_generic:NNNNnn#1#2#3#4#5#6{ % \let:NN\g_calc_A_register#2\let:NN\l_calc_B_register#3 % \int_set:Nn \l_calc_current_type_int {#1} -% \group_begin: -% \let:NN \real\calc_real:n -% \let:NN \ratio\calc_ratio:nn -% \tlp_set:Nx\l_calc_expression_tlp{#6} -% \exp_after:NN -% \group_end: -% \exp_after:NN\calc_open:w\exp_after:NN(\l_calc_expression_tlp! +% \tlp_set:Nx\l_calc_expression_tlp{#6} +% \exp_after:NN\calc_open:w\exp_after:NN(\l_calc_expression_tlp ! % \pref_global:D\g_calc_A_register\l_calc_B_register % \group_end: -% #4#5\l_calc_B_register +% #4{#5}\l_calc_B_register % } % \end{verbatim} % \end{macro} @@ -295,22 +304,22 @@ % types. First integer registers. % \begin{macrocode} \def_new:Npn\calc_int_set:Nn{ - \calc_assign_generic:NNNNNn\c_zero\g_calc_A_int\l_calc_B_int\int_set:Nn + \calc_assign_generic:NNNNnn\c_zero\g_calc_A_int\l_calc_B_int\int_set:Nn } \def_new:Npn\calc_int_gset:Nn{ - \calc_assign_generic:NNNNNn\c_zero\g_calc_A_int\l_calc_B_int\int_gset:Nn + \calc_assign_generic:NNNNnn\c_zero\g_calc_A_int\l_calc_B_int\int_gset:Nn } \def_new:Npn\calc_int_add:Nn{ - \calc_assign_generic:NNNNNn\c_zero\g_calc_A_int\l_calc_B_int\int_add:Nn + \calc_assign_generic:NNNNnn\c_zero\g_calc_A_int\l_calc_B_int\int_add:Nn } \def_new:Npn\calc_int_gadd:Nn{ - \calc_assign_generic:NNNNNn\c_zero\g_calc_A_int\l_calc_B_int\int_gadd:Nn + \calc_assign_generic:NNNNnn\c_zero\g_calc_A_int\l_calc_B_int\int_gadd:Nn } \def_new:Npn\calc_int_sub:Nn{ - \calc_assign_generic:NNNNNn\c_zero\g_calc_A_int\l_calc_B_int\int_sub:Nn + \calc_assign_generic:NNNNnn\c_zero\g_calc_A_int\l_calc_B_int\int_sub:Nn } \def_new:Npn\calc_int_gsub:Nn{ - \calc_assign_generic:NNNNNn\c_zero\g_calc_A_int\l_calc_B_int\int_gsub:Nn + \calc_assign_generic:NNNNnn\c_zero\g_calc_A_int\l_calc_B_int\int_gsub:Nn } % \end{macrocode} % \end{macro} @@ -329,22 +338,22 @@ % Dimens. % \begin{macrocode} \def_new:Npn\calc_dim_set:Nn{ - \calc_assign_generic:NNNNNn\c_one\g_calc_A_dim\l_calc_B_dim\dim_set:Nn + \calc_assign_generic:NNNNnn\c_one\g_calc_A_dim\l_calc_B_dim\dim_set:Nn } \def_new:Npn\calc_dim_gset:Nn{ - \calc_assign_generic:NNNNNn\c_one\g_calc_A_dim\l_calc_B_dim\dim_gset:Nn + \calc_assign_generic:NNNNnn\c_one\g_calc_A_dim\l_calc_B_dim\dim_gset:Nn } \def_new:Npn\calc_dim_add:Nn{ - \calc_assign_generic:NNNNNn\c_one\g_calc_A_dim\l_calc_B_dim\dim_add:Nn + \calc_assign_generic:NNNNnn\c_one\g_calc_A_dim\l_calc_B_dim\dim_add:Nn } \def_new:Npn\calc_dim_gadd:Nn{ - \calc_assign_generic:NNNNNn\c_one\g_calc_A_dim\l_calc_B_dim\dim_gadd:Nn + \calc_assign_generic:NNNNnn\c_one\g_calc_A_dim\l_calc_B_dim\dim_gadd:Nn } \def_new:Npn\calc_dim_sub:Nn{ - \calc_assign_generic:NNNNNn\c_one\g_calc_A_int\l_calc_B_int\dim_sub:Nn + \calc_assign_generic:NNNNnn\c_one\g_calc_A_int\l_calc_B_int\dim_sub:Nn } \def_new:Npn\calc_dim_gsub:Nn{ - \calc_assign_generic:NNNNNn\c_one\g_calc_A_int\l_calc_B_int\dim_gsub:Nn + \calc_assign_generic:NNNNnn\c_one\g_calc_A_int\l_calc_B_int\dim_gsub:Nn } % \end{macrocode} % \end{macro} @@ -363,22 +372,22 @@ % Skips. % \begin{macrocode} \def_new:Npn\calc_skip_set:Nn{ - \calc_assign_generic:NNNNNn\c_two\g_calc_A_dim\l_calc_B_dim\skip_set:Nn + \calc_assign_generic:NNNNnn\c_two\g_calc_A_skip\l_calc_B_skip\skip_set:Nn } \def_new:Npn\calc_skip_gset:Nn{ - \calc_assign_generic:NNNNNn\c_two\g_calc_A_dim\l_calc_B_dim\skip_gset:Nn + \calc_assign_generic:NNNNnn\c_two\g_calc_A_skip\l_calc_B_skip\skip_gset:Nn } \def_new:Npn\calc_skip_add:Nn{ - \calc_assign_generic:NNNNNn\c_two\g_calc_A_dim\l_calc_B_dim\skip_add:Nn + \calc_assign_generic:NNNNnn\c_two\g_calc_A_skip\l_calc_B_skip\skip_add:Nn } \def_new:Npn\calc_skip_gadd:Nn{ - \calc_assign_generic:NNNNNn\c_two\g_calc_A_dim\l_calc_B_dim\skip_gadd:Nn + \calc_assign_generic:NNNNnn\c_two\g_calc_A_skip\l_calc_B_skip\skip_gadd:Nn } \def_new:Npn\calc_skip_sub:Nn{ - \calc_assign_generic:NNNNNn\c_two\g_calc_A_dim\l_calc_B_dim\skip_sub:Nn + \calc_assign_generic:NNNNnn\c_two\g_calc_A_skip\l_calc_B_skip\skip_sub:Nn } \def_new:Npn\calc_skip_gsub:Nn{ - \calc_assign_generic:NNNNNn\c_two\g_calc_A_dim\l_calc_B_dim\skip_gsub:Nn + \calc_assign_generic:NNNNnn\c_two\g_calc_A_skip\l_calc_B_skip\skip_gsub:Nn } % \end{macrocode} % \end{macro} @@ -397,22 +406,28 @@ % Muskips. % \begin{macrocode} \def_new:Npn\calc_muskip_set:Nn{ - \calc_assign_generic:NNNNNn\c_three\g_calc_A_dim\l_calc_B_dim\muskip_set:Nn + \calc_assign_generic:NNNNnn\c_three\g_calc_A_muskip\l_calc_B_muskip + \muskip_set:Nn } \def_new:Npn\calc_muskip_gset:Nn{ - \calc_assign_generic:NNNNNn\c_three\g_calc_A_dim\l_calc_B_dim\muskip_gset:Nn + \calc_assign_generic:NNNNnn\c_three\g_calc_A_muskip\l_calc_B_muskip + \muskip_gset:Nn } \def_new:Npn\calc_muskip_add:Nn{ - \calc_assign_generic:NNNNNn\c_three\g_calc_A_dim\l_calc_B_dim\muskip_add:Nn + \calc_assign_generic:NNNNnn\c_three\g_calc_A_muskip\l_calc_B_muskip + \muskip_add:Nn } \def_new:Npn\calc_muskip_gadd:Nn{ - \calc_assign_generic:NNNNNn\c_three\g_calc_A_dim\l_calc_B_dim\muskip_gadd:Nn + \calc_assign_generic:NNNNnn\c_three\g_calc_A_muskip\l_calc_B_muskip + \muskip_gadd:Nn } \def_new:Npn\calc_muskip_sub:Nn{ - \calc_assign_generic:NNNNNn\c_three\g_calc_A_dim\l_calc_B_dim\muskip_add:Nn + \calc_assign_generic:NNNNnn\c_three\g_calc_A_muskip\l_calc_B_muskip + \muskip_add:Nn } \def_new:Npn\calc_muskip_gsub:Nn{ - \calc_assign_generic:NNNNNn\c_three\g_calc_A_dim\l_calc_B_dim\muskip_gadd:Nn + \calc_assign_generic:NNNNnn\c_three\g_calc_A_muskip\l_calc_B_muskip + \muskip_gadd:Nn } % \end{macrocode} % \end{macro} @@ -485,13 +500,16 @@ \if_meaning:NN#1*\let:NN\calc_next:w\calc_multiply:N \else: \if_meaning:NN#1/\let:NN\calc_next:w\calc_divide:N \else: \if_meaning:NN#1)\let:NN\calc_next:w\calc_close: \else: + \if_meaning:NN#1\scan_stop:\let:NN\calc_next:w\calc_post_scan:N + \else: % \end{macrocode} % If we get here, there is an error but let's also disable % |\calc_next:w| since it is otherwise undefined. No need to give % extra errors just for that. % \begin{macrocode} - \let:NN \calc_next:w \scan_stop: - \calc_error:N#1 + \let:NN \calc_next:w \use_noop: + \calc_error:N#1 + \fi: \fi: \fi: \fi: @@ -600,6 +618,7 @@ \group_begin: \let:NN\g_calc_A_register\g_calc_A_int \let:NN\l_calc_B_register\l_calc_B_int + \int_zero:N \l_calc_current_type_int \group_execute_after:N#1\calc_pre_scan:N } \def_new:Npn\calc_multiply_B_by_A:{ @@ -655,10 +674,10 @@ % \begin{macrocode} \def_protected_long:Npn \calc_textsize:Nn#1#2{ \group_begin: - \let:NN\widthof\box_wd:N - \let:NN\heightof\box_ht:N - \let:NN\depthof\box_dp:N - \def:Npn\totalheightof{\box_ht:N\box_dp:N} + \let:NN\calc_widthof_aux:n\box_wd:N + \let:NN\calc_heightof_aux:n\box_ht:N + \let:NN\calc_depthof_aux:n\box_dp:N + \def:Npn\calc_totalheightof_aux:n{\box_ht:N\box_dp:N} \exp_args:No\calc_calculate_box_size:nnn{#1} {\dim_gset:Nn\g_calc_A_register} % \end{macrocode} @@ -666,10 +685,10 @@ % call. % \begin{macrocode} { - \let:NN \depthof\calc_depthof:n - \let:NN \widthof\calc_widthof:n - \let:NN \heightof\calc_heightof:n - \let:NN \totalheightof\calc_totalheightof:n + \let:NN \calc_depthof_aux:n \calc_depthof_auxi:n + \let:NN \calc_widthof_aux:n \calc_widthof_auxi:n + \let:NN \calc_heightof_aux:n \calc_heightof_auxi:n + \let:NN \calc_totalheightof_aux:n \calc_totalheightof_auxi:n #2 } \group_end: @@ -845,8 +864,8 @@ \def_long_new:Npn \calc_minof:nn#1#2{ \calc_maxmin_operation:Nnn < \exp_not:n{{#1}{#2}} } -\let_new:NN \maxof \calc_maxof:nn -\let_new:NN \minof \calc_minof:nn +\let:NN \maxof \calc_maxof:nn +\let:NN \minof \calc_minof:nn % \end{macrocode} % \end{macro} % \end{macro} @@ -854,31 +873,47 @@ % \end{macro} % % \begin{macro}{\calc_widthof:n} +% \begin{macro}{\calc_widthof_aux:n} +% \begin{macro}{\calc_widthof_auxi:n} % \begin{macro}{\calc_heightof:n} +% \begin{macro}{\calc_heightof_aux:n} +% \begin{macro}{\calc_heightof_auxi:n} % \begin{macro}{\calc_depthof:n} +% \begin{macro}{\calc_depthof_aux:n} +% \begin{macro}{\calc_depthof_auxi:n} % \begin{macro}{\calc_totalheightof:n} -% \begin{macro}{\widthof} -% \begin{macro}{\heightof} -% \begin{macro}{\depthof} -% \begin{macro}{\totalheightof} +% \begin{macro}{\calc_totalheightof_aux:n} +% \begin{macro}{\calc_totalheightof_auxi:n} % Text dimension commands. % \begin{macrocode} \def_long_new:Npn \calc_widthof:n#1{ - \calc_textsize:Nn \exp_not:N\widthof\exp_not:n{{#1}} + \calc_textsize:Nn \exp_not:N\calc_widthof_aux:n\exp_not:n{{#1}} } \def_long_new:Npn \calc_heightof:n#1{ - \calc_textsize:Nn \exp_not:N\heightof\exp_not:n{{#1}} + \calc_textsize:Nn \exp_not:N\calc_heightof_aux:n\exp_not:n{{#1}} } \def_long_new:Npn \calc_depthof:n#1{ - \calc_textsize:Nn \exp_not:N\depthof\exp_not:n{{#1}} + \calc_textsize:Nn \exp_not:N\calc_depthof_aux:n\exp_not:n{{#1}} } \def_long_new:Npn \calc_totalheightof:n#1{ - \calc_textsize:Nn \exp_not:N\totalheightof\exp_not:n{{#1}} + \calc_textsize:Nn \exp_not:N\calc_totalheightof_aux:n \exp_not:n{{#1}} } -\let:NN \depthof\calc_depthof:n -\let:NN \widthof\calc_widthof:n -\let:NN \heightof\calc_heightof:n -\let:NN \totalheightof\calc_totalheightof:n +\def_long_new:Npn \calc_widthof_aux:n #1{ + \exp_not:N\calc_widthof_aux:n\exp_not:n{{#1}} +} +\let_new:NN \calc_widthof_auxi:n \calc_widthof_aux:n +\def_long_new:Npn \calc_depthof_aux:n #1{ + \exp_not:N\calc_depthof_aux:n\exp_not:n{{#1}} +} +\let_new:NN \calc_depthof_auxi:n \calc_depthof_aux:n +\def_long_new:Npn \calc_heightof_aux:n #1{ + \exp_not:N\calc_heightof_aux:n\exp_not:n{{#1}} +} +\let_new:NN \calc_heightof_auxi:n \calc_heightof_aux:n +\def_long_new:Npn \calc_totalheightof_aux:n #1{ + \exp_not:N\calc_totalheightof_aux:n\exp_not:n{{#1}} +} +\let_new:NN \calc_totalheightof_auxi:n \calc_totalheightof_aux:n % \end{macrocode} % \end{macro} % \end{macro} @@ -888,25 +923,119 @@ % \end{macro} % \end{macro} % \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} % % \begin{macro}{\calc_ratio:nn} % \begin{macro}{\calc_real:n} -% \begin{macro}{\ratio} -% \begin{macro}{\real} % Ratio and real. % \begin{macrocode} \def_long_new:Npn \calc_ratio:nn#1#2{ \calc_ratio_multiply:nn\exp_not:n{{#1}{#2}}} -\let_new:NN \calc_real:n \calc_real_evaluate:nn +\def_new:Npn \calc_real:n {\calc_real_evaluate:nn} % \end{macrocode} % We can implement real and ratio without actually using these % names. We'll see. % \begin{macrocode} -\let_new:NN \ratio\calc_ratio:nn -\let_new:NN \real\calc_real:n % \end{macrocode} % \end{macro} % \end{macro} +% +% \begin{macro}{\widthof} +% \begin{macro}{\heightof} +% \begin{macro}{\depthof} +% \begin{macro}{\totalheightof} +% \begin{macro}{\ratio} +% \begin{macro}{\real} +% User commands. +% \begin{macrocode} +\let:NN \depthof\calc_depthof:n +\let:NN \widthof\calc_widthof:n +\let:NN \heightof\calc_heightof:n +\let:NN \totalheightof\calc_totalheightof:n +%%\let:NN \ratio\calc_ratio:nn +%%\let:NN \real\calc_real:n +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\setlength} +% \begin{macro}{\gsetlength} +% \begin{macro}{\addtolength} +% \begin{macro}{\gaddtolength} +% \begin{macrocode} +\def_protected:Npn \setlength{\calc_skip_set:Nn} +\def_protected:Npn \gsetlength{\calc_skip_gset:Nn} +\def_protected:Npn \addtolength{\calc_skip_add:Nn} +\def_protected:Npn \gaddtolength{\calc_skip_gadd:Nn} +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\calc_setcounter:nn} +% \begin{macro}{\calc_addtocounter:nn} +% \begin{macro}{\calc_stepcounter:n} +% \begin{macro}{\setcounter} +% \begin{macro}{\addtocounter} +% \begin{macro}{\stepcounter} +% \begin{macro}{\calc_chk_document_counter:nn} +% Document commands for \LaTeXe\ counters. Also add support for +% \textsf{amstext}. Note that when \textsf{l3breqn} is used, +% |\mathchoice| will no longer need this switch as the argument is +% only executed once. +% \begin{macrocode} +\newif\iffirstchoice@ \firstchoice@true +\def_protected:Npn \calc_setcounter:nn#1#2{ + \calc_chk_document_counter:nn{#1}{ + \exp_args:Nc\calc_int_gset:Nn {c@#1}{#2} + } +} +\def_protected:Npn \calc_addtocounter:nn#1#2{ + \iffirstchoice@ + \calc_chk_document_counter:nn{#1}{ + \exp_args:Nc\calc_int_gadd:Nn {c@#1}{#2} + } + \fi: +} +\def_protected:Npn \calc_stepcounter:n#1{ + \iffirstchoice@ + \calc_chk_document_counter:nn{#1}{ + \int_gincr:c {c@#1} + \group_begin: + \let:NN \@elt\@stpelt \cs_use:c{cl@#1} + \group_end: + } + \fi: +} +\def_new:Npn \calc_chk_document_counter:nn#1{ + \cs_if_free:cTF{c@#1}{\@nocounterr {#1}} +} +\let:NN \setcounter \calc_setcounter:nn +\let:NN \addtocounter \calc_addtocounter:nn +\let:NN \stepcounter \calc_stepcounter:n +\AtBeginDocument{ + \let:NN \setcounter \calc_setcounter:nn + \let:NN \addtocounter \calc_addtocounter:nn + \let:NN \stepcounter \calc_stepcounter:n +} +% \end{macrocode} +% Prevent the usual \textsf{calc} from loading. +% \begin{macrocode} +%<package>\def:cpn{ver@calc.sty}{2005/08/06} +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} % \end{macro} % \end{macro} % |