T-F-S / csvsimple

A LaTeX package for lightweight CSV file processing.
http://www.ctan.org/pkg/csvsimple
LaTeX Project Public License v1.3c
24 stars 5 forks source link

Wrong argument description "integer expression" for `\IfCsvsimIntCompareTF`/`\ifcsvintcmp` #37

Closed muzimuzhi closed 3 months ago

muzimuzhi commented 7 months ago

The first argument of \IfCsvsimIntCompareTF and \ifcsvintcmp is documented as <integer expression>, but it actually has to have the form <integer expression> (<relation> <integer expression>)+, as required by the underlying \int_compare:nTF/\int_compare_p:n. https://github.com/T-F-S/csvsimple/blob/94632b980ff7f5beed9ca7a1361cf05c2481ac8b/doc/latex/csvsimple/csvsimple-l3.tex#L2448-L2459

The difference is, an <integer expression> cannot contain a relation, while the first argument of \int_compare:nTF requires at least one relation. A relation is one of =, ==, >=, >, <=, <, and !=, from doc of \int_compare:nTF.

\documentclass{article}

\begin{document}
\ExplSyntaxOn\ttfamily
\int_set:Nn \l_tmpa_int { 3 }
\int_compare:nTF { \l_tmpa_int } { T } { F } % errors!
\int_compare:nTF { \l_tmpa_int >= 3 }    { T } { F } % true
\int_compare:nTF { 1 < \l_tmpa_int < 5 } { T } { F } % true
\par

\int_eval:n { \l_tmpa_int }, % leaves "3"
\int_eval:n { \l_tmpa_int >= 3},    % wrong! leaves "3>=3" in input stream
\int_eval:n { 1 < \l_tmpa_int < 5 } % errors! 
\par

\fp_set:Nn \l_tmpa_fp { 3.14 }
\fp_compare:nTF { 0 }          { T } { F } % false
\fp_compare:nTF { \l_tmpa_fp } { T } { F } % true
\fp_compare:nTF { \l_tmpa_fp >= 3 }    { T } { F } % true
\fp_compare:nTF { 1 < \l_tmpa_fp < 5 } { T } { F } % true
\par

\fp_eval:n { \l_tmpa_fp },        % leaves "3.14"
\fp_eval:n { \l_tmpa_fp >= 3 },   % leaves "1" (true)
\fp_eval:n { 1 < \l_tmpa_fp < 5 } % leaves "1" (true)
\ExplSyntaxOff
\end{document}

Differently, <floating point expression> is, from my point of view, a valid description for arguments that are finally passed to \fp_compare:nTF/\fp_compare_p:n, because

Perhaps the last rule can be documented.

muzimuzhi commented 7 months ago

I just opened https://github.com/latex3/latex3/issues/1424 to ask if it's sensible to relax the documented form of first argument of \fp_compare:nTF.

T-F-S commented 7 months ago

Since these number tests a mere wrappers for LaTeX3 functions, I want to keep the documentation quite short here, because possible users are hinted to \fp_compare:nTF and \int_compare:nTF and the documentation of interface3.pdf should be the prime source, not the csvsimple-l3 documentation.

But you are right that the current description is misleading. I would go for the following:

grafik

muzimuzhi commented 7 months ago

Several other <floating point expression> arguments may need the same renaming. For example csvsim/filter fp.

T-F-S commented 7 months ago

I realized that the example for csvsim/filter fp contains a working content for \fp_compare_p:n with logical && which is not covered by the (current?) documention inside interface3.pdf.

So, I will move the && part to csvsim/and filter fp.

grafik

grafik

muzimuzhi commented 7 months ago

I realized that the example for csvsim/filter fp contains a working content for \fp_compare_p:n with logical && which is not covered by the (current?) documention inside interface3.pdf.

So, I will move the && part to csvsim/and filter fp.

Not necessary. <fp expr> does support && operation, as well as ||.

image
T-F-S commented 6 months ago

Not necessary. <fp expr> does support && operation, as well as ||.

I missed it while I was skipping quickly through interface3.pdf and feared that it was dropped. But, luckily, you are right, it's still documented and the example can stay as is was. Thank you.

T-F-S commented 3 months ago

Integrated into https://github.com/T-F-S/csvsimple/releases/tag/v2.6.1