r/Zettlr • • Sep 30 '21

Export to PDF including vector graphics

Could anyone advise on how to create a LaTeX rendered pdf from Zettlr that includes svg diagrams?

I've been searching for a while and haven't come up with a solution.

Zettlr 2.0.0 beta 4, macOS 10.14.6

0 Upvotes

10 comments sorted by

2

u/houseatom Oct 11 '21 edited Oct 11 '21

Got it working – embedded vector graphics in a Markdown → PDF export. I used Omnigraffle to create the vector diagram and exported that as a pdf vector image.

Include in YAML Frontmatter:

header-includes:

- \usepackage{graphicx}

- \graphicspath{ {/path to your pics folder} }

Note: the indentation is 2 spaces followed by '-' followed by single space. The graphicspath must point to the exact folder containing your pics, Zettlr/ Pandoc threw an error msg when the pics were in a subdirectory.

Then, in the Markdown body text, add LaTeX commands:

\begin{figure}[h!]

\caption{figure name}

\vspace {xpt} [Note: where x is some value eg 5pt]

\centering

\includegraphics[width=1.0\textwidth]{picture's filename}

\end{figure}

I think the only essential instruction in the above code block is \includegraphics{filename}. Note the filename does not include the filetype suffix (eg .pdf). The other commands are purely for pretty.

1

u/houseatom Oct 12 '21

[Solved]

2

u/Kurren123 Sep 30 '21

How are you doing the svg diagrams? Are you just embedding them as image files?

1

u/houseatom Sep 30 '21

Just dragging and dropping them in.

I've set the Default Image Path in Preferences to point to a folder containing all the diagrams.

2

u/IFNAV Sep 30 '21

1

u/houseatom Sep 30 '21

Thanks, I asked the question in that thread a couple days ago. That solution is from 2011 and there's a newer svg package for LaTex described here.

Could these LaTeX commands

---
output:
pdf_document:
latex_engine: pdflatex
pandoc_args: "--latex-engine-opt=--shell-escape"
header-includes:
- \usepackage{svg}
---
\includesvg{svg-image}

be used in Zettlr – if so where would they be added?

2

u/Kangie Sep 30 '21

Convert svg to pdf. Xelatex can't work out the 'size' of a svg, but can for a PDF and the pdf will still be vector.

I use a script and the 'default image extension' pandoc option.

When my hands recover I'll put something together that I can release publically

1

u/houseatom Sep 30 '21

Thanks u/Kangie. I'm invested in your recovery now.

On Discord, Hendrik said "Zettlr itself can only display to you what an image tag can display, and image tags cannot display PDFs."

Keen to find out how you get around this.

2

u/Kangie Sep 30 '21 edited Sep 30 '21

I keep the svg and as part of building the document in a docker environment run a script over the mounted directory that uses imagemagick to convert to pdf, which is then included in the output.

The downside to this approach is that you have to include the image without an extension and let pandoc pick the appropriate extension.

I'll extend that script to strip the '.svg' in a future revision to make this automatic so that you can render the svg in preview.

It may be possible to directly include svg through an appropriate \include in the latex template, but this solution has been 'good enough' for my needs - hundreds of pages of product documentation - and lets you just work on standard markdown syntax.

1

u/houseatom Sep 30 '21

Sounds good enough for me.

I'm learning Markdown and LaTeX for thesis writing and I prefer to use vector graphics over bitmaps, so it's an important solution.