texlive[68201] Master/texmf-dist: odsfile (7sep23)

commits+karl at tug.org commits+karl at tug.org
Thu Sep 7 22:15:22 CEST 2023


Revision: 68201
          http://tug.org/svn/texlive?view=revision&revision=68201
Author:   karl
Date:     2023-09-07 22:15:22 +0200 (Thu, 07 Sep 2023)
Log Message:
-----------
odsfile (7sep23)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/odsfile/odsfile.pdf
    trunk/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex
    trunk/Master/texmf-dist/doc/lualatex/odsfile/pokus.ods
    trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua
    trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty

Modified: trunk/Master/texmf-dist/doc/lualatex/odsfile/odsfile.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex	2023-09-07 20:15:13 UTC (rev 68200)
+++ trunk/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex	2023-09-07 20:15:22 UTC (rev 68201)
@@ -8,7 +8,7 @@
 \author{Michal Hoftich (\url{michal.h21 at gmail.com})}
 \title{The \textsf{odsfile} package:\\
 accessing of the \textsf{opendocument spreadsheet} from \LaTeX{}
-documents\thanks{Version 0.7, last revisited 2022-12-13.}
+documents\thanks{Version 0.8, last revisited 2023-09-07.}
 }
 \usepackage[english]{babel}
 \lstloadlanguages{[LaTeX]Tex} 
@@ -36,7 +36,7 @@
 Their contents can be read as \LaTeX{} tables, can be pass to macros,
  you can also add new data to existing spreadsheets.
 
-\ods format consist of number of |xml| files packed in the |zip| file. 
+The \ods format consist of number of |xml| files packed in the |zip| file. 
 This package uses \LuaTeX's zip library, LuaXML library\footnote{Pure |lua| library 
 for working with |xml| files, it is available form CTAN or \url{https://github.com/michal-h21/LuaXML}} and lua scripting to read |xml| content from this archive, 
 which means that it is not possible to use this package with pdf\LaTeX{} or \XeLaTeX. 
@@ -205,7 +205,27 @@
 
 \end{description} 
 
+\subsection{Character escaping}
 
+To prevent compilation errors, \textsf{odsfile} escapes characters that have special meaning in \LaTeX, 
+for example backslashes or dollar characters. In some cases, you may want to
+execute the \TeX\ code that is saved in the spreadsheet. In that case, use the \texttt{escape} option:
+
+\begin{description}
+
+\item[escape] Set the value to false to ignore special characters in the cell data.
+\end{description}
+
+The following example prints the left cell in the last row in table in bold, because the original 
+spreadsheet contains the \verb|\textbf{bold}| command.
+
+\begin{LTXexample}
+\begin{tabular}{lll}
+\includespread[sheet=List1,columns=head,escape=false]
+\end{tabular}     
+\end{LTXexample}
+
+
 \section{Templates}\label{sec:tpl}
 
 If you don't want to specify tabular environment by hand, you can use simple templating mechanism to insert tabular environment by hand. 
@@ -272,7 +292,7 @@
 
 You can explicitly load \ods file with \marginpar{\cmd{\loadodsfile}}\cmd{\loadodsfile}\oarg{key val list}\marg{filename}. This can be useful, if you only want to write some data to the file, otherwise it is better to use \cmd{\includespread}.
 
-For saving spreadsheets modified with |AddRow|, you can use \cmd{\savespreadsheet}\marginpar{\cmd{\savespreadsheet}}. This command uses call to external |zip| utility, so you should have installed it and you have to call lua\LaTeX with |lualatex --shell-escape filename|. Lua\LaTeX also must have write permissions for accessing the \ods file. This command creates file |content.xml| in the current directory, so if externall call fails, you can run
+For saving spreadsheets modified with |AddRow|, you can use \cmd{\savespreadsheet}\marginpar{\cmd{\savespreadsheet}}. This command uses call to external |zip| utility, so you should have installed it and you have to call Lua\LaTeX\ with |lualatex --shell-escape filename|. Lua\LaTeX\ also must have write permissions for accessing the \ods file. This command creates file |content.xml| in the current directory, so if externall call fails, you can run
 \begin{verbatim}
 zip -r filename.ods content.xml
 \end{verbatim} 
@@ -381,6 +401,13 @@
 \section{Changes}
 
 \begin{description}
+  \item[v0.8]
+    \begin{itemize}
+      \item added the escape option for enabling or disabling of the character escaping
+      \item fixed handling of merged cells in ranges
+      \item fixed escaping of backslashes
+      \item fixed row insertion
+    \end{itemize}
    \item[v0.7]
      \begin{itemize}
        \item Fixed character escaping. Unescaped ``\%,\#,\$, \_ and \&'' characters will be escaped to prevent compilation errors.

Modified: trunk/Master/texmf-dist/doc/lualatex/odsfile/pokus.ods
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua	2023-09-07 20:15:13 UTC (rev 68200)
+++ trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua	2023-09-07 20:15:22 UTC (rev 68201)
@@ -42,7 +42,8 @@
       
       for i = 1, #val do
         local r = val[i]
-        local rowRep = r["_attr"]["table:number-rows-repeated"] or 1
+        local rattr = r["_attr"] or {}
+        local rowRep = rattr["table:number-rows-repeated"] or 1
 
         row = {}
         row["_attr"] = r["_attr"]
@@ -214,19 +215,23 @@
 end
 
 function escape(s)
-  return string.gsub(s, "([%\\]?)([#%%%$&_%{%}%\\|])", function(a,b)
-    if a=="" then 
-      if b == "\\" then
-        return "\\textbackslash"
-      elseif b == "|" then
-        return "\\textbar"
-      else
-        return "\\"..b 
+  if latexescape=="true" then
+    return string.gsub(s, "([%\\]?)([#%%%$&_%{%}%\\|])", function(a,b)
+      if a=="" then 
+        if b == "\\" then
+          return "\\textbackslash{}"
+        elseif b == "|" then
+          return "\\textbar{}"
+        else
+          return "\\"..b 
+        end
+      elseif a=="\\" and b=="\\" then
+        return "\\textbackslash\\textbackslash{}"
       end
-    elseif a=="\\" and b=="\\" then
-        return "\\textbackslash\\textbackslash"
-    end
-  end)
+    end)
+  else
+    return s
+  end
 end
 
 get_link = function(val)
@@ -268,6 +273,7 @@
     cells = {},
     -- Generic function for inserting cell
     addCell = function(self,val, attr,pos)
+      local attr = attr or {}
       if pos then
         table.insert(self.cells,pos,{["text:p"] = val, ["_attr"] = attr})
         self.pos = pos
@@ -298,7 +304,7 @@
       return #sheet["table:table-row"]+1
     end,
     insert = function(self, sheet, pos)
-      local t = {}
+      local t = {_attr = {}}
       local pos = pos or self:findLastRow(sheet)
       print("pos je: ",pos)
       if sheet["table:table-column"]["_attr"] and sheet["table:table-column"]["_attr"]["table:number-columns-repeated"] then
@@ -307,9 +313,9 @@
         table_columns = #sheet["table:table-column"]
       end
       for i=1, table_columns do
-        table.insert(t,self.cells[i] or {})  
+        table.insert(t,self.cells[i] or {_attr={}})  
       end
-      t = {["table:table-cell"]=t}
+      t = {["table:table-cell"]=t, _attr = {}}
       table.insert(sheet["table:table-row"],pos,t)
     end
   }

Modified: trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty	2023-09-07 20:15:13 UTC (rev 68200)
+++ trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty	2023-09-07 20:15:22 UTC (rev 68201)
@@ -1,6 +1,6 @@
 % Package odsfile. Author Michal Hoftich <michal.h21 at gmail.com>
 % This package is subject of LPPL license, version 1.3c
-\ProvidesPackage{odsfile}[2022/12/13 v0.7 odsfile package to select cells from ODS sheets and
+\ProvidesPackage{odsfile}[2023/09/07 v0.8 odsfile package to select cells from ODS sheets and
       typeset them as LaTeX tables]
 \RequirePackage{luacode,xkeyval,xparse}
 
@@ -13,6 +13,7 @@
 \define at key{includespread}{rowtemplate}{\luaexec{rowtemplate="\luatexluaescapestring{\detokenize{#1}}"}}%
 \define at key{includespread}{celltemplate}{\luaexec{celltpl="\luatexluaescapestring{\detokenize{#1}}"}}%
 \define at key{includespread}{multicoltemplate}{\luaexec{multicoltpl="\luatexluaescapestring{\unexpanded{#1}}"}}%
+\define at key{includespread}{escape}{\luaexec{latexescape="\luatexluaescapestring{\unexpanded{#1}}"}}%
 
 \newcommand\OdsNl{\\}
 \newcommand\OdsLastNl{\\}
@@ -72,6 +73,7 @@
 rowtemplate = nil
 celltpl   = "-{value}"
 multicoltpl = "\\multicolumn{-{count}}{l}{-{value}}"
+latexescape = "true"
 \end{luacode*}
 
 \newcommand\loadodsfile[2][]{%
@@ -112,6 +114,7 @@
     celltpl = "-{value}"
     columnbreak = "\\linebreak{}"
     coltypes    = nil
+    latexescape = "true"
   }%
   \setkeys{includespread}{#1}%
   \luaexec{%
@@ -142,7 +145,8 @@
         else
           value = odsreader.interp(celltpl, {value = value})
         end
-        table.insert(t,value)
+        % table.insert(t,value)
+        t[i] = value
         headings[i] = br
         i = i + x
       end
@@ -251,6 +255,8 @@
 \luaexec{%
 body = body or odsreader.getTable(odsfile)
 row:insert(body,pos)%
+% we must save the updated table to the original table
+odsfile.root["office:document-content"]["office:body"]["office:spreadsheet"]["table:table"] = body%
 }%
 }
 



More information about the tex-live-commits mailing list.