Skip to content

Commit

Permalink
Add pdf export recipe (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hegghammer authored Aug 15, 2024
1 parent 4a410d1 commit d24814d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 12 deletions.
Binary file added docs/assets/images/pdf_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions docs/user/recipes/export-to-pdf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Export to PDF

This #recipe shows how to export a note to PDF.

## Required extensions

- **[vscode-pandoc](https://marketplace.visualstudio.com/items?itemName=chrischinchilla.vscode-pandoc)**

## Required third-party tools

- [Pandoc](https://pandoc.org/installing.html)
- A [LaTeX distribution](https://www.latex-project.org/get/) such as TeXLive (Linux), MacTeX (MacOS), or MikTeX (Windows)

Check that Pandoc is installed by opening a terminal and running `pandoc --version`.

Check that Pandoc can produce PDFs with LaTeX by running the following in the terminal.

```
echo It is working > test.md
pandoc test.md -o test.pdf
```

## Instructions

1. Create a folder in your workspace named `.pandoc`. Take note of the full path to this directory. The rest of this recipe will refer to this path as `$WORKSPACE/.pandoc`.

2. Download the template file [`foam.latex`](https://raw.githubusercontent.com/Hegghammer/foam-templates/main/foam.latex) from [Hegghammer/foam-templates](https://github.com/Hegghammer/foam-templates) and place it in `$WORKSPACE/.pandoc`.

3. In VSCode, open `settings.json` for your user (or just for your workspace if you prefer), and add the following line:

```
"pandoc.pdfOptString": "--from=markdown+wikilinks_title_after_pipe --resource-path $WORKSPACE/.pandoc --template foam --listings",
```

Make sure to replace `$WORKSPACE/.pandoc` with the real full path to the `.pandoc` directory you created earlier.

4. Open a Foam note in VSCode.

5. Press `Ctrl` + `k`, `p`. Choose "pdf", and press `Enter`.

The PDF should look something like this:

![Sample PDF output](../../assets/images/pdf_output.png)

## Options

If you include a name in the `author` parameter in the YAML of the Foam note, that name will feature in the PDF header on the top left.

If you don't want syntax highlighting and frames around the codeblocks, remove `--listings` from the `pandoc.pdfOptString` parameter in `settings.json`.

## Further customization

If you know some LaTeX, you can [tweak](https://bookdown.org/yihui/rmarkdown-cookbook/latex-template.html) the `foam.latex` template to your needs. Alternatively, you can supply another ready-made template such as [Eisvogel](https://github.com/Wandmalfarbe/pandoc-latex-template); just place the `TEMPLATE_NAME.latex` file in `$WORKSPACE/.pandoc`. You can also use all of Pandoc's [other functionalities](https://learnbyexample.github.io/customizing-pandoc/) by tweaking the `pandoc.pdfOptString` parameter in `settings.json`.
27 changes: 15 additions & 12 deletions docs/user/recipes/recipes.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<!-- omit in toc -->

# Recipes

A #recipe is a guide, tip or strategy for getting the most out of your Foam workspace!

- [Contribute](#contribute)
- [Take smart notes](#take-smart-notes)
- [Discover](#discover)
- [Organise](#organise)
- [Write](#write)
- [Version control](#version-control)
- [Publish](#publish)
- [Collaborate](#collaborate)
- [Workflow](#workflow)
- [Creative ideas](#creative-ideas)
- [Other](#other)
- [Recipes](#recipes)
- [Contribute](#contribute)
- [Take smart notes](#take-smart-notes)
- [Discover](#discover)
- [Organise](#organise)
- [Write](#write)
- [Version control](#version-control)
- [Publish](#publish)
- [Collaborate](#collaborate)
- [Workflow](#workflow)
- [Creative ideas](#creative-ideas)
- [Other](#other)

## Contribute

Expand Down Expand Up @@ -75,11 +77,11 @@ A #recipe is a guide, tip or strategy for getting the most out of your Foam work
- Publish using community templates
- [[publish-to-netlify-with-eleventy]] by [@juanfrank77](https://github.com/juanfrank77)
- [[generate-gatsby-site]] by [@mathieudutour](https://github.com/mathieudutour) and [@hikerpig](https://github.com/hikerpig)

- Make the site your own by [[publish-to-github]].
- Render math symbols, by either
- adding client-side [[math-support-with-mathjax]] to the default [[publish-to-github-pages]] site
- adding a custom Jekyll plugin to support [[math-support-with-katex]]
- Export note to PDF [[export-to-pdf]]

## Collaborate

Expand Down Expand Up @@ -140,6 +142,7 @@ _See [[contribution-guide]] and [[how-to-write-recipes]]._
[publish-to-github]: ../publishing/publish-to-github.md "Publish to GitHub"
[math-support-with-mathjax]: ../publishing/math-support-with-mathjax.md "Math Support"
[math-support-with-katex]: ../publishing/math-support-with-katex.md "Katex Math Rendering"
[export-to-pdf]: export-to-pdf.md "Export to PDF"
[real-time-collaboration]: real-time-collaboration.md "Real-time Collaboration"
[capture-notes-with-drafts-pro]: capture-notes-with-drafts-pro.md "Capture Notes With Drafts Pro"
[capture-notes-with-shortcuts-and-github-actions]: capture-notes-with-shortcuts-and-github-actions.md "Capture Notes With Shortcuts and GitHub Actions"
Expand Down

0 comments on commit d24814d

Please sign in to comment.