I know that I can use spreadtab to make automatic calculations in a tabular. However, I only managed to do simple operations like +-*/, but I have no idea how to make more complex ones like log, ln, sin, cos, tan, exp.

I tried to insert some fp functions in the spreadtab, but only receive errors.

Here is a minimal example:



    @number & @$\ln$(number)\\
    10 & \FPln{\result}{a2} \result


It gives the error: Missing = inserted for \ifnum. \end{spreadtab}.


3 Answers 3


It seems you can use the ln and sin functions directly:

enter image description here




    @$x$ & @$\ln(x)$ & @$\sin(x)$ [$x$ in degrees] \\
     15  & ln(a2)    & sin(a2*pi/180) \\
     30  & ln(a3)    & sin(a3*pi/180) \\
     45  & ln(a4)    & sin(a4*pi/180) \\
     90  & ln(a5)    & sin(a5*pi/180) \\

  • You are right, and sin(), cos() also. My bad I did not check that correctly, I tried with log() and didn't found informations about theses functions in the spreadtab manual. Should I delete my question, or would it be better to keep it so other distracted people may find the answer?
    – Togh
    Nov 22, 2014 at 20:23
  • @Togh: My usual opinion is to not delete a question -- What you did is exactly what I would have tried, so am sure that others will run into the similar problems in the future. Nov 22, 2014 at 20:26
  • Oops. Well you might be interested in a more powerful way of dealing with mathematical calculations which I've already posted below.
    – DJP
    Nov 22, 2014 at 20:37
  • ln(), exp(), ^, sin(), cos() and tan() works too.
    – Togh
    Nov 23, 2014 at 9:45

A solution using the powerful xfp package:


\def\Precision{4} % calculation precision

  round-mode = places,
  round-precision = \Precision,
  group-digits = false

\DeclareSIUnit[mode = text]\radian{rad}


% http://tex.stackexchange.com/a/201554/15874
  \multido{\i = 1+1}{10}{\protected@xdef\skyIDtable{\skyIDtable
    & \fpeval{round(ln(\i),\Precision)}   % logarithmic
    & \fpeval{round(sin(\i),\Precision)}  % sine (radian)
    & \fpeval{round(sind(\i),\Precision)} % sine (degrees)
    & \fpeval{round(tan(\i),\Precision)}  % tangent (radian)
    & \fpeval{round(tand(\i),\Precision)} % tangent (degrees)
    & \fpeval{round(exp(\i),\Precision)}  % exponential

    S[table-format =  2]
    S[table-format =  1.\Precision]
    S[table-format = -1.\Precision]
    S[table-format =  1.\Precision]
    S[table-format = -1.\Precision]
    S[table-format =  1.\Precision]
    S[table-format =  5.\Precision]
     {$x$} & {$\ln x$} & {$\sin x$}     & {$\sin x$}     & {$\tan x$}     & {$\tan x$}     & {$\exp x$} \\
     {---} & {---}     & {\si{\radian}} & {\si{\degree}} & {\si{\radian}} & {\si{\degree}} & {---}      \\




Note that log_[b], i.e. the logarithm in base b, is not implemented yet.


LaTeX was designed for typesetting. If you're going to use it for mathematical calculation too then you should consider the sagetex package. It's using the power of a computer algebra system SAGE allows you to calculations and plot and place them anywhere you want. In the case of tables you can have Sage typeset them for you (as in the example below) which saves a lot of time and eliminates mistakes. The sagetex package requires you to have access to Sage. You can get that through a free Sagemath Cloud account or you can install Sage locally on your computer.

f(x) = sin(x*pi/180.)
g(x) = cos(x*pi/180.)
h(x) = tan(x*pi/180.)
m(x) = tan(x)

output = ""
output += r"\begin{tabular}{ccccccccc} "
output += r" degrees & sine & cosine & tangent & & degrees & sine & cosine &   tangent \\ \hline "
for i in range(1, 5):
    output += r"%d & %8.4f & %8.4f & %8.4f & & %d & %8.4f & % 8.4f & %12.4f  \\ "%(i, f(i), g(i), h(i), i+45, f(i+45), g(i+45), h(i+45))
output += r"\end{tabular}"
You can do the traditional table entering data cell by cell:\\
$\sage{f(45).n(digits=5)}$ & $\sage{cos(pi/3).n(digits=4)}$ &   $\sage{log(8,2).n(digits=4)}$\\
 $\sage{ln(7).n(digits=4)}$ & $\sage{m(pi/3).n(digits=4)}$ &      $\sage{exp(2).n(digits=5)}$\\ 

Or you can do calculations inline:
What's the value of $e^{5}$? It's $\sage{(e^5)}$. That's not helpful.
What is it as a decimal? It's $\sage{(e^5).n(digits=8)}$.

What's $\log_2(8)$? It's $\sage{log(8,2)}$. 

Here is a screenshot of the code running in Sagemath Cloud: enter image description here

Note that the for loop beginning with for i in range(1, 5): produces 4 lines of the table because i must be less than the last number. You can change 5 to a bigger number and have Sage create the table for you.

  • Using python could be a more familiar programming way to me, good to have pointed this possibility to use sage. Does it require -shell-escape ?
    – Togh
    Nov 22, 2014 at 21:00
  • Sagetex gives you both Python and Sage commands. It requires -shell-escape but if you're using Sagemath Cloud then everything is taken care of automatically.
    – DJP
    Nov 22, 2014 at 22:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .