On 4/11/2018 2:15 a.m., Graeme wrote:
The spreadtab module is extremely useful, as it provides a wrapper around a conventional table environment, to enable some spreadsheet-like capabilities within the table (using the LaTeX package spreadtab).
It can be downloaded from wiki.lyx.org/Layouts/Modules.

When creating a long(multipage) table within the sLTable environment provided by the spreadtab module, there is one small difference between the plain LaTeX code produced by LyX 2.3.0 and 2.3.1.
Specifically, LyX 2.3.0 exports the lines:
    \sLTable{}{%
    \begin{longtable}{|c|c|c|c|c|}
while LyX 2.3.1 exports the lines
    \sLTable{}{%
    \begin{longtable}[c]{|c|c|c|c|c|}

In practice I think the LyX 2.3.1 version is correct, but it exposes a bug in spreadtab module version 1.4, which cannot handle the optional [c] argument following \begin{longtable}.

Thus LyX 2.3.0 can successfully generate a PDF file, while LyX 2.3.1 fails with a LaTeX error. This applies to LyX under both Windows 10 with MikTeX, and Linux Mint with TeXLive 2017.

An example LyX file is attached, along with the PDF file generated successfully from it using File/Export/PDF(ps2pdf) with LyX 2.3.0.

Unfortunately, I am not sure how to fix the bug in the spreadtab module, so help on this would be welcome.

Graeme
I've attached the new module which works with longtables now, and also "normal" tables -- the tabular environment with or without the optional vertical alignment  argument. The documentation also needs updating. When that's done I'll make a zip file of both module and documentation and make them available from the wiki as before.

The spreadtab documentation nowhere mentions longtables. I suspect the author of that package  would be suprised to find someone contemplating using it for tables big enough to break across pages. He writes "... the 3 stages [of pdf compilation] described above take time, and above all, fp is slow in its calculations. The spreadtab environment leads to much slower
compilation than with a classical table."

(But then, perhaps he would think that that is just the sort of thing a LyX user would do. He is scathing of LyX, and of people who use LyX. To add to my sins, I wrote to him in English. Thrice a sinner.)

Andrew


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
#\DeclareLyXModule[spreadtab.sty,fp.sty,xstring.sty]{Spreadtab}
# DescriptionBegin
# Adds commands which give LyX tables spreadsheet capabilities
# (minimum example: adding a column of figures). Tables are
# built in LyX using its table toolbar facilities. Instant
# preview allows the calculated values to be viewed in LyX. 
# DescriptionEnd
#
# spreadtab.module v.2.0 2018-11-05
#
# Assumes at least version 0.4a of spreadtab.sty and 
# will fail with 0.3 and earlier versions. Also assumes
# LyX 2.2.x or later. 
#
# Author: Andrew Parsloe  ajpars...@gmail.com
#
Format 60

AddToPreamble
\usepackage{spreadtab}

% for LyX, instead of \\
\STeol{\tabularnewline}

% default text cell marker is @ but ` is neater
\renewcommand{\STtextcell}{`}

% to avoid 18 places of decimals
\STautoround{4}

% pattern-matching macros to turn LyX tables into spreadtab tables
% #1=save cell, #2=new col format
% opt arg: #4=environment, #5=[,          #6=remainder
% none:    #4=environment, #5=col. format #6=remainder
\def\sLt@b[#1]#2#3\begin#4#5#6\end#7%
  {%
    \def\sLtmpb{#2}#3%
    \if#5[
      \ifx\sLtmpb\empty
        \sLlt@bopt[#1]{#4}#5#6\endspreadtab%
      \else
        \sLlt@boptreform[#1]{#2}#4#5#6\endspreadtab%
      \fi
    \else
      \ifx\sLtmpb\empty
        \sLt@bnone[#1]{#4}{#5}#6\endspreadtab%
      \else%
        \sLt@bnonereform[#1]{#2}{#4}{#5}#6\endspreadtab%
      \fi
    \fi
  }

\def\sLlt@bopt[#1]#2[#3]#4#5{\sLt@bsubst{#1}{#2}{#3}{#4}{#5}}
\def\sLlt@boptreform[#1]#2#3[#4]#5#6{\sLt@bsubst{#1}{#3}{#4}{#2}{#6}}
\def\sLt@bnone[#1]#2#3#4{\sLt@bsubst{#1}{#2}{}{#3}{#4}}
\def\sLt@bnonereform[#1]#2#3#4#5{\sLt@bsubst{#1}{#3}{}{#2}{#5}}

\def\sLt@bsubst#1#2#3#4#5{\spreadtab[#1]{{#2}[#3]{#4}}#5}

EndPreamble

Style sLTable
  Category      Tables
  LatexType       Command
  LatexName       sLTable
  Argument        1
    LabelString   "New column formatting"
  End
  Argument        2
    LabelString  "Cell contents"
    Mandatory     1
  End
  Align           Center
  PassThruChars    *^\
  Preamble
  \newcommand{\sLTable}[3][]{\sLt@b[#2]{#1}#3}
  EndPreamble
End
  
InsetLayout Flex:sLSaveCell
  LyXType      custom
  LatexType       Command
  LatexName       sLSaveCell
  ContentAsLabel  1
  Decoration    Classic
  LabelFont
    Color      phantomtext
  EndFont
  LabelString    Save
  Multipar      0
  PassThru      1
  ResetsFont    0
  Preamble
    \newcommand\sLSaveCell[1]{\sLs@vecell#1}
    \def\sLs@vecell#1,#2{\STsavecell{#2}{#1}}
    EndPreamble
End

InsetLayout Flex:sLRetrieve
  LyXType      custom
  LatexType       Command
  LatexName       sLRetrieve
  ContentAsLabel  1
  Decoration    Classic
  LabelFont
    Color      phantomtext
  EndFont
  LabelString    Ret
  Multipar      0
  PassThru      1
  ResetsFont    0
  Preamble
  \newcommand\sLRetrieve[1]{$#1$}
  EndPreamble
End

InsetLayout Flex:sLNumberFormat
  LyXType      custom
  LatexType       Command
  LatexName       sLNumFormat
  ContentAsLabel  1
  Decoration    Classic
  LabelFont
    Color      phantomtext
  EndFont
  LabelString    NFmt
  Multipar      0
  PassThru      0
  ResetsFont    0
  Preamble
    \newcommand\sLNumFormat[1]{\sLdofm@t#1}
    \def\sLdofm@t#1,#2{\if0#2\STautoround*{#1}\else\STautoround{#1}\fi}
  EndPreamble
End

Reply via email to