Skip to content

Commit d24814d

Browse files
authored
Add pdf export recipe (#1383)
1 parent 4a410d1 commit d24814d

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

docs/assets/images/pdf_output.png

102 KB
Loading

docs/user/recipes/export-to-pdf.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Export to PDF
2+
3+
This #recipe shows how to export a note to PDF.
4+
5+
## Required extensions
6+
7+
- **[vscode-pandoc](https://marketplace.visualstudio.com/items?itemName=chrischinchilla.vscode-pandoc)**
8+
9+
## Required third-party tools
10+
11+
- [Pandoc](https://pandoc.org/installing.html)
12+
- A [LaTeX distribution](https://www.latex-project.org/get/) such as TeXLive (Linux), MacTeX (MacOS), or MikTeX (Windows)
13+
14+
Check that Pandoc is installed by opening a terminal and running `pandoc --version`.
15+
16+
Check that Pandoc can produce PDFs with LaTeX by running the following in the terminal.
17+
18+
```
19+
echo It is working > test.md
20+
pandoc test.md -o test.pdf
21+
```
22+
23+
## Instructions
24+
25+
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`.
26+
27+
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`.
28+
29+
3. In VSCode, open `settings.json` for your user (or just for your workspace if you prefer), and add the following line:
30+
31+
```
32+
"pandoc.pdfOptString": "--from=markdown+wikilinks_title_after_pipe --resource-path $WORKSPACE/.pandoc --template foam --listings",
33+
```
34+
35+
Make sure to replace `$WORKSPACE/.pandoc` with the real full path to the `.pandoc` directory you created earlier.
36+
37+
4. Open a Foam note in VSCode.
38+
39+
5. Press `Ctrl` + `k`, `p`. Choose "pdf", and press `Enter`.
40+
41+
The PDF should look something like this:
42+
43+
![Sample PDF output](../../assets/images/pdf_output.png)
44+
45+
## Options
46+
47+
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.
48+
49+
If you don't want syntax highlighting and frames around the codeblocks, remove `--listings` from the `pandoc.pdfOptString` parameter in `settings.json`.
50+
51+
## Further customization
52+
53+
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`.

docs/user/recipes/recipes.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<!-- omit in toc -->
2+
23
# Recipes
34

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

6-
- [Contribute](#contribute)
7-
- [Take smart notes](#take-smart-notes)
8-
- [Discover](#discover)
9-
- [Organise](#organise)
10-
- [Write](#write)
11-
- [Version control](#version-control)
12-
- [Publish](#publish)
13-
- [Collaborate](#collaborate)
14-
- [Workflow](#workflow)
15-
- [Creative ideas](#creative-ideas)
16-
- [Other](#other)
7+
- [Recipes](#recipes)
8+
- [Contribute](#contribute)
9+
- [Take smart notes](#take-smart-notes)
10+
- [Discover](#discover)
11+
- [Organise](#organise)
12+
- [Write](#write)
13+
- [Version control](#version-control)
14+
- [Publish](#publish)
15+
- [Collaborate](#collaborate)
16+
- [Workflow](#workflow)
17+
- [Creative ideas](#creative-ideas)
18+
- [Other](#other)
1719

1820
## Contribute
1921

@@ -75,11 +77,11 @@ A #recipe is a guide, tip or strategy for getting the most out of your Foam work
7577
- Publish using community templates
7678
- [[publish-to-netlify-with-eleventy]] by [@juanfrank77](https://github.com/juanfrank77)
7779
- [[generate-gatsby-site]] by [@mathieudutour](https://github.com/mathieudutour) and [@hikerpig](https://github.com/hikerpig)
78-
7980
- Make the site your own by [[publish-to-github]].
8081
- Render math symbols, by either
8182
- adding client-side [[math-support-with-mathjax]] to the default [[publish-to-github-pages]] site
8283
- adding a custom Jekyll plugin to support [[math-support-with-katex]]
84+
- Export note to PDF [[export-to-pdf]]
8385

8486
## Collaborate
8587

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

0 commit comments

Comments
 (0)