summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/expl3/l3calc.dtx
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-06-09 23:31:15 +0000
committerKarl Berry <karl@freefriends.org>2009-06-09 23:31:15 +0000
commit215b9a864d5829070bdc66ba736986eb72e5143e (patch)
treefe0882c81fc4ec945cee4b512f72eaa21ea5f791 /Master/texmf-dist/source/latex/expl3/l3calc.dtx
parentdf90ec06321940c2f066b05e12f1b5ab099105da (diff)
expl3 1407 (9jun09)
git-svn-id: svn://tug.org/texlive/trunk@13686 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/expl3/l3calc.dtx')
-rw-r--r--Master/texmf-dist/source/latex/expl3/l3calc.dtx493
1 files changed, 302 insertions, 191 deletions
diff --git a/Master/texmf-dist/source/latex/expl3/l3calc.dtx b/Master/texmf-dist/source/latex/expl3/l3calc.dtx
index 842e68864c7..c9519f13ca4 100644
--- a/Master/texmf-dist/source/latex/expl3/l3calc.dtx
+++ b/Master/texmf-dist/source/latex/expl3/l3calc.dtx
@@ -1,5 +1,5 @@
% \iffalse
-%% File: l3calc.dtx Copyright (C) 2006 LaTeX3 project
+%% File: l3calc.dtx Copyright (C) 2006,2009 LaTeX3 project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -17,7 +17,7 @@
%%
%% The development version of the bundle can be found at
%%
-%% http://www.latex-project.org/cgi-bin/cvsweb.cgi/
+%% http://www.latex-project.org/svnroot/experimental/trunk/
%%
%% for those people who are interested.
%%
@@ -35,7 +35,7 @@
\RequirePackage{l3names}
%</driver|package>
%\fi
-\GetIdInfo$Id: l3calc.dtx 621 2007-09-01 20:14:19Z morten $
+\GetIdInfo$Id: l3calc.dtx 1362 2009-05-28 20:19:21Z joseph $
{L3 Experimental calc module}
%\iffalse
%<*driver>
@@ -43,7 +43,7 @@
\ProvidesFile{\filename.\filenameext}
[\filedate\space v\fileversion\space\filedescription]
%\iffalse
-\documentclass{l3doc}
+\documentclass[full]{l3doc}
\begin{document}
\DocInput{\filename.\filenameext}
\end{document}
@@ -58,8 +58,8 @@
% \date{\filedate}
% \maketitle
%
-% \section{Infix notation arithmetic}
-%
+% \begin{documentation}
+%
% This is pretty much a straight adaption of the \textsf{calc} package
% and as such has same syntax for the \meta{calc expression}. However,
% there are some noticeable differences.
@@ -83,16 +83,51 @@
% the original \textsf{calc} package providing the same functionality
% and will prevent the original \textsf{calc} package from loading.
%
+% \section{User functions}
+%
+%
+% \begin{function}{ \maxof |
+% \minof |
+% \widthof |
+% \heightof |
+% \depthof |
+% \totalheightof |
+% \ratio |
+% \real |
+% \setlength |
+% \gsetlength |
+% \addtolength |
+% \gaddtolength |
+% \setcounter |
+% \addtocounter |
+% \stepcounter }
+% See documentation for \LaTeXe\ package \pkg{calc}.
+% \end{function}
+%
+% \begin{function}{ \calc_maxof:nn |
+% \calc_minof:nn |
+% \calc_widthof:n |
+% \calc_heightof:n |
+% \calc_depthof:n |
+% \calc_totalheightof:n |
+% \calc_ratio:nn |
+% \calc_real:n |
+% \calc_setcounter:nn |
+% \calc_addtocounter:nn |
+% \calc_stepcounter:n }
+% Equivalent commands as the above in the \pkg{expl3} namespace.
+% \end{function}
+%
% \begin{function}{
% \calc_int_set:Nn |
% \calc_int_gset:Nn |
% \calc_int_add:Nn |
% \calc_int_gadd:Nn |
% \calc_int_sub:Nn |
-% \calc_int_gsub:Nn |
+% \calc_int_gsub:Nn
% }
% \begin{syntax}
-% "\calc_int_set:Nn" <int> "{"<calc expression>"}"
+% "\calc_int_set:Nn" <int> \Arg{calc expression}
% \end{syntax}
% Evaluates <calc expression> and either adds or subtracts it from
% <int> or sets <int> to it. These operations can also be global.
@@ -108,7 +143,7 @@
% \calc_dim_gsub:Nn |
% }
% \begin{syntax}
-% "\calc_dim_set:Nn" <dim> "{"<calc expression>"}"
+% "\calc_dim_set:Nn" <dim> \Arg{calc expression}
% \end{syntax}
% Evaluates <calc expression> and either adds or subtracts it from
% <dim> or sets <dim> to it. These operations can also be global.
@@ -124,7 +159,7 @@
% \calc_skip_gsub:Nn |
% }
% \begin{syntax}
-% "\calc_skip_set:Nn" <skip> "{"<calc expression>"}"
+% "\calc_skip_set:Nn" <skip> \Arg{calc expression}
% \end{syntax}
% Evaluates <calc expression> and either adds or subtracts it from
% <skip> or sets <skip> to it. These operations can also be global.
@@ -140,7 +175,7 @@
% \calc_muskip_gsub:Nn |
% }
% \begin{syntax}
-% "\calc_muskip_set:Nn" <muskip> "{"<calc expression>"}"
+% "\calc_muskip_set:Nn" <muskip> \Arg{calc expression}
% \end{syntax}
% Evaluates <calc expression> and either adds or subtracts it from
% <muskip> or sets <muskip> to it. These operations can also be
@@ -152,8 +187,8 @@
% \calc_calculate_box_size:nnn |
% }
% \begin{syntax}
-% "\calc_calculate_box_size:nnn" "{"<dim-set>"}" \\
-% "{"<item 1> <item 2> ... <item n>"}" "{"<contents>"}"
+% "\calc_calculate_box_size:nnn" \Arg{dim-set} \\
+% "{"<item 1> <item 2> ... <item n>"}" \Arg{contents}
% \end{syntax}
% Sets <contents> in a temporary box "\l_tmpa_box". Then <dim-set>
% is put in front of a loop that inserts "+"\meta{item$\sb{i}$} in
@@ -172,9 +207,72 @@
% \end{verbatim}
% \end{function}
%
-% \StopEventually{}
+% \end{documentation}
+%
+% \begin{implementation}
+%
%
-% \subsection{The Implementation}
+% \section{\pkg{l3calc} implementation}
+%
+% \subsection{Variables}
+%
+% \begin{function}{ \l_calc_expression_tl |
+% \g_calc_A_register |
+% \l_calc_B_register |
+% \l_calc_current_type_int |
+% \g_calc_A_int |
+% \l_calc_B_int |
+% \l_calc_C_int |
+% \g_calc_A_dim |
+% \l_calc_B_dim |
+% \l_calc_C_dim |
+% \g_calc_A_skip |
+% \l_calc_B_skip |
+% \l_calc_C_skip |
+% \g_calc_A_muskip |
+% \l_calc_B_muskip |
+% \l_calc_C_muskip }
+% Internal registers.
+% \end{function}
+%
+% \subsection{Internal functions}
+%
+% \begin{function}{ \calc_assign_generic:NNNNnn |
+% \calc_pre_scan:N |
+% \calc_open:w |
+% \calc_init_B: |
+% \calc_numeric: |
+% \calc_close: |
+% \calc_post_scan:N |
+% \calc_multiply:N |
+% \calc_divide:N |
+% \calc_generic_add_or_subtract:N |
+% \calc_add: |
+% \calc_subtract: |
+% \calc_add_A_to_B: |
+% \calc_subtract_A_from_B: |
+% \calc_generic_multiply_or_divide:N |
+% \calc_multiply_B_by_A: |
+% \calc_divide_B_by_A: |
+% \calc_multiply: |
+% \calc_divide: |
+% \calc_textsize:Nn |
+% \calc_ratio_multiply:nn |
+% \calc_ratio_divide:nn |
+% \calc_real_evaluate:nn |
+% \calc_real_multiply:n |
+% \calc_real_divide:n |
+% \calc_maxmin_operation:Nnn |
+% \calc_maxmin_generic:Nnn |
+% \calc_maxmin_div_or_mul:NNnn |
+% \calc_maxmin_multiply: |
+% \calc_maxmin_multiply: |
+% \calc_error:N |
+% \calc_chk_document_counter:nn }
+% Awaiting better documentation ":)"
+% \end{function}
+%
+% \subsection{Module code}
%
% Since this is basically a re-worked version of the \textsf{calc}
% package, I haven't bothered with too many comments except for in the
@@ -186,23 +284,21 @@
%<*package>
\ProvidesExplPackage
{\filename}{\filedate}{\fileversion}{\filedescription}
-\RequirePackage{l3int}
-\RequirePackage{l3skip}
-\RequirePackage{l3box}
+\package_check_loaded_expl:
%</package>
%<*initex|package>
% \end{macrocode}
%
%
-% \begin{macro}{\l_calc_expression_tlp}
+% \begin{macro}{\l_calc_expression_tl}
% \begin{macro}{\g_calc_A_register}
% \begin{macro}{\l_calc_B_register}
% \begin{macro}{\l_calc_current_type_int}
% Here we define some registers and pointers we will need.
% \begin{macrocode}
-\tlp_new:Nn\l_calc_expression_tlp{}
-\def_new:Npn \g_calc_A_register{}
-\def_new:Npn \l_calc_B_register{}
+\tl_new:Nn\l_calc_expression_tl{}
+\cs_new_nopar:Npn \g_calc_A_register{}
+\cs_new_nopar:Npn \l_calc_B_register{}
\int_new:N \l_calc_current_type_int
% \end{macrocode}
% \end{macro}
@@ -261,17 +357,17 @@
% 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
+\cs_new:Npn \calc_assign_generic:NNNNnn#1#2#3#4#5#6{
+ \cs_set_eq:NN\g_calc_A_register#2
+ \cs_set_eq: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
+ \cs_set_eq:NN \real \calc_real:n
+ \cs_set_eq:NN \ratio\calc_ratio:nn
+ \tl_set:Nx\l_calc_expression_tl{#6}
+ \exp_after:wN
\group_end:
- \exp_after:NN\calc_open:w\exp_after:NN(\l_calc_expression_tlp !
+ \exp_after:wN\calc_open:w\exp_after:wN(\l_calc_expression_tl !
\pref_global:D\g_calc_A_register\l_calc_B_register
\group_end:
#4{#5}\l_calc_B_register
@@ -280,11 +376,11 @@
% 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{
-% \let:NN\g_calc_A_register#2\let:NN\l_calc_B_register#3
+% \cs_new:Npn \calc_assign_generic:NNNNnn#1#2#3#4#5#6{
+% \cs_set_eq:NN\g_calc_A_register#2\cs_set_eq: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 !
+% \tl_set:Nx\l_calc_expression_tl{#6}
+% \exp_after:wN\calc_open:w\exp_after:wN(\l_calc_expression_tl !
% \pref_global:D\g_calc_A_register\l_calc_B_register
% \group_end:
% #4{#5}\l_calc_B_register
@@ -303,22 +399,22 @@
% Here are the individual versions for the different register
% types. First integer registers.
% \begin{macrocode}
-\def_new:Npn\calc_int_set:Nn{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_int_gsub:Nn{
\calc_assign_generic:NNNNnn\c_zero\g_calc_A_int\l_calc_B_int\int_gsub:Nn
}
% \end{macrocode}
@@ -337,22 +433,22 @@
% \begin{macro}{\calc_dim_gsub:Nn}
% Dimens.
% \begin{macrocode}
-\def_new:Npn\calc_dim_set:Nn{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_dim_gsub:Nn{
\calc_assign_generic:NNNNnn\c_one\g_calc_A_int\l_calc_B_int\dim_gsub:Nn
}
% \end{macrocode}
@@ -371,22 +467,22 @@
% \begin{macro}{\calc_skip_gsub:Nn}
% Skips.
% \begin{macrocode}
-\def_new:Npn\calc_skip_set:Nn{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_skip_gsub:Nn{
\calc_assign_generic:NNNNnn\c_two\g_calc_A_skip\l_calc_B_skip\skip_gsub:Nn
}
% \end{macrocode}
@@ -405,27 +501,27 @@
% \begin{macro}{\calc_muskip_gsub:Nn}
% Muskips.
% \begin{macrocode}
-\def_new:Npn\calc_muskip_set:Nn{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_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{
+\cs_new_nopar:Npn\calc_muskip_sub: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{
+\cs_new_nopar:Npn\calc_muskip_gsub:Nn{
\calc_assign_generic:NNNNnn\c_three\g_calc_A_muskip\l_calc_B_muskip
\muskip_gadd:Nn
}
@@ -442,13 +538,13 @@
% In case we found one of the special operations, this should just
% be executed.
% \begin{macrocode}
-\def_new:Npn \calc_pre_scan:N #1{
- \if_meaning:NN(#1
- \exp_after:NN\calc_open:w
+\cs_new_nopar:Npn \calc_pre_scan:N #1{
+ \if_meaning:w(#1
+ \exp_after:wN\calc_open:w
\else:
- \if_meaning:NN \calc_textsize:Nn #1
+ \if_meaning:w \calc_textsize:Nn #1
\else:
- \if_meaning:NN \calc_maxmin_operation:Nnn #1
+ \if_meaning:w \calc_maxmin_operation:Nnn #1
\else:
% \end{macrocode}
% |\calc_numeric:| uses a primitive assignment so doesn't care about
@@ -464,7 +560,7 @@
%
% \begin{macro}{\calc_open:w}
% \begin{macrocode}
-\def_new:Npn \calc_open:w({
+\cs_new_nopar:Npn \calc_open:w({
\group_begin:\group_execute_after:N\calc_init_B:
\group_begin:\group_execute_after:N\calc_init_B:
\calc_pre_scan:N
@@ -476,12 +572,12 @@
% \begin{macro}{\calc_numeric:}
% \begin{macro}{\calc_close:}
% \begin{macrocode}
-\def_new:Npn\calc_init_B:{\l_calc_B_register\g_calc_A_register}
-\def_new:Npn\calc_numeric:{
+\cs_new_nopar:Npn\calc_init_B:{\l_calc_B_register\g_calc_A_register}
+\cs_new_nopar:Npn\calc_numeric:{
\tex_afterassignment:D\calc_post_scan:N
\pref_global:D\g_calc_A_register
}
-\def_new:Npn\calc_close:{
+\cs_new_nopar:Npn\calc_close:{
\group_end:\pref_global:D\g_calc_A_register\l_calc_B_register
\group_end:\pref_global:D\g_calc_A_register\l_calc_B_register
\calc_post_scan:N}
@@ -493,21 +589,21 @@
% \begin{macro}{\calc_post_scan:N}
% Look at what token we have and decide where to go.
% \begin{macrocode}
-\def_new:Npn\calc_post_scan:N#1{
- \if_meaning:NN#1!\let:NN\calc_next:w\group_end: \else:
- \if_meaning:NN#1+\let:NN\calc_next:w\calc_add: \else:
- \if_meaning:NN#1-\let:NN\calc_next:w\calc_subtract: \else:
- \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
+\cs_new_nopar:Npn\calc_post_scan:N#1{
+ \if_meaning:w#1!\cs_set_eq:NN\calc_next:w\group_end: \else:
+ \if_meaning:w#1+\cs_set_eq:NN\calc_next:w\calc_add: \else:
+ \if_meaning:w#1-\cs_set_eq:NN\calc_next:w\calc_subtract: \else:
+ \if_meaning:w#1*\cs_set_eq:NN\calc_next:w\calc_multiply:N \else:
+ \if_meaning:w#1/\cs_set_eq:NN\calc_next:w\calc_divide:N \else:
+ \if_meaning:w#1)\cs_set_eq:NN\calc_next:w\calc_close: \else:
+ \if_meaning:w#1\scan_stop:\cs_set_eq: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 \use_noop:
+ \cs_set_eq:NN \calc_next:w \prg_do_nothing:
\calc_error:N#1
\fi:
\fi:
@@ -524,33 +620,33 @@
% \begin{macro}{\calc_divide:N}
% The switches for multiplication and division.
% \begin{macrocode}
-\def_new:Npn \calc_multiply:N #1{
- \if_meaning:NN \calc_maxmin_operation:Nnn #1
- \let:NN \calc_next:w \calc_maxmin_multiply:
+\cs_new_nopar:Npn \calc_multiply:N #1{
+ \if_meaning:w \calc_maxmin_operation:Nnn #1
+ \cs_set_eq:NN \calc_next:w \calc_maxmin_multiply:
\else:
- \if_meaning:NN \calc_ratio_multiply:nn #1
- \let:NN \calc_next:w \calc_ratio_multiply:nn
+ \if_meaning:w \calc_ratio_multiply:nn #1
+ \cs_set_eq:NN \calc_next:w \calc_ratio_multiply:nn
\else:
- \if_meaning:NN \calc_real_evaluate:nn #1
- \let:NN \calc_next:w \calc_real_multiply:n
+ \if_meaning:w \calc_real_evaluate:nn #1
+ \cs_set_eq:NN \calc_next:w \calc_real_multiply:n
\else:
- \def:Npn \calc_next:w{\calc_multiply: #1}
+ \cs_set_nopar:Npn \calc_next:w{\calc_multiply: #1}
\fi:
\fi:
\fi:
\calc_next:w
}
-\def_new:Npn \calc_divide:N #1{
- \if_meaning:NN \calc_maxmin_operation:Nnn #1
- \let:NN \calc_next:w \calc_maxmin_divide:
+\cs_new_nopar:Npn \calc_divide:N #1{
+ \if_meaning:w \calc_maxmin_operation:Nnn #1
+ \cs_set_eq:NN \calc_next:w \calc_maxmin_divide:
\else:
- \if_meaning:NN \calc_ratio_multiply:nn #1
- \let:NN \calc_next:w \calc_ratio_divide:nn
+ \if_meaning:w \calc_ratio_multiply:nn #1
+ \cs_set_eq:NN \calc_next:w \calc_ratio_divide:nn
\else:
- \if_meaning:NN \calc_real_evaluate:nn #1
- \let:NN \calc_next:w \calc_real_divide:n
+ \if_meaning:w \calc_real_evaluate:nn #1
+ \cs_set_eq:NN \calc_next:w \calc_real_divide:n
\else:
- \def:Npn \calc_next:w{\calc_divide: #1}
+ \cs_set_nopar:Npn \calc_next:w{\calc_divide: #1}
\fi:
\fi:
\fi:
@@ -560,26 +656,26 @@
% \end{macro}
% \end{macro}
%
-% \begin{macro}{\calc_generic_add:N}
+% \begin{macro}{\calc_generic_add_or_subtract:N}
% \begin{macro}{\calc_add:}
% \begin{macro}{\calc_subtract:}
% \begin{macro}{\calc_add_A_to_B:}
% \begin{macro}{\calc_subtract_A_from_B:}
% Here is how we add and subtract.
% \begin{macrocode}
-\def_new:Npn\calc_generic_add_or_subtract:N#1{
+\cs_new_nopar:Npn\calc_generic_add_or_subtract:N#1{
\group_end:
\pref_global:D\g_calc_A_register\l_calc_B_register\group_end:
\group_begin:\group_execute_after:N#1\group_begin:
\group_execute_after:N\calc_init_B:
\calc_pre_scan:N}
-\def_new:Npn\calc_add:{\calc_generic_add_or_subtract:N\calc_add_A_to_B:}
-\def_new:Npn\calc_subtract:{
+\cs_new_nopar:Npn\calc_add:{\calc_generic_add_or_subtract:N\calc_add_A_to_B:}
+\cs_new_nopar:Npn\calc_subtract:{
\calc_generic_add_or_subtract:N\calc_subtract_A_from_B:}
% \end{macrocode}
% Don't use |\tex_advance:D| since it allows overflows.
% \begin{macrocode}
-\def_new:Npn\calc_add_A_to_B:{
+\cs_new_nopar:Npn\calc_add_A_to_B:{
\l_calc_B_register
\if_case:w\l_calc_current_type_int
\etex_numexpr:D\or:
@@ -588,7 +684,7 @@
\etex_muexpr:D\fi:
\l_calc_B_register + \g_calc_A_register\scan_stop:
}
-\def_new:Npn\calc_subtract_A_from_B:{
+\cs_new_nopar:Npn\calc_subtract_A_from_B:{
\l_calc_B_register
\if_case:w\l_calc_current_type_int
\etex_numexpr:D\or:
@@ -613,15 +709,15 @@
% primitive \TeX{} operations but the expandable operations provided
% by \eTeX. This means that all results are rounded not truncated!
% \begin{macrocode}
-\def_new:Npn\calc_generic_multiply_or_divide:N#1{
+\cs_new_nopar:Npn\calc_generic_multiply_or_divide:N#1{
\group_end:
\group_begin:
- \let:NN\g_calc_A_register\g_calc_A_int
- \let:NN\l_calc_B_register\l_calc_B_int
+ \cs_set_eq:NN\g_calc_A_register\g_calc_A_int
+ \cs_set_eq: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:{
+\cs_new_nopar:Npn\calc_multiply_B_by_A:{
\l_calc_B_register
\if_case:w\l_calc_current_type_int
\etex_numexpr:D\or:
@@ -630,7 +726,7 @@
\etex_muexpr:D\fi:
\l_calc_B_register*\g_calc_A_int\scan_stop:
}
-\def_new:Npn\calc_divide_B_by_A:{
+\cs_new_nopar:Npn\calc_divide_B_by_A:{
\l_calc_B_register
\if_case:w\l_calc_current_type_int
\etex_numexpr:D\or:
@@ -639,9 +735,9 @@
\etex_muexpr:D\fi:
\l_calc_B_register/\g_calc_A_int\scan_stop:
}
-\def_new:Npn\calc_multiply:{
+\cs_new_nopar:Npn\calc_multiply:{
\calc_generic_multiply_or_divide:N\calc_multiply_B_by_A:}
-\def_new:Npn\calc_divide:{
+\cs_new_nopar:Npn\calc_divide:{
\calc_generic_multiply_or_divide:N\calc_divide_B_by_A:}
% \end{macrocode}
% \end{macro}
@@ -651,19 +747,19 @@
% \end{macro}
%
% \begin{macro}{\calc_calculate_box_size:nnn}
-% \begin{macro}{\calc_calculate_box_size_aux:n}
+% \begin{macro}[aux]{\calc_calculate_box_size_aux:n}
% Put something in a box and measure it. |#1| is a list of
% |\box_ht:N| etc., |#2| should be |\dim_set:Nn|\meta{dim register}
% or |\dim_gset:Nn|\meta{dim register} and |#3| is the contents.
% \begin{macrocode}
-\def_long_new:Npn \calc_calculate_box_size:nnn #1#2#3{
+\cs_new:Npn \calc_calculate_box_size:nnn #1#2#3{
\hbox_set:Nn \l_tmpa_box {{#3}}
- #2{\c_zero_dim \tlist_map_function:nN{#1}\calc_calculate_box_size_aux:n}
+ #2{\c_zero_dim \tl_map_function:nN{#1}\calc_calculate_box_size_aux:n}
}
% \end{macrocode}
% Helper for calculating the final dimension.
% \begin{macrocode}
-\def:Npn \calc_calculate_box_size_aux:n#1{ + #1\l_tmpa_box}
+\cs_set_nopar:Npn \calc_calculate_box_size_aux:n#1{ + #1\l_tmpa_box}
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -672,12 +768,12 @@
% \begin{macro}{\calc_textsize:Nn}
% Now we can define |\calc_textsize:Nn|.
% \begin{macrocode}
-\def_protected_long:Npn \calc_textsize:Nn#1#2{
+\cs_set_protected:Npn \calc_textsize:Nn#1#2{
\group_begin:
- \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}
+ \cs_set_eq:NN\calc_widthof_aux:n\box_wd:N
+ \cs_set_eq:NN\calc_heightof_aux:n\box_ht:N
+ \cs_set_eq:NN\calc_depthof_aux:n\box_dp:N
+ \cs_set_nopar: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}
@@ -685,10 +781,10 @@
% call.
% \begin{macrocode}
{
- \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
+ \cs_set_eq:NN \calc_depthof_aux:n \calc_depthof_auxi:n
+ \cs_set_eq:NN \calc_widthof_aux:n \calc_widthof_auxi:n
+ \cs_set_eq:NN \calc_heightof_aux:n \calc_heightof_auxi:n
+ \cs_set_eq:NN \calc_totalheightof_aux:n \calc_totalheightof_auxi:n
#2
}
\group_end:
@@ -703,7 +799,7 @@
% register, the ratio is probably also done with this type and we'll
% have to convert them to regular points.
% \begin{macrocode}
-\def_protected_long:Npn\calc_ratio_multiply:nn#1#2{
+\cs_set_protected:Npn\calc_ratio_multiply:nn#1#2{
\group_end:\group_begin:
\if_num:w\l_calc_current_type_int < \c_three
\calc_dim_set:Nn\l_calc_B_int{#1}
@@ -715,7 +811,7 @@
% \end{macrocode}
% Then store the ratio as a fraction, which we just pass on.
% \begin{macrocode}
- \gdef:Npx\calc_calculated_ratio:{
+ \cs_gset_nopar:Npx\calc_calculated_ratio:{
\int_use:N\l_calc_B_int/\int_use:N\l_calc_C_int
}
\group_end:
@@ -738,7 +834,7 @@
% \end{macrocode}
% Division is just flipping the arguments around.
% \begin{macrocode}
-\def_long_new:Npn \calc_ratio_divide:nn#1#2{\calc_ratio_multiply:nn{#2}{#1}}
+\cs_new:Npn \calc_ratio_divide:nn#1#2{\calc_ratio_multiply:nn{#2}{#1}}
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -750,7 +846,7 @@
% |\ratio|, this is horribly inefficient since we just want to convert
% the decimal to a fraction.
% \begin{macrocode}
-\def_protected_new:Npn\calc_real_evaluate:nn #1#2{
+\cs_new_protected_nopar:Npn\calc_real_evaluate:nn #1#2{
\group_end:
\l_calc_B_register
\if_case:w\l_calc_current_type_int
@@ -764,8 +860,8 @@
\scan_stop:
\group_begin:
\calc_post_scan:N}
-\def_new:Npn \calc_real_multiply:n #1{\calc_real_evaluate:nn{#1}{1}}
-\def_new:Npn \calc_real_divide:n {\calc_real_evaluate:nn{1}}
+\cs_new_nopar:Npn \calc_real_multiply:n #1{\calc_real_evaluate:nn{#1}{1}}
+\cs_new_nopar:Npn \calc_real_divide:n {\calc_real_evaluate:nn{1}}
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -778,7 +874,7 @@
% \begin{macro}{\calc_maxmin_multiply:}
% The max and min functions.
% \begin{macrocode}
-\def_protected_long:Npn\calc_maxmin_operation:Nnn#1#2#3{
+\cs_set_protected:Npn\calc_maxmin_operation:Nnn#1#2#3{
\group_begin:
\calc_maxmin_generic:Nnn#1{#2}{#3}
\group_end:
@@ -787,7 +883,7 @@
% \end{macrocode}
% |#1| is either |>| or |<| and was expanded into this initially.
% \begin{macrocode}
-\def_protected_long_new:Npn \calc_maxmin_generic:Nnn#1#2#3{
+\cs_new_protected:Npn \calc_maxmin_generic:Nnn#1#2#3{
\group_begin:
\if_case:w\l_calc_current_type_int
\calc_int_set:Nn\l_calc_C_int{#2}%
@@ -816,7 +912,7 @@
\fi:
\group_end:
}
-\def_long_new:Npn\calc_maxmin_div_or_mul:NNnn#1#2#3#4{
+\cs_new:Npn\calc_maxmin_div_or_mul:NNnn#1#2#3#4{
\group_end:
\group_begin:
\int_zero:N\l_calc_current_type_int
@@ -826,9 +922,9 @@
\group_begin:
\calc_post_scan:N
}
-\def_new:Npn\calc_maxmin_multiply:{
+\cs_new_nopar:Npn\calc_maxmin_multiply:{
\calc_maxmin_div_or_mul:NNnn\calc_multiply_B_by_A:}
-\def_new:Npn\calc_maxmin_divide: {
+\cs_new_nopar:Npn\calc_maxmin_divide: {
\calc_maxmin_div_or_mul:NNnn\calc_divide_B_by_A:}
% \end{macrocode}
% \end{macro}
@@ -840,9 +936,9 @@
% \begin{macro}{\calc_error:N}
% The error message.
% \begin{macrocode}
-\def_new:Npn\calc_error:N#1{
+\cs_new_nopar:Npn\calc_error:N#1{
\PackageError{calc}
- {`\token_to_string:N#1'~ invalid~ at~ this~ point}
+ {`\token_to_str:N#1'~ invalid~ at~ this~ point}
{I~ expected~ to~ see~ one~ of:~ +~ -~ *~ /~ )}
}
% \end{macrocode}
@@ -858,14 +954,14 @@
% \begin{macro}{\minof}
% Max and min operations
% \begin{macrocode}
-\def_long_new:Npn \calc_maxof:nn#1#2{
+\cs_new:Npn \calc_maxof:nn#1#2{
\calc_maxmin_operation:Nnn > \exp_not:n{{#1}{#2}}
}
-\def_long_new:Npn \calc_minof:nn#1#2{
+\cs_new:Npn \calc_minof:nn#1#2{
\calc_maxmin_operation:Nnn < \exp_not:n{{#1}{#2}}
}
-\let:NN \maxof \calc_maxof:nn
-\let:NN \minof \calc_minof:nn
+\cs_set_eq:NN \maxof \calc_maxof:nn
+\cs_set_eq:NN \minof \calc_minof:nn
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -873,47 +969,47 @@
% \end{macro}
%
% \begin{macro}{\calc_widthof:n}
-% \begin{macro}{\calc_widthof_aux:n}
-% \begin{macro}{\calc_widthof_auxi:n}
+% \begin{macro}[aux]{\calc_widthof_aux:n}
+% \begin{macro}[aux]{\calc_widthof_auxi:n}
% \begin{macro}{\calc_heightof:n}
-% \begin{macro}{\calc_heightof_aux:n}
-% \begin{macro}{\calc_heightof_auxi:n}
+% \begin{macro}[aux]{\calc_heightof_aux:n}
+% \begin{macro}[aux]{\calc_heightof_auxi:n}
% \begin{macro}{\calc_depthof:n}
-% \begin{macro}{\calc_depthof_aux:n}
-% \begin{macro}{\calc_depthof_auxi:n}
+% \begin{macro}[aux]{\calc_depthof_aux:n}
+% \begin{macro}[aux]{\calc_depthof_auxi:n}
% \begin{macro}{\calc_totalheightof:n}
-% \begin{macro}{\calc_totalheightof_aux:n}
-% \begin{macro}{\calc_totalheightof_auxi:n}
+% \begin{macro}[aux]{\calc_totalheightof_aux:n}
+% \begin{macro}[aux]{\calc_totalheightof_auxi:n}
% Text dimension commands.
% \begin{macrocode}
-\def_long_new:Npn \calc_widthof:n#1{
+\cs_new:Npn \calc_widthof:n#1{
\calc_textsize:Nn \exp_not:N\calc_widthof_aux:n\exp_not:n{{#1}}
}
-\def_long_new:Npn \calc_heightof:n#1{
+\cs_new:Npn \calc_heightof:n#1{
\calc_textsize:Nn \exp_not:N\calc_heightof_aux:n\exp_not:n{{#1}}
}
-\def_long_new:Npn \calc_depthof:n#1{
+\cs_new:Npn \calc_depthof:n#1{
\calc_textsize:Nn \exp_not:N\calc_depthof_aux:n\exp_not:n{{#1}}
}
-\def_long_new:Npn \calc_totalheightof:n#1{
+\cs_new:Npn \calc_totalheightof:n#1{
\calc_textsize:Nn \exp_not:N\calc_totalheightof_aux:n \exp_not:n{{#1}}
}
-\def_long_new:Npn \calc_widthof_aux:n #1{
+\cs_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{
+\cs_new_eq:NN \calc_widthof_auxi:n \calc_widthof_aux:n
+\cs_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{
+\cs_new_eq:NN \calc_depthof_auxi:n \calc_depthof_aux:n
+\cs_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{
+\cs_new_eq:NN \calc_heightof_auxi:n \calc_heightof_aux:n
+\cs_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
+\cs_new_eq:NN \calc_totalheightof_auxi:n \calc_totalheightof_aux:n
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -932,9 +1028,9 @@
% \begin{macro}{\calc_real:n}
% Ratio and real.
% \begin{macrocode}
-\def_long_new:Npn \calc_ratio:nn#1#2{
+\cs_new:Npn \calc_ratio:nn#1#2{
\calc_ratio_multiply:nn\exp_not:n{{#1}{#2}}}
-\def_new:Npn \calc_real:n {\calc_real_evaluate:nn}
+\cs_new_nopar:Npn \calc_real:n {\calc_real_evaluate:nn}
% \end{macrocode}
% We can implement real and ratio without actually using these
% names. We'll see.
@@ -951,12 +1047,12 @@
% \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
+\cs_set_eq:NN \depthof\calc_depthof:n
+\cs_set_eq:NN \widthof\calc_widthof:n
+\cs_set_eq:NN \heightof\calc_heightof:n
+\cs_set_eq:NN \totalheightof\calc_totalheightof:n
+%%\cs_set_eq:NN \ratio\calc_ratio:nn
+%%\cs_set_eq:NN \real\calc_real:n
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -970,10 +1066,10 @@
% \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}
+\cs_set_protected_nopar:Npn \setlength{\calc_skip_set:Nn}
+\cs_set_protected_nopar:Npn \gsetlength{\calc_skip_gset:Nn}
+\cs_set_protected_nopar:Npn \addtolength{\calc_skip_add:Nn}
+\cs_set_protected_nopar:Npn \gaddtolength{\calc_skip_gadd:Nn}
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -992,44 +1088,67 @@
% |\mathchoice| will no longer need this switch as the argument is
% only executed once.
% \begin{macrocode}
+%</initex|package>
+%<*package>
\newif\iffirstchoice@ \firstchoice@true
-\def_protected:Npn \calc_setcounter:nn#1#2{
+%</package>
+%<*initex|package>
+\cs_set_protected_nopar: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{
+\cs_set_protected_nopar:Npn \calc_addtocounter:nn#1#2{
+%</initex|package>
+%<*package>
\iffirstchoice@
+%</package>
+%<*initex|package>
\calc_chk_document_counter:nn{#1}{
\exp_args:Nc\calc_int_gadd:Nn {c@#1}{#2}
}
+%</initex|package>
+%<*package>
\fi:
+%</package>
+%<*initex|package>
}
-\def_protected:Npn \calc_stepcounter:n#1{
+\cs_set_protected_nopar:Npn \calc_stepcounter:n#1{
+%</initex|package>
+%<*package>
\iffirstchoice@
+%</package>
+%<*initex|package>
\calc_chk_document_counter:nn{#1}{
\int_gincr:c {c@#1}
\group_begin:
- \let:NN \@elt\@stpelt \cs_use:c{cl@#1}
+ \cs_set_eq:NN \@elt\@stpelt \use:c{cl@#1}
\group_end:
}
+%</initex|package>
+%<*package>
\fi:
+%</package>
+%<*initex|package>
}
-\def_new:Npn \calc_chk_document_counter:nn#1{
+\cs_new_nopar: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
+\cs_set_eq:NN \setcounter \calc_setcounter:nn
+\cs_set_eq:NN \addtocounter \calc_addtocounter:nn
+\cs_set_eq:NN \stepcounter \calc_stepcounter:n
+%</initex|package>
+%<*package>
\AtBeginDocument{
- \let:NN \setcounter \calc_setcounter:nn
- \let:NN \addtocounter \calc_addtocounter:nn
- \let:NN \stepcounter \calc_stepcounter:n
+ \cs_set_eq:NN \setcounter \calc_setcounter:nn
+ \cs_set_eq:NN \addtocounter \calc_addtocounter:nn
+ \cs_set_eq: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}
+\cs_set_nopar:cpn{ver@calc.sty}{2005/08/06}
+%</package>
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -1038,22 +1157,14 @@
% \end{macro}
% \end{macro}
% \end{macro}
-%
-%
+%
% \begin{macrocode}
-%</initex|package>
%<*showmemory>
\showMemUsage
%</showmemory>
% \end{macrocode}
%
-% \endinput
-%
-% $Log$
-% Revision 1.2 2006/01/27 23:11:47 morten
-% Fixed bug in \calc_pre_scan:N and avoid using \advance in order to
-% catch overflows.
-%
-% Revision 1.1 2006/01/27 07:51:13 morten
-% Initial version of a calc module
+% \end{implementation}
+% \PrintIndex
%
+% \endinput