0
0

bookdownのGitBook Styleのオプション変更方法

Last updated at Posted at 2024-08-25

bookdownとは

本を執筆することに特化したRのパッケージです.
bookdownはR Markdown (http://rmarkdown.rstudio.com) を使用するため,Markdown構文のシンプルさと複数の出力形式に対応する事ができます.

image.png

モチベーション

bookdownのGitBook Styleのオプションを変更したい.


👆"bookdownリファレンスのオプション"

方法

_output.ymlの設定を変更します.

公式が用意しているデモプロジェクト (https://github.com/rstudio/bookdown-demo) では
_output.yml (https://github.com/rstudio/bookdown-demo/blob/main/_output.yml) は次のように設定されています.

bookdown::gitbook:
  css: style.css
  config:
    toc:
      before: |
        <li><a href="./">A Minimal Book Example</a></li>
      after: |
        <li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
    edit: https://github.com/rstudio/bookdown-demo/edit/master/%s
    download: ["pdf", "epub"]
bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
bookdown::epub_book: default
bookdown::bs4_book: default

結果は先に載せた"bookdownリファレンスのオプション"画像のようにレンダリングされます.

リファレンス (https://bookdown.org/yihui/bookdown/html.html#gitbook-style) ではgitbookフォーマットのデフォルトの設定データをYAMLメタデータとして載せてくれています.

bookdown::gitbook:
  config:
    toc:
      collapse: subsection
      scroll_highlight: true
      before: null
      after: null
    toolbar:
      position: fixed
    edit : null
    download: null
    search:
      engine: lunr # or fuse
      # options to control/tune search engine behavior (for
      # fuse.js, refer to https://fusejs.io/api/options.html)
      options: null
    fontsettings:
      theme: white
      family: sans
      size: 2
    sharing:
      facebook: true
      github: false
      twitter: true
      linkedin: false
      weibo: false
      instapaper: false
      vk: false
      whatsapp: false
      all: ['facebook', 'twitter', 'linkedin', 'weibo', 'instapaper']
    info: true

これに基づいて,自身の_output.ymlを変更してみましょう.

使用例

_output.yml

bookdown::gitbook:
  css: style.css
  config:
    info: false
    toc:
      before: |
        <li><a href="./">ToB213</a></li>
      after: |
        <li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
    edit: https://github.com/ToB213/tob213.github.io/edit/main/book/%s
    download: ["pdf", "epub"]
    search:
      engine: fuse
    sharing:
      facebook: false
      github: true
      twitter: true
      linkedin: false
      weibo: false
      instapaper: false
      vk: false
      whatsapp: false
      all: ['twitter', 'github']
bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
bookdown::epub_book: default
bookdown::bs4_book: default

出力結果

最後に

その他,bookdownの詳細な設定方法はリファレンスを参照してください.
お疲れ様です:sunny:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0