@@ -479,12 +479,137 @@ MyST enables building a PDF from the same source as you built your website.
479479
480480Some features are web-specific, however, and won't be rendered in an output PDF.
481481
482-
482+ Let's try it out!
483483
484484
485485### 💪 Exercise C: Render a PDF from the same source as your website
486486
487- TODO
487+ #### Attempt to build our current project as PDF
488+
489+ Building PDF(s) from a MyST project requires on command:
490+
491+ ``` bash
492+ myst build --pdf
493+ ```
494+
495+ :::{important} 👀 You should notice...
496+ :class: simple
497+ :icon: false
498+
499+ This command fails with:
500+
501+ ```
502+ 📭 No file exports with kind "pdf" found.
503+ You may need to add an 'exports' field to the frontmatter of the file(s) you wish to
504+ export:
505+
506+ ---
507+ exports:
508+ - format: pdf
509+ ---
510+ ```
511+
512+ This is because we need to tell MyST which pieces of the site should be exportable as
513+ PDF.
514+ :::
515+
516+
517+ ### Configure the frontmatter to allow PDF export
518+
519+ To tell MyST that we want a PDF export for a specific document, we need to define {term}` frontmatter ` .
520+
521+ While we're here, let's also set some other metadata like the document's author.
522+
523+ Add to the top of ` index.md ` :
524+
525+ ``` {code} Markdown
526+ :filename: index.md
527+ :linenos:
528+ :emphasize-lines: 1-12
529+
530+ ---
531+ authors:
532+ - name: "Your name"
533+ affiliations:
534+ - "Your employer"
535+ email: "your-email@example.com"
536+ github: "your-github-username"
537+ # Optional: Do you have an ORCID?
538+ # orcid: "0000-0000-0000-0000"
539+ export:
540+ - "pdf"
541+ ---
542+
543+ Hello, world!
544+ ```
545+
546+ :::{hint} On quoting in YAML
547+ :class: dropdown
548+
549+ YAML is intended to be a human-friendly data format.
550+ There are many ways that it excels at this goal, and in other ways, it introduces
551+ pitfalls that are easy to fall in to.
552+
553+ A single rule will help you avoid many of these pitfalls:
554+ ** _ always quote strings in your YAML_ ** .
555+
556+ ** Example: Upgrading the Python version**
557+
558+ ``` yaml
559+ requires_python : 3.9
560+ ` ` `
561+
562+ ☝️
563+ Looks good to me, and it works fine. I'll just upgrade that to 3.10...
564+
565+ ` ` ` yaml
566+ requires_python : 3.10
567+ ` ` `
568+
569+ 🙅
570+ This value isn't a string, it's a number, so it evaluates to 3.1.
571+
572+ ` ` ` yaml
573+ requires_python : " 3.10"
574+ ` ` `
575+
576+ ✅
577+ The only way to get the result you want is to quote the string.
578+
579+ **Example: ISO country codes**
580+
581+ ` ` ` yaml
582+ country_code : gb
583+ ` ` `
584+
585+ ☝️
586+ Looks good to me, and it works fine. I'll just update my program to process data for
587+ Norway...
588+
589+ ` ` ` yaml
590+ country_code : no
591+ ` ` `
592+
593+ 🙅
594+ This value isn't a string, it's a **boolean**, so it evaluates to ` false`.
595+
596+ ` ` ` yaml
597+ country_code: "no"
598+ ` ` `
599+
600+ ✅
601+ The only way to get the result you want is to quote the string.
602+
603+ Save yourself the pain :
604+ **_always defensively quote your YAML strings_**.
605+
606+ There are many more ways YAML can be confusing.
607+ There are a lot of special rules to remember!
608+ For more, check out
609+ [The YAML document from hell](https://ruudvanasseldonk.com/2023/01/11/the-yaml-document-from-hell)
610+ and <https://noyaml.com/>.
611+ :: :
612+
488613
489614# ### 🧠 What do we know now?
490615
0 commit comments