
私は次のようなTexテンプレートを使用しています https://github.com/davecap/markdown-latex-boilerplate/blob/master/template.tex
標準のマークダウン コードから 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
。
次に、次のマークダウン ファイルを作成しますtest.md
。
---
header-includes: |
\usepackage[export]{adjustbox}
\let\includegraphicsbak\includegraphics
\renewcommand*{\includegraphics}[2][]{\includegraphicsbak[frame,#1]{#2}}
---
{ width=150px height=150px }
次のようにコンパイルすると、次のようになりますpandoc test.md -o test.pdf
。
答え2
yaml テンプレートを機能させる方法が見つからなかったため、CLI パラメータとして @Clément のオプションを使用しました。
pandoc --pdf-engine xelatex \
[…]
-V header-includes:'\usepackage[export]{adjustbox} \let\includegraphicsbak\includegraphics \renewcommand*{\includegraphics}[2][]{\includegraphicsbak[frame,#1]{#2}}'