I am trying to use the fp package, and the results are deeply confusing to me:

\FPeval\testing{2 + 2}
a & \testing

This will not compile:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018/Arch Linux) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2018-04-01> patch level 5
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
`Fixed Point Package', Version 0.8, April 2, 1995 (C) Michael Mehlich
No file mvce.aux.
( FP-EVAL ( FP-UPN ( FP-ADD ) ) )
! Undefined control sequence.
l.6 a & \testing

However, removing the & will give the intended result. Why does that happen, and what can I do about it? Should I use a different package for arithmetic?

This is just a simplified example. I actually want to use the result multiple times across a & and \\ boundary, which is why I can't just move the FPeval where the result is used.


\testing is a local variable, lost in the local scope (corresponding to each cell of the tabular). You need to set it global to use it in a different cell, or outside the tabular.

EDIT: Since egreg strongly recommends avoiding the syntax \global\let\testing\testing, I instead introduce \localtesting and \testing as the local and global versions of the same data.

\FPeval\localtesting{2 + 2}\global\let\testing\localtesting
a & \testing

Look, I am even available outside the tabular: \testing

enter image description here

  • Isn't it more the cells than the tabular env? Each cell in a table is a local group. – daleif Oct 17 '18 at 17:52
  • I believe that's what I need, thanks. Are there any other scopes than \global? For example, is it possible to make the variable's scope be the interior of a \newcommand definition? Could I wrap this construction into a macro, to avoid typing it out every time? Something like \myeval\global\testing{2 + 2} – NieDzejkob Oct 17 '18 at 17:54
  • 1
    @daleif That is what I meant, but I see how it can be confused...I will edit to clarify. – Steven B. Segletes Oct 17 '18 at 18:03
  • @NieDzejkob There are only local and global scopes. With extra work, you could save a global variable, change it as you wish, and then reset it back to the earlier value, but why spend the effort? That said, you could certainly define a \gFPeval that accomplishes both the \FPeval and the globalization. – Steven B. Segletes Oct 17 '18 at 18:07
  • 2
    To wrap this monstrosity into a neat macro: \def\geval#1#2{\FPeval#1{#2}\global\let#1#1} – NieDzejkob Oct 17 '18 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.