Writing a book with bookdown in foreign languages

I remember 4 years back when I started writing master thesis in Warsaw School of Economics, I started to learn LaTeX and it was an amazing tool to write technical documents. However, to master LaTeX is not an easy job at all as it is quite tricky to solve various problems. To tell you the truth, since then I never ever used LateX again.

When started using Rmarkdown in 2016, it was very clear to me that Rmarkdown would be my favarite language to write any technical and non-technical documents. Since 2016, many new packages in markdown family have been borned and has helped statisticians, analysts around the world to write better & easier. For blogging, we have fantastic blogdown (my 2 websites are written in blogdown). However, I haven’t tried using bookdown yet.

Now that I would like to write a book about practical data science with my experience and knowledge in Vietnamese, I started to use bookdown and try to write the book in Vietnamese. It sounds quite easy as there are many fantastic tutorial available online. However, to write a book in foreign language rather than English is not that easy if you do not know LaTeX.

In this blog, I want to share some simple but very effective tips to write a book with bookdown in foreign language in some simple steps.


Step 1: Install bookdown

Of course, it is the critical part to start to write a book with bookdown. You can install bookdown easily as follows.

install.packages("bookdown")

 


 

Step 2: Create a new project with bookdown

After installing bookdown, you can easily create a new book project with bookdown from RStudio.

File >> New Project >> New bookproject using bookdown

After finishing this part, you already have had a standard, simple book to follow (of course, it is in English). So, the next steps are to change the contents into your desired language.

 


Step 3: Read & follow instruction from bookdown’s author

Yihui has written a great book about how to use bookdown efficiently. In this online book, there is a chapter which helps you to internationalize your book, or namely to write a book in other languages.

To do it, you can simply translate all parameters defined in bookdown into your language. The default translation of these parameters are as follows.

language:
  label:
    fig: 'Figure '
    tab: 'Table '
    eq: 'Equation '
    thm: 'Theorem '
    lem: 'Lemma '
    cor: 'Corollary '
    prp: 'Proposition '
    cnj: 'Conjecture '
    def: 'Definition '
    exm: 'Example '
    exr: 'Exercise '
    proof: 'Proof. '
    remark: 'Remark. '
    solution: 'Solution. '
  ui:
    edit: Edit
    chapter_name: ''

You can read all details in the following link https://bookdown.org/yihui/bookdown/internationalization.html.

However, after translating above parameters, it works only in HTML version, not pdf one. I searched through the internet but it could not find any specific instruction.

The key thing here is to change the preamble.tex file in your project. The original preamble file is as follows:

\usepackage{booktabs}

To make the whole book translated into your desired language, you need to add 2 lines of codes as follows:

\usepackage{booktabs}
\usepackage[utf8]{inputenc}
\usepackage[vietnamese]{babel}

If your language is spanish, feel free to change vietnamese to spanish. After changing, your book will work perfectly with all contents, parameters translated into your language.


Hope that this tip could help analysts to use bookdown easier when writing a book in their own languages!

Anh Hoang Duc
Anh Hoang Duc
Business Analytics professional

.

comments powered by Disqus