Luc*_*ryn 101 markdown latex pandoc
最近,我开始使用Pandoc降价,似乎一个很好的替代乳胶,因为我的文档没有很多的数学公式,我没有用乳胶任何经验,这与小于2周提交截止日期相结合,使得它一个很好的解决方案.
有一件事我一直没能恢复过来是如何迫使它离开页面空的休息,谁能帮助?
Luc*_*ryn 125
看起来像pandoc markdown使用标准的LaTeX标签用于此目的:
\newpage 和 \pagebreak
tar*_*leb 15
TL; DR:使用\newpage下面的Lua过滤器以多种格式获取分页符.
Pandoc将所有输入解析为内部文档格式.该格式没有专门的方式来表示分页符,但仍有可能以其他方式对信息进行编码.一种方法是使用原始LaTeX \newpage.这在输出LaTeX(或通过LaTeX创建的pdf)时非常有效.但是,在针对HTML或docx等不同格式时会遇到问题.
定位其他格式时的一个简单解决方案是使用pandoc过滤器,该过滤器可以转换内部文档表示,以满足我们的需求.Pandoc 2.0及更高版本甚至允许使用包含的Lua解释器来执行此转换.
让我们假设我们通过\newpage插入一条像空行一样的行来指示分页符,如下所示:
lorem ipsum
\newpage
more text
Run Code Online (Sandbox Code Playgroud)
的\newpage将被解析为RawBlock包含原始的TeX.如果目标格式可以包含原始TeX(即LaTeX,Markdown,Org等),则该块仅包含在输出中.
我们可以使用简单的Lua过滤器来定位不同的格式.以下适用于docx,LaTeX,epub和轻量级标记.
--- Return a block element causing a page break in the given format.
local function newpage(format)
if format == 'docx' then
local pagebreak = '<w:p><w:r><w:br w:type="page"/></w:r></w:p>'
return pandoc.RawBlock('openxml', pagebreak)
elseif format:match 'html.*' then
return pandoc.RawBlock('html', '<div style=""></div>')
elseif format:match 'tex$' then
return pandoc.RawBlock('tex', '\\newpage{}')
elseif format:match 'epub' then
local pagebreak = '<p style="page-break-after: always;"> </p>'
return pandoc.RawBlock('html', pagebreak)
else
-- fall back to insert a form feed character
return pandoc.Para{pandoc.Str '\f'}
end
end
-- Filter function called on each RawBlock element.
function RawBlock (el)
-- check that the block is TeX or LaTeX and contains only \newpage or
-- \pagebreak.
if el.text:match '\\newpage' then
-- use format-specific pagebreak marker. FORMAT is set by pandoc to
-- the targeted output format.
return newpage(FORMAT)
end
-- otherwise, leave the block unchanged
return nil
end
Run Code Online (Sandbox Code Playgroud)
我们发布了更新,功能更新的版本.它可以从官方的pandoc lua-filters存储库中获得.
我发现这不适用于 .doc 和 .odt 格式。我发现的一个解决方法是使用文本编辑器(在我的例子中为 ibre office)插入一条水平线-----------------并格式化“水平线”样式以打破页面并使其不可见
无法编辑 LucasSeveryn 答案,告诉队列已满,因此请在此处添加一些信息。
\newpage并\pagebreak需要raw_tex扩展。
// 使用 pandoc 2.9.2.1,不适用于 docx 或 html 输出,--verbose 说
[INFO] Not rendering RawBlock (Format "tex") "\\pagebreak"
[INFO] Not rendering RawBlock (Format "tex") "\\newpage"
Run Code Online (Sandbox Code Playgroud)
https://pandoc.org/MANUAL.html#extension-raw_attribute
```{=openxml}
<w:p>
<w:r>
<w:br w:type="page"/>
</w:r>
</w:p>
```
Run Code Online (Sandbox Code Playgroud)
// 也不支持 gfm 输入格式。
// 这适用于 docx 输出,不适用于 html 输出。
这需要+raw_tex格式扩展。这并不支持 pandoc 中的所有 Markdown 变体。
https://pandoc.org/MANUAL.html#markdown-variants
Note, however, that commonmark and gfm have limited support for extensions.
Only those listed below (and smart, raw_tex, and hard_line_breaks) will work.
The extensions can, however, all be individually disabled.
Also, raw_tex only affects gfm output, not input.
Run Code Online (Sandbox Code Playgroud)
所以-f markdown会起作用,但-f gfm不起作用。
https://pandoc.org/MANUAL.html#option--from
Extensions can be individually enabled or disabled by appending
+EXTENSION or -EXTENSION to the format name.
Run Code Online (Sandbox Code Playgroud)
例如
-t html+raw_tex:输出启用raw_tex
-f markdown-raw_tex-raw_attribute:输入禁用 raw_tex 和 raw_attribute
| 归档时间: |
|
| 查看次数: |
32116 次 |
| 最近记录: |