![使用 pandoc、markdown 从 latex 模板生成 PDF 中的图像框架边框](https://linux22.com/image/348133/%E4%BD%BF%E7%94%A8%20pandoc%E3%80%81markdown%20%E4%BB%8E%20latex%20%E6%A8%A1%E6%9D%BF%E7%94%9F%E6%88%90%20PDF%20%E4%B8%AD%E7%9A%84%E5%9B%BE%E5%83%8F%E6%A1%86%E6%9E%B6%E8%BE%B9%E6%A1%86.png)
我正在使用类似于 https://github.com/davecap/markdown-latex-boilerplate/blob/master/template.tex
如何获取从标准 markdown 代码传递到 tex 模板的图像周围的框架?
显然,此代码处理图像大小,但我如何添加图形框架?
$if(graphics)$
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
$endif$
...
\begin{document}
$body$
\end{document}
答案1
无需编辑模板,您可以使用YAML 元数据块传递重新定义的选项\includegraphics
,以便始终添加框架,与这里所做的类似。
以此图为例,我们称之为Screenshot_20200131_230154.png
:
然后,以下 markdown 文件test.md
:
---
header-includes: |
\usepackage[export]{adjustbox}
\let\includegraphicsbak\includegraphics
\renewcommand*{\includegraphics}[2][]{\includegraphicsbak[frame,#1]{#2}}
---
![](Screenshot_20200131_230154.png){ width=150px height=150px }
编译后会产生pandoc test.md -o test.pdf
:
答案2
我没有找到如何使 yaml 模板工作,因此我使用@Clément 的选项作为 CLI 参数:
pandoc --pdf-engine xelatex \
[…]
-V header-includes:'\usepackage[export]{adjustbox} \let\includegraphicsbak\includegraphics \renewcommand*{\includegraphics}[2][]{\includegraphicsbak[frame,#1]{#2}}'