You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/lessons/6b_pdfgeneration.md
+1-42Lines changed: 1 addition & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,45 +47,4 @@ Rather than specifying the extension, you can just use the file name and an aste
47
47
48
48
For YouTube clips and online interactive materials embedded through iframes, you can make use of plugins.
49
49
See for instance the [iframe-to-thumbnail plugin](https://github.com/jupyter-book/myst-plugins/tree/main/plugins/iframe-to-thumbnail-pdf).
50
-
This plugin replaces the iframe with a thumbnail image that links to the original content as well as a QR code and a link in the caption.
51
-
52
-
## Additional Considerations
53
-
54
-
**WIP**
55
-
56
-
### Excluding and including sections for PDF[^1]
57
-
[^1]: Directly copied from the official [Myst documentation](https://mystmd.org/guide/creating-pdf-documents#excluding-content-from-specific-exports).
58
-
59
-
60
-
If you need to inject some LaTeX or Typst-specific content into their respective exports, you may use the {raw:latex} or {raw:typst} role and directive.
61
-
For example, to insert a new page in Typst with two columns:
Copy file name to clipboardExpand all lines: content/lessons/6c_pdfoutput.md
+74-34Lines changed: 74 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,55 +6,76 @@ numbering:
6
6
7
7
# Create a PDF 🌶
8
8
9
-
**outline**
10
-
- Install Typst and confirm availability on CLI
11
-
- generate a PDF using default setup (`lapreprint-typst`)
12
-
- set up and use `plain_typst_book`
13
-
- set up GHA
14
-
- play with configuration of website to use PDF
9
+
With a general understanding of document creation using MyST and our choice to use Typst for PDF generation, you are ready to create a PDF from your book repository using Jupyter Book.
15
10
11
+
In this lesson, we will:
12
+
- Install Typst (or use it within a GitHub Action workflow if working online-only)
13
+
- Generate a PDF using the `lapreprint-typst` template
14
+
- Set up and use the `plain_typst_book` template
15
+
- Modify the GitHub Action workflow to generate a PDF
16
+
- Explore how the PDF can be customized and shared via the book website
16
17
17
-
With a general understanding of document creation using MyST and our choice to use Typst for PDF generation, you are ready to create a PDF from your book repository using Jupyter Book.
18
+
```{warning}
19
+
To complete this lesson locally, you will need to install Typst. If this is not possible, or you are following the online-only path, you can complete the exercises using GitHub Actions. The exercises in this lesson use **Local** and **GitHub Actions** to distinguish instructions for each case.
20
+
```
18
21
19
22
## Install Typst
20
23
21
-
::::{tab-set}
22
-
:::{tab-item} Locally
23
24
To produce a PDF output locally, you need to have Typst installed on your system.
24
25
25
26
````{exercise} Install Typst
26
-
Follow [these steps](xref:myst/creating-pdf-documents#typst-install) to install Typst locally.
27
+
28
+
::::{tab-set}
29
+
:::{tab-item} Local
30
+
31
+
Install Typst using the nstructions available at the [Typst GitHub repo](https://github.com/typst/typst?tab=readme-ov-file#installation) and Jupyter Book 2 context is provided [here](xref:myst-guide/creating-pdf-documents#typst-install).
27
32
28
33
Check whether Typst is correctly installed by running the following command in your terminal:
29
34
30
35
```console
31
36
typst --version
32
37
```
33
-
34
-
````
35
38
:::
36
39
:::{tab-item} GitHub Actions
37
-
If you are not working locally, you will need to use GHA to generate your PDF. You can proceed through this lesson sequentially, however, skip the steps that ask you to build the PDF using your CLI. Once you have updated your `myst.yml` file to use the `plain_typst_book` you can set up GHA to build and view the PDF.
38
40
39
-
**WIP**: these instructions need improvement.
41
+
Until you get to the Lesson "PDF output with GH Actions" you won't be generating PDF's, but you can still learn how the template is defined and used by Juypter Book.
42
+
40
43
:::
41
44
::::
42
-
45
+
````
43
46
44
47
## Generate a PDF
45
48
46
-
:::{exercise} Generate a PDF using the CLI
47
-
**WIP**
48
-
- generate a PDF using the command line (will use `lapreprint-typst`)
49
-
- answer questions (bullet list below)
50
-
- look at the output. Can we do better? (yes)
49
+
Once Typst is installed and available in your terminal it can be used with Jupyter Book to generate a PDF file.
51
50
52
-
The template is...
53
-
The PDF is found...
54
51
52
+
````{exercise} Generate a PDF of your book
53
+
54
+
::::{tab-set}
55
+
:::{tab-item} Local
56
+
57
+
Generate a PDF using the command `jupyter book build --pdf`.
58
+
59
+
View the PDF and observe how the contents of your website are formatted in the PDF document.
60
+
61
+
Next, review the contents of the `myst.yml` file and answer the following questions:
62
+
- What template is being used?
63
+
- Where is the PDF output file saved after being generated?
64
+
:::
65
+
:::{tab-item} GitHub Actions
66
+
67
+
Review the contents of the `myst.yml` file and answer the following questions:
68
+
- What template is being used?
69
+
- Where is the PDF output file saved after being generated?
55
70
:::
71
+
::::
72
+
````
56
73
57
74
75
+
```{tip} Good practice with PDFs and Git
76
+
Git is not intended for use with binary files like PDF's. When working with PDF's locally you may be tempted to commit the generated file to your repository, especially if you intend to share your work online. However, this will lead to unecessary large Git workspace and is not recommended. For this reason the `.gitignore` file already ignores PDF files, and the upcoming exercise with GH Actions illustrates how a PDF can be generated online and saved as a downloadable artifact, rather than committing it to the repository.
77
+
```
78
+
58
79
## Change the PDF template
59
80
60
81
As seen in the previous exercise, the PDF generated by the `lapreprint-typst` template is not ideal for rendering content designed as a website made with the `book-theme`. Luckily, another Typst template is available: [the Plain Typst Book `plain_typst_book`](https://github.com/myst-templates/plain_typst_book) (not yet listed on the MyST Templates GH Organization). An example YAML snippet that implements this in the `myst.yml` file is illustrated here:
@@ -72,15 +93,24 @@ As seen in the previous exercise, the PDF generated by the `lapreprint-typst` te
72
93
```
73
94
74
95
75
-
:::{exercise} Implement the `plain_typst_book` template in your book
76
-
**WIP**
77
-
change, generate, view output
96
+
````{exercise} Change the template
97
+
98
+
::::{tab-set}
99
+
:::{tab-item} Local
100
+
101
+
Using the example code provided above, update your `myst.yml` file to use the `plain_typst_book` template in your book, then rebuild the PDF.
102
+
103
+
Observe how the rendered PDF is different than the previous template.
78
104
:::
105
+
:::{tab-item} GitHub Actions
106
+
107
+
Using the example code provided above, update your `myst.yml` file to use the `plain_typst_book` template in your book. Although you will commit this in your repository, the PDF still won't be generated until completing the next exercise.
79
108
80
-
:::{exercise} Customize the template and regenerate the PDF
81
-
visit the repo, read doc, change some features of the template
82
109
:::
110
+
::::
111
+
````
83
112
113
+
(section:pdf-with-gha)=
84
114
## PDF output with GH Actions
85
115
86
116
Building and including your PDF is possible through a GitHub action that automatically builds the PDF when you push changes to GitHub. This has both is pros and cons. For instance, the build of your PDF is done prior to the build of your book, and if there is an error in the workflow your website may not be updated, or the PDF may not be included as a download. On the other hand, you do not need to install anything locally and the PDF is always up to date when you push changes. The workflow steps are:
@@ -97,18 +127,28 @@ Building and including your PDF is possible through a GitHub action that automat
97
127
myst build --typst
98
128
```
99
129
100
-
```{tip} Good practice with PDFs and Git
101
-
Don't commit PDF's. Hence the `.gitignore`. Don't let your GHA commit PDF's either (hence the artifact upload, which is shown later).
102
-
In fact, PDF generation in GHA is a form of software testing: successful generation of the PDF indicates everything is working properly.
103
-
```
130
+
````{exercise} Change the workflow
104
131
105
-
:::{exercise} Add PDF generation to GHA workflow
106
-
**WIP**
107
-
change, view output
132
+
::::{tab-set}
133
+
:::{tab-item} Local
134
+
135
+
Using the example code provided above, update your `deploy.yml` file to build the PDF as part of your GitHub Action workflow.
136
+
137
+
Visit the Actions page of your repository to find where the artifact (PDF) can be downloaded.
138
+
:::
139
+
:::{tab-item} GitHub Actions
140
+
141
+
Using the example code provided above, update your `deploy.yml` file to build the PDF as part of your GitHub Action workflow.
142
+
143
+
Visit the Actions page of your repository to find where the artifact (PDF) can be downloaded.
108
144
:::
145
+
::::
146
+
````
109
147
110
148
## More fun with PDF's
111
149
150
+
**WIP**
151
+
112
152
add MyST action button, add download on page.
113
153
114
154
Upload as artifact (GHA only). This can be done even if the website build fails.
This page provides additional information about the [Typst template `plain_typst_book`](https://github.com/myst-templates/plain_typst_book) which was set up for this book as part of the exercises on the previous page.
10
+
11
+
**WIP**
12
+
- brief overview of how the template works (repo, inclusion, etc)
13
+
- summary of how to "view" it
14
+
- examples of usage (options)
15
+
- more advanced explanations, if needed
16
+
17
+
18
+
## Excluding and including sections for PDF[^1]
19
+
[^1]: Directly copied from the official [Myst documentation](https://mystmd.org/guide/creating-pdf-documents#excluding-content-from-specific-exports).
20
+
21
+
22
+
If you need to inject some LaTeX or Typst-specific content into their respective exports, you may use the {raw:latex} or {raw:typst} role and directive.
23
+
For example, to insert a new page in Typst with two columns:
0 commit comments