Pandoc:颜色、风格和技巧

Pandoc is a very handy tool to create PDF documents from MarkDown files.

Pandoc是一个非常方便的工具,可以从MarkDown文件创建PDF文件。

Its workflow is very similar to LaTeX (and indeed, by default, it uses it to convert to PDF), but less verbose and a bit easier to write.

它的工作流程与LaTeX非常相似(事实上,在默认情况下,它使用LaTeX来转换为PDF),但没有那么多废话,也更容易编写。

However, soon you will face the limits of MarkDown, such as the lack of colors, and you’ll start to introduce bad LaTeX code for this or that feature.

然而,很快你就会面临MarkDown的限制,比如缺乏颜色,你会开始为这个或那个功能引入糟糕的LaTeX代码。

Let’s see a better way to solve the problem.

让我们看看解决这个问题的更好方法。

LUA filters

LUA过滤器

Pandoc supports LUA filters as preprocessor for the documents: with them you can create custom elements that will change various aspects of the document.

Pandoc支持LUA过滤器作为文档的预处理器:用它们可以创建自定义元素,改变文档的各个方面。

You just need to put the .lua script in your document’s folder, and pass the --lua-filter=filter.lua option to the Pandoc command line.

你只需要把.lua 脚本放在你的文档的文件夹里,并在Pandoc命令行中传递--lua-filter=filter.lua 选项。

A complete guide to write LUA filters for Pandoc can be found here.

为Pandoc编写LUA过滤器的完整指南可以在这里找到。

Colors!

颜色!

MarkDown doesn’t support colors. Our LUA filter would parse for a particular keyword (e.g. color), and insert the LaTeX command. The script below also converts colors for HTML documents.

MarkDown不支持颜色。我们的LUA过滤器将解析一个特定的关键词(例如:color ),并插入LaTeX命令。下面的脚本也可以转换HTML文档的颜色。

Span = function(el) color = el.attributes['color'] if color == nil then return el end if FORMAT:match 'html' then el.attributes['color'] = nil el.attributes['style'] = 'color: ' .. color .. ';' return el elseif FORMAT:match 'latex' then el.attributes['color'] = nil table.insert( el.content, 1, pandoc.RawInline('latex', '\\textcolor{'..color..'}{') ) table.insert( el.content, pandoc.RawInline('latex', '}') ) return el.content else return el end
end

You also have to include the directive \usepackage{xcolor} in your document.

你还必须在你的文件中包括指令\usepackage{xcolor}

To do this, either create a style.tex file with the above instruction, included with -H style.tex option, or by ...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.124.0. UTC+08:00, 2024-04-25 12:50
浙ICP备14020137号-1 $访客地图$