我正在使用类似于 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}}'