davidcarlisle / dpctex

Assorted TeX packages
93 stars 30 forks source link

numdef: use a numdef-ed command inside FPeval #37

Closed vinraspa closed 1 year ago

vinraspa commented 1 year ago

Hello. First, let me thank you for your package numdef.sty. I use it a lot. Today, I encountered an issue with fp package (\FPeval command). see below :

\num\FPeval\field1{1/7}            % Command  \field1 is created
field1 = \field1                   % and is correctly displayed

\num\FPeval\field2{2*\field1}      % This fails!
field2 = \field2    

Here is the error message:

! Argument of \doaction has an extra }.
<inserted text> 
                \par 
l.48    \num\FPeval\field2{2*\protect\field1}

I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.

Runaway argument?
 ]0.142857142857142857\FP@upn@debug {+++ result of upn-expression is \ETC.
! Paragraph ended before \doaction was complete.
<to be read again> 
                   \par 
l.48    \num\FPeval\field2{2*\field1}

I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.

I also tried this: \num\FPeval\field2{2*\ptotect\field1} and \num\FPeval\field2{2*\field{1}} but it failed too. Do you think of a workaround? Maybe have I missed something...

Thank you in advance!

davidcarlisle commented 1 year ago

Personally I wouldn't use numdef at all. I don't think I have ever used the package, and never added it to CTAN or the standard tex distributions.

Command \field1 is created

You have not defined \field1 but \field which then does non-expandable lookahead and assignments to find a following number (1 here). I doubt there is any reasonable way to make that work in fp package \FPeval (or in the standard latex \fpeval) sorry.

If you use \fielda, \fieldb, ... rather than \field1, \field2, this package is not needed at all.

vinraspa commented 1 year ago

OK. Thank you.