使用 pandoc、markdown 從 Latex 模板產生 pdf 中的圖像框架邊框

使用 pandoc、markdown 從 Latex 模板產生 pdf 中的圖像框架邊框

我正在使用類似於的 tex 模板 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}}'

相關內容