After reading this amazing answer, I'm wondering if it possible to do the same thing but the other way round, that is create a LibreOffice spreadsheet from luatex, exporting data from the tex
file to the spreadsheet.
The example I have in mind is: say I'm typesetting the solution of an exam with a documentclass that defines a macro \answer
to be used in the following context.
\documentclass{myclass}
\begin{document}
\section{Test 1}
\begin{enumerate}
\item The \answer{definition of entropy} states that \answer{$S = k_B
\ln \Omega$}.
\end{enumerate}
\end{document}
I grade my students with a LibreOffice spreadsheet. So I'd like luatex
to create (or modify) a spreasheet so I can have automatically something like in the screenshot below.
I understand that a lua interface to LibreOffice does not exist. So I see three ways here:
- Creating a zip file from scratch meeting the
.ods
standard. - Using some magic to interface LibreOffice API with luatex (with LuaJava?).
- Using some perl or other kind of magic to do the job.
As @canaaerus suggested in comments, I could export things from tex
with a csv file but I'd like to have a real .ods
out of the box so that I could have style information (like bold face, centered text, etc.) and formulas.
Best Answer
Edit 14-08-2012 New version of
odsfile
incorporates ideas from this answer. It is now possible to use following code:Package is now included in
TeX Live
andxml
library is distributed separately http://ctan.org/pkg/luaxml, so now it can be used by other packages.This is my solution using
lualatex
and development version of odsfile. First of all, I created serialization function fromLuaXML
tables toxml
.Code
outputs
Then there is small library for adding contents to ods file,
exams.lua
It has one function and one object.
updateZip(zipfile, updatefile)
tries to run zip utility, which have to be installed in your system. Unfortunately, I have some problems with access rights on my computer, so it doesn't work here. Instead, I just run this command from commandline using generatedxml
and it works just fine.newRow() returns object with some methods:
addCell(val,attr,pos)
addString(val,attr,pos)
addNumber(val,attr,pos)
these methods add columns into row.addCell
is generic one and should not be used. attr is array with attributes, you can leave it empty.pos
means position of the column in the row, it can also benil
insert(sheet, pos)
this function insert row to the sheet, you can specify row position withpos
Now some simple
LaTeX
package,exams.sty
This package defines three user commands and one environment:
\examspreadsheet{odsfile}{sheet}
loads sheet from file. you can leftsheet
blank, then first sheet will be selected\answer{text}
add row to the spreadsheet\savespreadsheet
saves sheet to theods file
exam
all answers should be inside it, at end, it saves filecontent.xml
in the current directory.Note: there is some spurious space in definition of
\answer
, that I cannot find.Now some sample file:
Compile with
If you get error message in the console output like:
then you have to change file permissions of the
ods
file to enable writing for other users, or simply run commandAnd the result in
openoffice calc
: