cagix / pandoc-lecture

Pandoc Markdown Lecture Template: This project defines a skeleton repo for creating lecture slides and handouts including lecture notes out of Pandoc Markdown (https://pandoc.org/MANUAL.html) using a single source approach.
MIT License
100 stars 18 forks source link

Table compatibility with pandoc 2.11 #7

Open fpopineau opened 3 years ago

fpopineau commented 3 years ago

Hi,

Just found this very nice package and when trying it, I hit this problem with pandoc 2.11.1 where exams could not be generated. Error:

Error running filter ../filters/exams.lua:
PandocLuaError "Error during function call: ../filters/exams.lua:55: attempt to index a nil value (field 'align')\nstack traceback:\n\t../filters/exams.lua:55: in function <../filters/exams.lua:29>\n\t[C]: in ?\n\t[C]: in field 'walk_block'\n\t../filters/exams.lua:88: in function 'solution'"

I was able to fix it with this simple patch:

diff --git a/filters/exams.lua b/filters/exams.lua
index 7197ac4..be050ee 100644
--- a/filters/exams.lua
+++ b/filters/exams.lua
@@ -26,7 +26,7 @@ end

 -- transform markdown table to simple latex tabular
-local function mdtabletotabular(el)
+local function mdtabletotabular(elt)
     -- returns (list of) `Block` (since `Table` is of type `Block`)

     local function addcell(tab, cell)
@@ -48,6 +48,9 @@ local function mdtabletotabular(el)
         tab[#tab] = pandoc.RawBlock("latex", "\\\\\\hline")
     end

+    -- FP: the parameter is a Table, but afterwards is treated as a SimpleTable
+    local el = pandoc.utils.to_simple_table(elt)
+
     -- alignments: pandoc to tex
     local align = { [pandoc.AlignDefault] = "c", [pandoc.AlignLeft] = "l", [pandoc.AlignRight] = "r", [pandoc.AlignCenter] = "c" }

Thank you for this package.

cagix commented 3 years ago

Yeah, unfortunately the internal representation of tables has changed with pandoc 2.10(?). I haven't had time to adopt the lua-filter. However, the exams should work with pandoc 2.9.x. Sorry for this inconvenience.

The rest of the package already works with Pandoc 2.11.x :-)