4

I'm using a tex template similar to https://github.com/davecap/markdown-latex-boilerplate/blob/master/template.tex

How can I get a frame around images which are passed from standard markdown code to the tex template?

Obviously this code handles the image sizes, but how can I add the graphics frames?

$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}

2 Answers 2

5

Without editing the template, you can use the YAML metadata block to pass options that would redefine \includegraphics so that it would always add a frame, similarly to what is done here.

Take, i.e., this picture as an example, and let's call it Screenshot_20200131_230154.png:

enter image description here

Then, the following markdown file 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 }

would produce, when compiled with pandoc test.md -o test.pdf:

enter image description here

4

I didn't find how to make the yaml template work so I used @Clément's options as CLI parameters:

pandoc --pdf-engine xelatex \
    […]
    -V header-includes:'\usepackage[export]{adjustbox} \let\includegraphicsbak\includegraphics \renewcommand*{\includegraphics}[2][]{\includegraphicsbak[frame,#1]{#2}}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .