2

similar to this question I want to use a function inside of a spreadtab region, but i do not want to use it out of a separate file but just simplify the usage and readability.

Unfortunately the usage of \newcommand, \def and \edef does not expand the text into the region and therefore the text is not recognized by spreadtab as normal.

My first idea would be to be able to make a textual macro such as in C-Programming by #define

The command that I currently have in the non-working state is this:

\newcommand*{\pos}[4]{ :={#1} &@ #2 &@ #3 & :={#4}\,\EUR & :={[-4,0]*[-1,0]}\,\EUR\\}

This would be exactly what I would want to insert into the spreadtab region. It corresponds to one line of the table. The output when using pos with

\pos{5}{text}{description}{10}

then is

:=5    @text    @description   10€       :=[-4,0]*[-1,0]€

instead of the expected line that I get when inserting the text directly into the spreadtab region:

5.00   text     description    10.00€    50.00€

Is there a possibility to create something like a C-Macro where the text is inserted before the 'compilation'? Or is there any other command I could use to simplify the usage without having to write all formatting issues again and again?

Thanks in advance.

1 Answer 1

3

If the tabular body contains \+{<argument>}, then the <argument> is expanded once:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{spreadtab,xpatch,eurosym}
\def\EUR{\geneuro}
\makeatletter
\def\spreadtab@ii{\IfSubStr\ST@tab{\noexpand\+}{\expandafter\spreadtab@iii\ST@tab\@nil}{}}
\def\spreadtab@iii#1\+#2#3\@nil{\edef\ST@tab{\unexpanded{#1}\unexpanded\expandafter{#2#3}}\spreadtab@ii}%
\xpretocmd\spreadtab@i\spreadtab@ii{}{}
\makeatother
\begin{document}
\newcommand*\pos[4]{ :={#1} &@ #2 &@ #3 & :={#4}\,\EUR & :={[-4,0]*[-1,0]}\,\EUR\\}

\begin{spreadtab}{{tabular}{*5c}}\hline
    \+{\pos{5}{text}{description}{10}}
    \+{\pos{9}{foo}{bar}{31}}\hline
\end{spreadtab}
\end{document}
2
  • This is almost great. Except when my LaTeX source file contains \usepackage[whatever]{babel}, all hell breaks loose with Missing = inserted for \ifnum.. Any idea to solve this ? Sep 16, 2015 at 5:05
  • \edef\pos#1#2#3#4{ \string:={#1} &@ #2 &@ #3 & \string:={#4}\noexpand\,\noexpand\EUR & \string:={[-4,0]*[-1,0]}\noexpand\,\noexpand\EUR\noexpand\\}
    – unbonpetit
    Sep 22, 2015 at 18:39

You must log in to answer this question.

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