texlive[72514] Master/texmf-dist: odsfile (10oct24)
commits+karl at tug.org
commits+karl at tug.org
Thu Oct 10 21:42:04 CEST 2024
Revision: 72514
https://tug.org/svn/texlive?view=revision&revision=72514
Author: karl
Date: 2024-10-10 21:42:04 +0200 (Thu, 10 Oct 2024)
Log Message:
-----------
odsfile (10oct24)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/lualatex/odsfile/odsfile.pdf
trunk/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex
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 2024-10-10 19:41:38 UTC (rev 72513)
+++ trunk/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex 2024-10-10 19:42:04 UTC (rev 72514)
@@ -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.8, last revisited 2023-09-07.}
+documents\thanks{Version 0.9, last revisited 2024-10-10.}
}
\usepackage[english]{babel}
\lstloadlanguages{[LaTeX]Tex}
@@ -84,7 +84,8 @@
format similar to spreadsheet processors, like |a2:c4|, selecting cells
starting at first column, second row and ending and third column, fourth row.
Other variant of supported ranges are \textit{named ranges}, which can be
- saved in the |ods file|.
+ saved in the |ods file|. You can specify multiple ranges to be included, separated
+ by comma, but in this case the range specification must be surrounded by braces: |{a1:b1,a3:b3}|.
\begin{LTXexample}
\begin{tabular}{lll}
@@ -111,6 +112,12 @@
\end{LTXexample}
\begin{LTXexample}
+\begin{tabular}{ll}
+\includespread[range={b1:c1,b3:c}]
+\end{tabular}
+\end{LTXexample}
+
+\begin{LTXexample}
\begin{tabular}{lll}
\includespread[range=newrangetest]
\end{tabular}
@@ -163,6 +170,9 @@
\end{tabular}
\end{LTXexample}
+\item[newline] Code that will be inserted instead of |\\| between rows. Default value is |\OdsNl|.
+\item[lastnewline] Code inserted after the last row. Default value is |\OdsLastNl|.
+
\item[template] Templates are simple mechanism to insert whole tabular environment with column specification. All columns are aligned to the left, if you want to do more advanced stuff with column specifications, you must enter them manually as in all previous examples.
\begin{LTXexample}
\includespread[columns=top,template=booktabs,range=a3]
@@ -225,7 +235,21 @@
\end{tabular}
\end{LTXexample}
+\subsection{Saving the generated table to a file}
+Use the \texttt{save} option to save the generated table to a file instead of including it directly into the document.
+
+\begin{LTXexample}
+There should be no table listed
+\includespread[sheet=List1,columns=head,escape=false,save=save-test.tex,debug=true]
+\end{LTXexample}
+
+\subsection{Debugging}
+
+You can print the generated table to the terminal output of \LaTeX\ using the \texttt{debug} option. Possible values are
+\texttt{true} and \texttt{false}.
+
+
\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.
@@ -401,6 +425,12 @@
\section{Changes}
\begin{description}
+ \item [v0.9]
+ \begin{itemize}
+ \item added the \texttt{save} and \texttt{debug} options
+ \item added support for multiple ranges in the \texttt{range} option
+ \item added \texttt{newline} and \texttt{lastnewline} options
+ \end{itemize}
\item[v0.8]
\begin{itemize}
\item added the escape option for enabling or disabling of the character escaping
Modified: trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua 2024-10-10 19:41:38 UTC (rev 72513)
+++ trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua 2024-10-10 19:42:04 UTC (rev 72514)
@@ -162,8 +162,15 @@
return t
end
+function join(tbl1, tbl2)
+ for _, x in ipairs(tbl2) do
+ tbl1[#tbl1+1] = x
+ end
+ return tbl1
+end
+
function getRange(range)
- if range == nil then return {nil,nil,nil,nil} end
+ if range == nil then return {{nil,nil,nil,nil}} end
local range = namedRanges[range] or range
local r = range:lower()
local function getNumber(s)
@@ -175,10 +182,12 @@
end
return f
end
+ local ranges = {}
for x1,y1,x2,y2 in r:gmatch("(%a*)(%d*):*(%a*)(%d*)") do
- return {getNumber(x1),tonumber(y1),getNumber(x2),tonumber(y2)}
+ ranges[#ranges+1] = {getNumber(x1),tonumber(y1),getNumber(x2),tonumber(y2)}
--print(string.format("%s, %s, %s, %s",getNumber(x1),y1,getNumber(x2),y2))
end
+ return ranges
end
function table_slice (values,i1,i2)
@@ -329,6 +338,12 @@
print ("Updating an ods file.\n" ..command .."\n Return code: ", os.execute(command))
end
+function save(filename, content)
+ local f = io.open(filename, "w")
+ f:write(content)
+ f:close()
+end
+
M.load= load
M.loadContent = loadContent
M.getTable= getTable
@@ -336,6 +351,7 @@
M.getColumnCount= getColumnCount
M.loadNameRanges= loadNameRanges
M.tableValues= tableValues
+M.join = join
M.getRange= getRange
M.getNumber= getNumber
M.table_slice = table_slice
@@ -352,5 +368,6 @@
M.insert = insert
-- for updateing the archive. Depends on external zip utility
M.updateZip= updateZip
+M.save = save
return M
Modified: trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty 2024-10-10 19:41:38 UTC (rev 72513)
+++ trunk/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty 2024-10-10 19:42:04 UTC (rev 72514)
@@ -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}[2023/09/07 v0.8 odsfile package to select cells from ODS sheets and
+\ProvidesPackage{odsfile}[2024/10/10 v0.9 odsfile package to select cells from ODS sheets and
typeset them as LaTeX tables]
\RequirePackage{luacode,xkeyval,xparse}
@@ -35,6 +35,15 @@
\define at key{includespread}{columnbreak}{%
\luaexec{columnbreak="\luatexluaescapestring{\unexpanded{#1}}{}"}%
}
+
+\define at key{includespread}{save}{%
+ \luaexec{odssave="\luatexluaescapestring{#1}"}%
+}
+
+\define at key{includespread}{debug}{% use either true or false
+ \luaexec{odsdebug=\luatexluaescapestring{#1}}%
+}
+
\define at key{includespread}{coltypes}{%
\luaexec{coltypes="\luatexluaescapestring{\unexpanded{#1}}"}%
}
@@ -57,7 +66,16 @@
}%
}{}%
+\define at key{includespread}{newline}{%
+ \luaexec{odsnl="\luatexluaescapestring{\unexpanded{#1}}"}%
+}
+\define at key{includespread}{lastnewline}{%
+ \luaexec{odslastnl="\luatexluaescapestring{\unexpanded{#1}}"}%
+}
+
+
+
% Variable initialization and helper functions
\begin{luacode*}
odsreader = require("odsfile")
@@ -67,6 +85,8 @@
columns = nil
templates = {}
row = {}
+odssave = nil
+odsdebug = nil
body = nil
odsfilename = ""
currenttemplate = nil
@@ -74,6 +94,8 @@
celltpl = "-{value}"
multicoltpl = "\\multicolumn{-{count}}{l}{-{value}}"
latexescape = "true"
+odsnl = "\\OdsNl"
+odslastnl = "\\OdsLastNl"
\end{luacode*}
\newcommand\loadodsfile[2][]{%
@@ -110,6 +132,8 @@
rowseparator = ""
columns=nil
currenttemplate = nil
+ odssave = nil
+ odsdebug = false
rowtemplate = nil
celltpl = "-{value}"
columnbreak = "\\linebreak{}"
@@ -119,8 +143,11 @@
\setkeys{includespread}{#1}%
\luaexec{%
body = odsreader.getTable(odsfile,sheetname)
- local real_range = odsreader.getRange(range)
- local values = odsreader.tableValues(body,real_range[1],real_range[2],real_range[3],real_range[4])
+ local ranges = odsreader.getRange(range)
+ local values = {}
+ for _, real_range in ipairs(ranges) do
+ values = odsreader.join(values, odsreader.tableValues(body,real_range[1],real_range[2],real_range[3],real_range[4]))
+ end
%-- Conversion of odsfile table values to LaTeX tabular
local concatParagraphs = function(column)
% -- second returned value signalize whether cell contain paragraph, or not
@@ -189,10 +216,13 @@
columns = rowValues(values[1])
content = odsreader.table_slice(content,2,nil)
elseif type(columns) == "number" and columns == 2 then
- local t = odsreader.tableValues(body,real_range[1],1,real_range[3],2)
+ local t = {}
+ for _, real_range in ipairs(ranges) do
+ t = odsreader.join(t, odsreader.tableValues(body,real_range[1],1,real_range[3],2))
+ end
columns = rowValues(t[1])
end
- if type(columns) == "table" then colheading = table.concat(columns," & ") .. "\\OdsNl " end
+ if type(columns) == "table" then colheading = table.concat(columns," & ") .. odsnl .. " " end
% coltypes = ""
if type(content)== "table" then
% coltypes= string.rep("l",\#content[1])
@@ -200,10 +230,16 @@
coltypes = makeColtypes(headings)
end
end
- content = table.concat(content, "\\OdsNl "..rowseparator) .. "\\OdsLastNl"
+ content = table.concat(content, odsnl .. " " ..rowseparator) .. odslastnl
local result = odsreader.interp(templates[currenttemplate],{content=content,coltypes=coltypes,colheading=colheading,rowsep=rowseparator})
- print(result)
- tex.print(result)
+ if odsdebug then
+ print(result)
+ end
+ if odssave then
+ odsreader.save(odssave, result)
+ else
+ tex.sprint(result)
+ end
else
local content = {}
currenttemplate = currenttemplate or "empty"
@@ -212,8 +248,14 @@
end
content = table.concat(content,rowseparator)
local result = odsreader.interp(templates[currenttemplate],{content=content,coltypes=coltypes,colheading=colheading,rowsep=rowseparator})
- print(result)
- tex.sprint(result)
+ if odsdebug then
+ print(result)
+ end
+ if odssave then
+ odsreader.save(odssave, result)
+ else
+ tex.sprint(result)
+ end
end
}%
}%
More information about the tex-live-commits
mailing list.