zxc的自留地

About Me

mdbook生成pdf

August 22, 2023

install

cargo install mdbook

init

mdbook init my-first-book

会生成如下的文件格式


my-first-book
├── book
├── book.toml └── src
    ├── chapter_1.md
    └── SUMMARY.md

make

这时候就需要在把需要制作的md文件,按照格式整理好,把所有的章节放到src下面,然后在SUMMARY.md 里加上相应目录的章节

例如这样

❯ tree -L 3 src
src
├── ch00_read_this_first.md
├── ch01_starting_vim.md
├── ch02_buffers_windows_tabs.md
├── ch03_searching_files.md
├── ch04_vim_grammar.md
├── ch05_moving_in_file.md
├── ch06_insert_mode.md
├── ch07_the_dot_command.md
├── ch08_registers.md
├── ch09_macros.md
├── ch10_undo.md
├── ch11_visual_mode.md
├── ch12_search_and_substitute.md
├── ch13_the_global_command.md
├── ch14_external_commands.md
├── ch15_command-line_mode.md
├── ch16_tags.md
├── ch17_fold.md
├── ch18_git.md
├── ch19_compile.md
├── ch20_views_sessions_viminfo.md
├── ch21_multiple_file_operations.md
├── ch22_vimrc.md
├── ch23_vim_packages.md
├── ch24_vim_runtime.md
├── ch25_vimscript_basic_data_types.md
├── ch26_vimscript_conditionals_and_loops.md
├── ch27_vimscript_variable_scopes.md
├── ch28_vimscript_functions.md
├── ch29_plugin_example_writing-a-titlecase-plugin.md
└── SUMMARY.md
❯ cat src/SUMMARY.md
# Summary

- [Chapter 0](./ch00_read_this_first.md)
- [Chapter 1](./ch01_starting_vim.md)
- [Chapter 2](./ch02_buffers_windows_tabs.md)
- [Chapter 3](./ch03_searching_files.md)
- [Chapter 4](./ch04_vim_grammar.md)
- [Chapter 5](./ch05_moving_in_file.md)
- [Chapter 6](./ch06_insert_mode.md)
- [Chapter 7](./ch07_the_dot_command.md)
- [Chapter 8](./ch08_registers.md)
- [Chapter 9](./ch09_macros.md)
- [Chapter 10](./ch10_undo.md)
- [Chapter 11](./ch11_visual_mode.md)
- [Chapter 12](./ch12_search_and_substitute.md)
- [Chapter 13](./ch13_the_global_command.md)
- [Chapter 14](./ch14_external_commands.md)
- [Chapter 15](./ch15_command-line_mode.md)
- [Chapter 16](./ch16_tags.md)
- [Chapter 17](./ch17_fold.md)
- [Chapter 18](./ch18_git.md)
- [Chapter 19](./ch19_compile.md)
- [Chapter 20](./ch20_views_sessions_viminfo.md)
- [Chapter 21](./ch21_multiple_file_operations.md)
- [Chapter 22](./ch22_vimrc.md)
- [Chapter 23](./ch23_vim_packages.md)
- [Chapter 24](./ch24_vim_runtime.md)
- [Chapter 25](./ch25_vimscript_basic_data_types.md)
- [Chapter 26](./ch26_vimscript_conditionals_and_loops.md)
- [Chapter 27](./ch27_vimscript_variable_scopes.md)
- [Chapter 28](./ch28_vimscript_functions.md)
- [Chapter 29](./ch29_plugin_example_writing-a-titlecase-plugin.md)

generate

最后就可以生成带有outline目录的pdf了

mdbook-pdf提供的镜像,不支持outline,然后修改了Dockerfile,加上了mdbook-pdf-outline的插件

修改book.toml

加上


[output.pdf]

[output.pdf-outline]
like-wkhtmltopdf = true

生成pdf

是通过挂载的方式,把文件夹挂到容器里执行,最后生成的文件在book/pdf-outline/output.pdf

docker run -v /root/my-first-book:/book zidy/mdbook-pdf-outline:latest

reference