3

I have two spreadtab tabulars, and I want some of the values calculated in the first one to be reused in the second one.

I like the tag(savedValue) method that allows me to save values from the tabular and reuse later in the text with \STtag{savedValue} with fancy names and a not so bad readability.

It works well in the texts, but not if I put them in an other tabular with the value to be executed (I want to make calculations again in the second tabular).

Here is a MWE:

\documentclass{article}
\usepackage{spreadtab}

\begin{document}

\begin{spreadtab}{{tabular}{c}}
    10tag(savedValue)
\end{spreadtab}

\begin{spreadtab}{{tabular}{c}}
    \STtag{savedValue}
\end{spreadtab}

\end{document}

The tabular is displayed according to my needs, but it gives a lot of errors that I do not understand: http://pastebin.com/a31RCUh7 (my text editor, TexStudio, use the 'nonstopmode')

Missing = inserted for \ifnum. \end{spreadtab}
  1. Am I using the right package for my needs (spreadtab, I need to make simple calculations in an 'exel' style and use theses values from one tabular to the other)?
  2. How could I correct this error? What am I doing wrong?
  3. Can I ask LaTeX to ignore this particular error (as the display seems correct and errors spamming more important errors I may make).

3 Answers 3

4

The best approach is to define a new macro-function. Its name could be value(<tag>):

EDIT: the list \ST@functions@with@assign@argument must be updated too.

\documentclass{article}
\usepackage{spreadtab}
\makeatletter
\newcommand\ST@func@value[2]{%
    \ifcsname ST@celltag@\detokenize\expandafter{#1}\endcsname
        \expandafter\let\expandafter#2\csname ST@celltag@\detokenize\expandafter{#1}\endcsname
    \else
        \PackageWarning\ST@package@name{The tag "\detokenize\expandafter{#1}" does not exists, have you defined it?}%
        \def#2{0}% use 0 if tag undefined
    \fi
}
\edef\ST@functions@with@text@arg{\ST@functions@with@text@arg,value}
\edef\ST@functions@no@calc@arg{\ST@functions@no@calc@arg,value}
\edef\ST@functions@list{\ST@functions@with@range@arg,\ST@functions@with@num@arg,\ST@functions@with@text@arg}
\edef\ST@functions@with@assign@argument{\ST@functions@with@assign@argument,value}
\makeatother
\begin{document}

\begin{spreadtab}{{tabular}{cc}}
    10tag(savedValue)&tag(foobar1)20
\end{spreadtab}

\begin{spreadtab}{{tabular}{cc}}
    value(savedValue)&value(foobar1)*2
\end{spreadtab}
\end{document}
4
  • See my edit, I forgot to update a list.
    – unbonpetit
    Commented Nov 7, 2014 at 15:37
  • 1
    I use your solution in my document, it works well. I saw that if I want to use the numerical value in text mode, I have to use \STtag{} and for the calculated mode value(). So for both in one cell: \STtag{name}= :={value(name)}. I think the macro you made here could be added to the spreadtab package (I discovered you are the author of it when I searched to email you this solution).
    – Togh
    Commented Nov 8, 2014 at 17:39
  • An other thing that may be interesting to add would be the possibility to pass entire column/row from one tabular to the other.
    – Togh
    Commented Nov 8, 2014 at 17:50
  • Thanks, you saved me here ! @unbonpetit, as @Togh said, this macro should be added to the spreadtab package, this is a must have.
    – Sylver
    Commented Dec 25, 2017 at 19:19
5

spreadtab doesn't seem very robust if you have tab references within the cell. You can hide the reference in a macro:

\documentclass{article}
\usepackage{spreadtab}

\begin{document}

\begin{spreadtab}{{tabular}{c}}
    10tag(savedValue)
\end{spreadtab}

\newcommand\foo{\STtag{savedValue}}


\begin{spreadtab}{{tabular}{c}}
\foo
\end{spreadtab}

\end{document}
2

There is an other way to export data from the tabular:

\documentclass{article}
\usepackage{spreadtab}

\begin{document}

\begin{spreadtab}[\STsavecell\savedValue{a1}]{{tabular}{c}}
    10
\end{spreadtab}

\begin{spreadtab}{{tabular}{c}}
\savedValue
\end{spreadtab}

\end{document}

This way do not generate error and may be simpler than putting the \STtag{} in a new command.

It has the main drawbacks that it do not allow as fancy names as tag() (tag allows me to end name with number), and that I find it less visual to manage with all the different names (I would like to reuse several columns from the first tabular to the second one).

1
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – yo'
    Commented Nov 7, 2014 at 9:11

You must log in to answer this question.

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