这个问题有一个可能的解决方案,但它适用于 ConTeXt 编写器,我无法使用它。
ConTeXt:如何更改 Pandoc 生成的块引用的背景颜色和边框?
有什么 LaTeX 解决方案可以实现相同的目的?
编辑:在 debian wheezy 系统上,pandoc 版本为 1.9.4.2。这是从pandoc -V geometry:a4paper -V geometry:margin=2cm test.md -o test.tex
\section{Test 1}
\subsection{Test 2}
\ldots{} this is a test.
\begin{verbatim}
Block
quote
123
\end{verbatim}
\ldots{} more text.
我不使用自定义模板。如果我将\startsetups framedsetups
链接中的示例 (...) 放入文件 framedtext.tex 中并通过 -H 包含它,我会得到(是的,我知道我必须更改环境verbatim
而不是blockquote
):
>$ pandoc -H framedtext.tex -V geometry:a4paper -V geometry:margin=2cm test.md -o test.pdf
pandoc: Error producing PDF from TeX source.
! Undefined control sequence.
l.39 \startsetups
答案1
如果您要生成 LaTeX 文档,只需使用 LaTeX 代码即可。一个非常简单的例子:
% mystylefile.pandoc
\usepackage{tcolorbox}
\newtcolorbox{myquote}{colback=red!5!white, colframe=red!75!black}
% redefine the 'quote' environment to use this 'myquote' environment
\renewenvironment{quote}{\begin{myquote}}{\end{myquote}}
然后是 markdown 文件:
<!-- test.md -->
This is not a block quote.
> This question has a possible solution, but it's for the ConTeXt writer, which I can't use.
> ConTeXt: How to change the background color and border of a Pandoc-generated blockquote?
> What would be a LaTeX solution to achieve the same?
This is not a block quote.
然后是以下这一pandoc
行:
pandoc -H mystylefile.pandoc -V geometry:a4paper -V geometry:margin=2cm test.md -o test.tex
如果您没有修改该latex.template
文件(请参阅这里有关如何修改它的一些提示),你最终应该得到一个.tex
如下所示的文件:
\documentclass[]{article}
% Note: I have cut out all the default stuff that ends up here
% to highlight what the effects are of including `mystylefile.sty`
\usepackage{tcolorbox}
\newtcolorbox{myquote}{colback=red!5!white, colframe=red!75!black}
\renewenvironment{quote}{\begin{myquote}}{\end{myquote}}
% Other default stuff removed
\begin{document}
This is not a block quote.
\begin{quote}
This question has a possible solution, but it's for the ConTeXt writer,
which I can't use. ConTeXt: How to change the background color and
border of a Pandoc-generated blockquote? What would be a LaTeX solution
to achieve the same?
\end{quote}
This is not a block quote.
\end{document}
这是快速破解方法。更好的解决方案是创建一个latex.template
文件并使用该文件(如果我没记错的话,这就是开关-D
的用途)。
答案2
使用jon 的回答使用最新版本的 pandoc,我能够将命令放在 markdown 本身的前言中,header-includes:
如下所示:
metadata.yml
:
header-includes:
- \usepackage{tcolorbox}
- \newtcolorbox{myquote}{colback=red!5!white, colframe=red!75!black}
- \renewenvironment{quote}{\begin{myquote}}{\end{myquote}}
在 markdown 中使用:
> Here's a blockquote
PDF 结果: