summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-01-20 23:20:06 +0000
committerKarl Berry <karl@freefriends.org>2014-01-20 23:20:06 +0000
commitc2221082bf4a9e1c5b6218fcabb401b07112add8 (patch)
treec7b774a0370902ee41e97090e44a5583469b852c /Master/texmf-dist/tex
parentc22509075f62a577b84ac0a4260769351460fd14 (diff)
odsfile (20jan14)
git-svn-id: svn://tug.org/texlive/trunk@32742 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty62
1 files changed, 55 insertions, 7 deletions
diff --git a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty
index b4c7f617e18..6ec21d15860 100644
--- a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty
+++ b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty
@@ -26,7 +26,12 @@ rowseparator=[[\\n]]
}{%
\luaexec{rowseparator="\luatexluaescapestring{#1}"}
}
-
+\define@key{includespread}{columnbreak}{%
+ \luaexec{columnbreak="\luatexluaescapestring{\unexpanded{#1}}{}"}
+}
+\define@key{includespread}{coltypes}{%
+ \luaexec{coltypes="\luatexluaescapestring{\unexpanded{#1}}"}
+}
\define@choicekey*+{includespread}{columns}[\val\nr]{head,top,none}{%
\ifcase\nr\relax%
\luaexec{columns=1}%
@@ -84,22 +89,60 @@ rowtemplate=nil
columns=nil
currenttemplate = nil
rowtemplate = nil
+ columnbreak = "\\linebreak{}"
+ coltypes = nil
}%
\setkeys{includespread}{#1}%
\luaexec{%
body = odsreader.getTable(odsfile,sheetname)
local values = odsreader.tableValues(body,range[1],range[2],range[3],range[4])
%-- Conversion of odsfile table values to LaTeX tabular
- local rowValues = function(row)
+ local concatParagraphs = function(column)
+ if type(column) =="table" then
+ return table.concat(column, columnbreak), true
+ end
+ return column, false
+ end
+ local rowValues = function(row, headings)
+ local headings = headings or {}
local t={}
- for _,column in pairs(row) do table.insert(t,column.value) end
- return t
+ local i = 1
+ for _,column in pairs(row) do
+ local value, br = concatParagraphs(column.value)
+ table.insert(t,value)
+ headings[i] = br
+ i = i + 1
+ end
+ return t, headings
+ end
+ local makeColtypes = function(h)
+ local maxsize = tex.hsize / 65536
+ local h = h or {}
+ local p = 0
+ for _, c in pairs(h) do
+ if c then p = p + 1 end
+ end
+ if p > 0 then
+ local j = {}
+ local size = tostring(math.floor(maxsize / \#h)) .. "pt"
+ for _, c in pairs(h) do
+ local k = "l"
+ if c then k = "p{"..size.."}" end
+ j[\#j+1]= k
+ end
+ return table.concat(j)
+ else
+ return string.rep("l",\#h)
+ end
end
if rowtemplate == nil then
+ local headings = {}
+ local currow = {}
currenttemplate = currenttemplate or "default"
content = {}
for i,row in pairs(values) do
- table.insert(content,table.concat(rowValues(row)," & "))
+ currow, headings = rowValues(row, headings)
+ table.insert(content,table.concat(currow," & "))
end
%-- Column headings handling
local colheading=""
@@ -111,8 +154,13 @@ rowtemplate=nil
columns = rowValues(t[1])
end
if type(columns) == "table" then colheading = table.concat(columns," & ") .. "\\\\" end
- coltypes = ""
- if type(content)== "table" then coltypes= string.rep("l",\#content[1]) end
+ % coltypes = ""
+ if type(content)== "table" then
+ % coltypes= string.rep("l",\#content[1])
+ if not coltypes then
+ coltypes = makeColtypes(headings)
+ end
+ end
tex.print(odsreader.interp(templates[currenttemplate],{content=table.concat(content, "\\\\ "..rowseparator),coltypes=coltypes,colheading=colheading,rowsep=rowseparator}))
else
local content = {}