[latex3-commits] [git/LaTeX3-latex3-latex2e] gh711: adding \dimeval, \skipeval and documentation (a10ed112)

Frank Mittelbach frank.mittelbach at latex-project.org
Tue Dec 7 12:30:28 CET 2021


Repository : https://github.com/latex3/latex2e
On branch  : gh711
Link       : https://github.com/latex3/latex2e/commit/a10ed1127910f76fb92738a51925308819d80c89

>---------------------------------------------------------------

commit a10ed1127910f76fb92738a51925308819d80c89
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date:   Tue Dec 7 12:30:28 2021 +0100

    adding \dimeval, \skipeval and documentation


>---------------------------------------------------------------

a10ed1127910f76fb92738a51925308819d80c89
 base/changes.txt       |  2 +-
 base/doc/ltnews35.tex  | 35 ++++++++++++++++++++++++++++++++++-
 base/doc/usrguide3.tex | 42 +++++++++++++++++++++++++++++++-----------
 base/ltfinal.dtx       | 18 +++++++++++++-----
 4 files changed, 79 insertions(+), 18 deletions(-)

diff --git a/base/changes.txt b/base/changes.txt
index 8aaca2d9..6c4997ce 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -9,7 +9,7 @@ are not part of the distribution.
 2021-11-30  Frank Mittelbach  <Frank.Mittelbach at latex-project.org>
 
 	* ltfinal.dtx (subsection{Homeless declarations}):
-	Added \fpeval and \inteval (gh711)
+	Added \fpeval, \inteval, \dimeval, and \skipeval (gh711)
 
 2021-11-17  Marcel Krüger  <Marcel.Krueger at latex-project.org>
 
diff --git a/base/doc/ltnews35.tex b/base/doc/ltnews35.tex
index ecc37a7c..26b389b9 100644
--- a/base/doc/ltnews35.tex
+++ b/base/doc/ltnews35.tex
@@ -141,7 +141,40 @@
 
 \subsection{Floating point and integer calculations}
 
-\emph{write doc}
+The L3 programming layer offers expandable commands for calculating
+floating point and integer values, but so far these functions have
+only been available to programmers, because they require
+\cs{ExplSyntaxOn} to be in force. To make them easily available at the
+document-level, the small package \pkg{xfp} defined \cs{fpeval} and
+\cs{inteval}.
+
+
+An example of use could be the following:
+\begin{verbatim}
+\LaTeX{} can now compute: 
+\[ \frac{\sin (3.5)}{2} + 2\cdot 10^{-3}
+    = \fpeval{sin(3.5)/2 + 2e-3}         \]
+\end{verbatim}
+which produces the following output:
+\begin{quote}
+\LaTeX{} can now compute: 
+\[ \frac{\sin (3.5)}{2} + 2\cdot 10^{-3}
+   = \fpeval{sin(3.5)/2 + 2e-3}         \]
+\end{quote}
+These two commands have now been moved into the kernel and in addition
+we also provide \cs{dimeval} and \cs{skipeval}. The details of their
+syntax are described in \file{usrguide3.pdf}.  The command \cs{fpeval}
+offers a rich syntax allows for extensive calculations whereas the
+other three commands are essentially thin wrappers for \cs{numexpr},
+\cs{dimexpr}, and \cs{glueexpr} \Dash therefore inheriting some syntax
+peculiars and limitations in expressiveness.
+\begin{verbatim}
+\newcommand\calulateheight[1]{%
+  \setlength\textheight{\dimeval{\topskip 
+        + \baselineskip * \inteval{#1-1}}}}
+\end{verbatim}
+The above, for example, calculates the appropriate \cs{textheight} for
+a given number of text lines.
 %
 \githubissue{711}
 
diff --git a/base/doc/usrguide3.tex b/base/doc/usrguide3.tex
index 4c0ff3aa..8f416765 100644
--- a/base/doc/usrguide3.tex
+++ b/base/doc/usrguide3.tex
@@ -31,12 +31,13 @@
 \documentclass{ltxguide}
 
 \usepackage[T1]{fontenc}  % needed for \textbackslash in tt
+\usepackage{csquotes}
 
 \title{New \LaTeX\ methods for authors (starting 2020)}
 \author{\copyright~Copyright 2020-2021, \LaTeX\ Project Team.\\
    All rights reserved.}
 
-\date{2021-11-30}
+\date{2021-12-07}
 
 \NewDocumentCommand\cs{m}{\texttt{\textbackslash\detokenize{#1}}}
 \NewDocumentCommand\marg{m}{\arg{#1}}
@@ -566,10 +567,12 @@ spaces are trimmed at both ends of the body: in the example there would
 otherwise be spaces coming from the ends the lines after |[\itshape]| and
 |world!|. Putting the prefix |!| before \texttt{b} suppresses space-trimming.
 
-When \texttt{b} is used in the argument specification, the last argument of the environment declaration (e.g., \cs{NewDocumentEnvironment}), which consists of an \meta{end code} to insert at
-|\end|\marg{environment}, is redundant since one can simply put that code at
-the end of the \meta{start code}. Nevertheless this (empty) \meta{end code}
-must be provided.
+When \texttt{b} is used in the argument specification, the last
+argument of the environment declaration (e.g.,
+\cs{NewDocumentEnvironment}), which consists of an \meta{end code} to
+insert at |\end|\marg{environment}, is redundant since one can simply
+put that code at the end of the \meta{start code}. Nevertheless this
+(empty) \meta{end code} must be provided.
 
 Environments that use this feature can be nested.
 
@@ -821,7 +824,8 @@ which produces the following output:
   and for example within a low-level \cs{edef} operation to give a
   purely numerical result.
 
-  The restrictions are:
+  This is basically a thin wrapper for the primitive \cs{numexpr}
+  command and therefore has some syntax restrictions. These are:
   \begin{itemize}
   \item \texttt{/} denotes division rounded to the closest integer with
     ties rounded away from zero;
@@ -836,17 +840,33 @@ which produces the following output:
     \texttt{/} or~\texttt{(} leads to an error.
   \end{itemize}
 
-
 An example of use could be the following.
 \begin{verbatim}
-  \LaTeX{} can now compute: The sum of the numbers is $\inteval{1 + 2 + 3}$.
+\LaTeX{} can now compute: The sum of the numbers is $\inteval{1 + 2 + 3}$.
 \end{verbatim}
 which results in
-\begin{quote}
-  \LaTeX{} can now compute: The sum of the numbers is $\inteval{1 + 2 + 3}$.
-\end{quote}
+\enquote{\LaTeX{} can now compute: The sum of the numbers is $\inteval{1 + 2 + 3}$.}
 
 
+\begin{decl}
+  |\dimeval| \arg{dimen expression} \qquad
+  |\skipeval| \arg{skip expression}
+\end{decl}
 
+Similar to \cs{inteval} but computing a length (\texttt{dimen}) or a
+rubber length (\texttt{skip}) value. Both are thin wrappers arround
+the corresponding engine primitives, which makes them fast, but
+therefore shows the same syntax peculiars as discussed
+above. Nevertheless, in practice they are usually sufficient.  For
+example
+\begin{verbatim}
+\newcommand\calulateheight[1]{%
+  \setlength\textheight{\dimeval{\topskip+\baselineskip*\inteval{#1-1}}}}
+\end{verbatim}
+sets the \cs{textheight} to the appropriate value if a page should
+hold a specific number of text lines. Thus after |\calulateheight{40}|
+it is set to \dimeval{\topskip+\baselineskip*\inteval{40-1}}, given
+the values \cs{topskip} (\dimeval{\topskip}) and \cs{baselineskip}
+(\dimeval{\baselineskip}) in the current document.
 
 \end{document}
diff --git a/base/ltfinal.dtx b/base/ltfinal.dtx
index 4d98859a..83d552ea 100644
--- a/base/ltfinal.dtx
+++ b/base/ltfinal.dtx
@@ -33,7 +33,7 @@
 %<*driver>
 % \fi
 \ProvidesFile{ltfinal.dtx}
-             [2021/11/30 v2.2r LaTeX Kernel (Final Settings)]
+             [2021/12/07 v2.2r LaTeX Kernel (Final Settings)]
 % \iffalse
 \documentclass{ltxdoc}
 \GetFileInfo{ltfinal.dtx}
@@ -120,10 +120,10 @@
 %    \begin{macrocode}
 %    \end{macrocode}
 %
-% \begin{macro}{\fpeval,\inteval}
-%     A document level wrapper around the code level function for
+% \begin{macro}{\fpeval,\inteval,\dimeval,\skipeval}
+%    A document level wrapper around the code level function for
 %    floating point calculations.
-% \changes{v2.2r}{2021/11/30}{Oved over from \texttt{xfp} package (gh/711)}
+% \changes{v2.2r}{2021/11/30}{Moved over from \texttt{xfp} package (gh/711)}
 %    \begin{macrocode}
 %<*2ekernel|latexrelease>
 %<latexrelease>\IncludeInRelease{2022/06/01}%
@@ -131,9 +131,15 @@
 \ExplSyntaxOn
 \NewExpandableDocumentCommand \fpeval { m } { \fp_eval:n {#1} }
 %    \end{macrocode}
-%     A second one, this time around an \eTeX{} primitive.
+%     And a few more, this time wrappers around the \eTeX{} primitives.
 %    \begin{macrocode}
 \NewExpandableDocumentCommand \inteval { m } { \int_eval:n {#1} }
+%    \end{macrocode}
+%    
+% \changes{v2.2r}{2021/12/07}{Added \cs{dimeval} and \cs{skipeval} (gh/711)}
+%    \begin{macrocode}
+\NewExpandableDocumentCommand \dimeval { m } { \dim_eval:n {#1} }
+\NewExpandableDocumentCommand \skipeval { m }{ \skip_eval:n {#1} }
 \ExplSyntaxOff
 %    \end{macrocode}
 % \end{macro}
@@ -147,6 +153,8 @@
 %<latexrelease>
 %<latexrelease>\let\fpeval\@undefined
 %<latexrelease>\let\inteval\@undefined
+%<latexrelease>\let\dimeval\@undefined
+%<latexrelease>\let\skipeval\@undefined
 %<latexrelease>\EndIncludeInRelease
 %<*2ekernel>
 %    \end{macrocode}





More information about the latex3-commits mailing list.