Error when Using pandoc convert docx to pdf

Viewed 46

I am not very familiar with pandoc , I just use this tool to convert some docs' file type. I normally use this command pandoc --pdf-engine=xelatex -V linkcolor:blue -V CJKmainfont="Songti SC" X.docx -o X.pdf And it works for most docs.... But recently, I got the following "Error message"...

Error producing PDF.
! Forbidden control sequence found while scanning use of \LT@nofcols.
<inserted text>
                \par
l.987 ...width - 0\tabcolsep) * \real{1.0000}}@{}}

If you need any more info , pls let me know...but maybe you need to tell me how... I am not techy... Thanks for you help

Thanks @tarleb, and the problematic table's Html goes like this:

<table>
<colgroup>
<col style="width: 67%" />
<col style="width: 32%" />
</colgroup>
<thead>
<tr class="header">
<th><ol type="1">
<li><blockquote>
<p>zhu</p>
</blockquote></li>
</ol>
<blockquote>
<p>由于J上有韵母er,且er为e开头,则zhu的按键为Qj</p>
</blockquote></th>
<th></th>
</tr>
<tr class="odd">
<th><ol start="2" type="1">
<li><blockquote>
<p>zhua</p>
</blockquote></li>
</ol>
<blockquote>
<p>由于Q上的ua、iu都不是a、e开头的韵母,则zhua的按键为Fq</p>
</blockquote></th>
<th><table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th>Q <strong>zh</strong></th>
</tr>
<tr class="odd">
<th><strong>ua</strong></th>
</tr>
<tr class="header">
<th><strong>iu</strong></th>
</tr>
</thead>
<tbody>
</tbody>
</table></th>
</tr>
<tr class="header">
<th><ol start="3" type="1">
<li><blockquote>
<p>cha</p>
</blockquote></li>
</ol>
<blockquote>
<p>由于S上的a为a、e本身开头的韵母,则cha的按键为Ws</p>
</blockquote></th>
<th><table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th>S <strong>zh</strong></th>
</tr>
<tr class="odd">
<th><strong>a</strong></th>
</tr>
<tr class="header">
<th><strong>ia</strong></th>
</tr>
</thead>
<tbody>
</tbody>
</table></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
1 Answers

Below is a pandoc Lua filter that should help to get the document compiled with LaTeX: it unwraps the nested tables and merges them into the top-level table.

The code isn't particularly pretty, and it does not offer a general solution for nested tables, but should work ok in the case at hand.

The filter can be used by saving it to a file unnest-table.lua and then passing it to pandoc via --lua-filter=unnested-table.lua.

local function allrows (tbl)
  local rows = pandoc.List{}
  rows:extend(tbl.head.rows)
  tbl.bodies:map(function (body) rows:extend(body.body) end)
  rows:extend(tbl.foot.rows)
  return rows
end

local function nested_rows (cell)
  local tbl = cell.contents[1]
  if tbl and tbl.t == 'Table' then
    return allrows(tbl)
  end
  return nil
end

function Table (tbl)
  local newhead = pandoc.TableHead()
  for i, row in ipairs(tbl.head.rows) do
    for j, cell in ipairs(row.cells) do
      local currow = row:clone()
      local nested_rows = nested_rows(cell)
      if nested_rows and #nested_rows > 0 then
        for jj=1, j-1 do
          currow.cells[jj].row_span = row.cells[jj].row_span + #nested_rows - 1
        end
        local firstnested = table.remove(nested_rows, 1)
        -- assume the nested table only has a single row
        currow.cells[j] = firstnested.cells[1]
        newhead.rows:insert(currow)
        newhead.rows:extend(nested_rows)
        goto continue
      end
    end
    newhead.rows:insert(row)
    ::continue::
  end
  tbl.head = newhead
  return tbl
end
Related