使用pandoc将docx转换为pdf时出错



我对pandoc不是很熟悉,我只是用这个工具来转换一些文档的文件类型。我通常使用这个命令pandoc --pdf-engine=xelatex -V linkcolor:blue -V CJKmainfont="Songti SC" X.docx -o X.pdf,它适用于大多数文档。。。。但最近,我得到了以下";错误消息"。。。

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

如果你需要更多信息,请告诉我。。。但也许你需要告诉我怎么。。。我不是技术。。。感谢您对的帮助

谢谢@tarleb,有问题的表的Html是这样的:

<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>

下面是一个pandoc-Lua过滤器,它应该有助于使用LaTeX编译文档:它打开嵌套表并将它们合并到顶级表中。

代码不是特别漂亮,而且并没有为嵌套表提供通用解决方案,但在当前情况下应该可以正常工作。

过滤器可以通过将其保存到文件unnest-table.lua,然后通过--lua-filter=unnested-table.lua将其传递给pandoc来使用。

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

最新更新