4

I recently started using the spreadtab package. This generally works well, but it has the following limitation, and probably other similar ones.

If one is tagging a cell (using tag), and then wants to reference the tagged value (using value), the tag needs to precede the value in the file. If value precedes tag it will not work.

TeX handles such things by saving state to a file, normally an aux file. But it seems the author chose not to go that route.

I was wondering if there were technical difficulties in implementing an approach like that, or if it was simply a matter of the author's preferences.

Among other benefits, this would also obviate the distinction between local and global tagging.

To illustrate the tagging issue, see

\documentclass[12pt]{scrlttr2}
\usepackage{spreadtab}
\begin{document}

\begin{spreadtab}{{tabular}{c}} value(foo)\ \end{spreadtab}

\begin{spreadtab}{{tabular}{c}} tag(foo)1\ \end{spreadtab} \end{document}

When compiled with pdflatex using spreadsheet 0.5, this gives the error:

! Undefined control sequence.
<write> 
Package \ST@package@name 
                                   Warning: The tag "\detokenize \expandafte...
l.7 \end{spreadtab}

?

If the tag is defined in a spreadtab which is inside a group, that requires special handling to be visible - one has to make the tag global. But if one was to save state to file that should not be necessary either.

\documentclass[12pt]{scrlttr2}
\usepackage{spreadtab}
\makeatletter
\def\ST@package@name{spreadtab}                               
\makeatother
\begin{document}

\begingroup \begin{spreadtab}{{tabular}{c}} tag(foo)1\ \end{spreadtab} \STmakegtag{foo}
\endgroup

\begin{spreadtab}{{tabular}{c}} value(foo)\ \end{spreadtab}

\end{document}

With @touhami's correction, this gives the warning

Package spreadtab Warning: The tag "foo" does not exists, have you defined it? 
on input line 23.
Faheem Mitha
  • 7,778
  • By the way, the error chowen here is unrelated it just a forgotten definition. One can add \makeatletter\def\ST@package@name{spreadtab}\makeatother. – touhami Aug 23 '21 at 19:52
  • @touhami Can you elaborate? A forgotten definition by who? – Faheem Mitha Aug 23 '21 at 20:03
  • FaheemMitha by the package's author, I suppose. If you add the line suggested by @touhami after loading the package, you'll see the real error: lilla.tex|9 warning| Package spreadtab Warning: The tag "foo" does not exists, have you defined it? on input line 9. [sic] – Rmano Aug 23 '21 at 20:06
  • @Rmano. Oh, so I should submit a bug report? I tried to register for the custom site on which the bug tracker is. It said I needed to get permission, but I never heard anything after that. I'll check the site again, and if it is still not working, I'll send an email. Thanks. – Faheem Mitha Aug 24 '21 at 06:24
  • Ah yes, I see. There is a line \PackageWarning\ST@package@name{The tag "\detokenize\expandafter{#1}" does not exists, have you defined it?} in spreadtab.sty which gets called. But \ST@package@nameis never actually defined. And it should be "exist". – Faheem Mitha Aug 24 '21 at 06:33
  • I have an account on framagit, so I created it: https://framagit.org/unbonpetit/spreadtab/-/issues/3 – Rmano Aug 24 '21 at 07:44
  • Thanks @Rmano. Appreciate the effort. – Faheem Mitha Aug 24 '21 at 08:59

1 Answers1

4

You can write the values to the aux file, this warns on the first pass that the tag is not defined, but on the second pass it is

\documentclass[12pt]{scrlttr2}
\usepackage{spreadtab}
\makeatletter
\def\ST@package@name{spreadtab}

\def\STsave#1{\immediate\write@auxout{% \global\string@namedef{\string\detokenize{ST@celltag@\detokenize\expandafter{#1}}}% {\csname ST@celltag@\detokenize\expandafter{#1}\endcsname}}}

\makeatother \begin{document}

\begin{spreadtab}{{tabular}{c}} value(foo)\ \end{spreadtab}

\begin{spreadtab}{{tabular}{c}} tag(foo)1\ \end{spreadtab} \STsave{foo}

\end{document}

David Carlisle
  • 757,742
  • I was not expecting a solution to this. I thought I would just get some comments. But this fixes the two examples above (I just added one.) Two questions. One, is this a general solution, and if so, why didn't the author do it this way before? And two, shouldn't this \STsave be part of the tag function? That way it would be handled automatically. – Faheem Mitha Aug 24 '21 at 10:18
  • @FaheemMitha you have to ask the author "Why" questions but I thought I saw that tag() was handled in a pre-parse and didn't expand to anything in the cell, you can not write to a file as an expandable operation so writing at that point may affect spacing or break things completely. But not sure about that, I don't know the package at all. – David Carlisle Aug 24 '21 at 10:30
  • also you'd probably have to ban using the same tag name in two tables as this would just save teh value of the last one and make it available from the start of the docuemnt which would be well defined but weird. – David Carlisle Aug 24 '21 at 10:32