Skip to content

Commit 878928c

Browse files
committed
typst PDF: include a general and a precise TOC
we need to hide the Conten't false TOC in the PDF, but keep it in the EPUB. for #509
1 parent 06a487d commit 878928c

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ epub: clean
1313
sbcl --load make-cookbook.lisp --eval '(generate)' --eval '(to-epub)' --eval '(uiop:quit)'
1414

1515
pdf: clean
16-
sbcl --load make-cookbook.lisp --eval '(generate)' --eval '(to-pdf)' --eval '(uiop:quit)'
16+
sbcl --disable-debugger --load make-cookbook.lisp --eval '(generate)' --eval '(to-pdf)' --eval '(uiop:quit)'
1717

1818
sample-pdf: clean
1919
sbcl --load make-cookbook.lisp --eval '(generate)' --eval '(sample-pdf)' --eval '(uiop:quit)'

foreword.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ title: Foreword
44

55
<!-- that's for the EPUB and the PDF versions -->
66

7+
The Common Lisp Cookbook is a collaborative resource. Thanks to
8+
everyone who helped along the way.
9+
10+
<!-- We want the Cookbook to help you learn Common Lisp in a wide range of -->
11+
<!-- day-to-day tasks. It can be used by Lisp newcomers as a tutorial -->
12+
<!-- (getting started, functions, CLOS…) and by everybody as a reference -->
13+
<!-- (loop!). -->
14+
715
We hope that these EPUB and PDF versions make the learning experience
816
even more practical and enjoyable.
917

index.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ The CL Cookbook aims to tackle all sort of topics, for the beginner and for the
8080
* [Using the Win32 API](win32.html)
8181
<!-- epub-exclude-end -->
8282

83+
<!-- pdf-include-start
8384
84-
## Download in EPUB
85+
{{PDF-TOCS}}
8586
86-
The Cookbook is also available in EPUB (and PDF) format.
87+
pdf-include-end -->
88+
89+
90+
## Download in EPUB and PDF
91+
92+
The Cookbook is also available in EPUB and PDF format.
8793

8894
You can [download it directly in EPUB](https://github.com/LispCookbook/cl-cookbook/releases/download/2023-12-13/common-lisp-cookbook.epub) and [PDF](https://github.com/LispCookbook/cl-cookbook/releases/download/2023-12-13/common-lisp-cookbook.pdf), and you can **pay what you want** to further support its development:
8995

@@ -110,7 +116,7 @@ The Cookbook has been translated to:
110116
* [Chinese simplified](https://oneforalone.github.io/cl-cookbook-cn/#/) ([Github](https://github.com/oneforalone/cl-cookbook-cn))
111117
* [Portuguese (Brazilian)](https://lisp.com.br/cl-cookbook/) ([Github](https://github.com/commonlispbr/cl-cookbook))
112118

113-
# Other CL Resources
119+
## Other CL Resources
114120

115121
<p id="two-cols"></p>
116122

@@ -153,7 +159,7 @@ Specifications
153159
* [The Common Lisp HyperSpec](http://www.lispworks.com/documentation/HyperSpec/Front/index.htm) by Kent M. Pitman (also available in [Dash](https://kapeli.com/dash), [Zeal](https://zealdocs.org/) and [Velocity](https://velocity.silverlakesoftware.com/))
154160
* [The Common Lisp Community Spec](https://cl-community-spec.github.io/pages/index.html) - a new rendering produced from the ANSI specification draft, that everyone has the right to edit.
155161

156-
# Further remarks
162+
## Further remarks
157163

158164
This is a collaborative project that aims to provide for Common Lisp something
159165
similar to the [Perl Cookbook][perl] published by O'Reilly. More details about

make-cookbook.lisp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414

1515
(require 'asdf)
1616

17+
;; You need the str library already installed:
18+
;; (ql:quickload "str")
19+
;; We use str:replace-all which relies on ppcre, so we need a library anyways.
20+
;; That's why I'm doing and using CIEL: small scripts are much easier to run and share.
21+
22+
(handler-case
23+
(require 'str)
24+
(error ()
25+
(format t "~&Please install the 'str' library to generate the PDF: (ql:quickload \"str\")~&")
26+
(uiop:quit 1)))
27+
1728
(defparameter chapters
1829
(list
1930
"index.md"
@@ -71,6 +82,17 @@
7182
(defparameter *epub-command-placeholder* "pandoc -o ~a --toc metadata.txt ~a"
7283
"format with book name and sources file.")
7384

85+
(defparameter pdf-toc "== Table Of Contents (High-level)
86+
<high-level-table-of-contents>
87+
#outline(title: none, depth:1)
88+
89+
#pagebreak()
90+
91+
== Table Of Contents (Detailed)
92+
<detailed-table-of-contents>
93+
#outline(title: none, depth:3)
94+
")
95+
7496
(defun reset-target ()
7597
(uiop:run-program (format nil "echo > ~a" *full-markdown*)))
7698

@@ -95,6 +117,16 @@
95117
(format t "~&Generating a very short PDF sample.~&")
96118
(uiop:run-program (format nil "typst compile ~a" *typst-preamble*)))
97119

120+
(defun insert-pdf-tocs ()
121+
"Replace {{PDF-TOCS}} in the .typ file with a proper TOC declaration.
122+
123+
Using sed was tooooo cumbersome."
124+
(format t "~&Inserting our table of contents into full-with-preamble.typ…~&")
125+
(let* ((file.typ "full-with-preamble.typ")
126+
(file-string (uiop:read-file-string file.typ))
127+
(new-content (str:replace-all "{{PDF-TOCS}}" pdf-toc file-string)))
128+
(str:to-file file.typ new-content)))
129+
98130
(defun to-pdf ()
99131
"Needs pandoc >= 3.8 with Markdown to Typst conversion,
100132
and the typst binary on the path."
@@ -114,10 +146,14 @@
114146
:output t
115147
:error-output t)
116148

149+
;; Insert our two outlines:
150+
(insert-pdf-tocs)
151+
117152
;; Compile the Typst document:
118153
(uiop:run-program "typst compile full-with-preamble.typ" :output t :error-output t)
119154
; todo utiliser min-book?
120-
(uiop:run-program "mv full-with-preamble.pdf common-lisp-cookbook.pdf"))
155+
(uiop:run-program "mv full-with-preamble.pdf common-lisp-cookbook.pdf")
156+
(format t "Done: common-lisp-cookbook.pdf"))
121157

122158
(defun build-full-source ()
123159
(format t "Creating the full source into ~a...~&" *full-markdown*)

metadata.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title:
77
creator:
88
- role: author
99
text: The Common Lisp Cookbook contributors
10-
rights: © January 2025, vindarel <vindarel@mailz.org>.
11-
This e-book is free of charge, but you can [pay what you want](https://ko-fi.com/s/01fee22a32) for it.
10+
rights: © November 2025, vindarel <vindarel@mailz.org>.
11+
This e-book is free of charge, but you can [pay what you want](https://ko-fi.com/s/01fee22a32) for it.
1212
cover-image: orly-cover.png
1313
...

typst-preamble.typ

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
to: "odd"
55
)
66

7+
#set heading(numbering: "1.")
78
#show link: underline
89

910
#set page(numbering: "1")

0 commit comments

Comments
 (0)