An open API service indexing awesome lists of open source software.

https://github.com/lightbridge-ks/thaipdf

R Markdown to PDF in Thai language 🇹🇭
https://github.com/lightbridge-ks/thaipdf

latex-template pdf-document r-package rmarkdown thai thai-language

Last synced: 8 months ago
JSON representation

R Markdown to PDF in Thai language 🇹🇭

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
# from: https://github.com/mitchelloharawild/vitae/blob/master/README.Rmd
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# thaipdf

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![CRAN status](https://www.r-pkg.org/badges/version/thaipdf)](https://CRAN.R-project.org/package=thaipdf) [![R-CMD-check](https://github.com/Lightbridge-KS/thaipdf/workflows/R-CMD-check/badge.svg)](https://github.com/Lightbridge-KS/thaipdf/actions) [![codecov](https://codecov.io/gh/Lightbridge-KS/thaipdf/branch/main/graph/badge.svg?token=QPhwQZt2vf)](https://app.codecov.io/gh/Lightbridge-KS/thaipdf) [![pkgdown](https://github.com/Lightbridge-KS/thaipdf/actions/workflows/pkgdown.yaml/badge.svg)](https://github.com/Lightbridge-KS/thaipdf/actions/workflows/pkgdown.yaml)

> R package :package: ช่วยสร้าง PDF document จาก R Markdown ที่ใช้ **ภาษาไทย :thailand:**

```{r show-previews, echo=FALSE, results='asis'}
knitr::kable(
tibble::tibble(
`1` = "![Thai book example 1](man/figures/book-th-ex1.png)",
`2` = "![Thai book example 2](man/figures/book-th-ex2.png)"
),
escape = FALSE
)
```

# Goal

R package นี้ช่วย**สร้าง PDF เป็นภาษาไทย :thailand: จาก [R Markdown](https://rmarkdown.rstudio.com) ได้โดยง่าย**

- **ผู้เริ่มต้น** สามารถ **knit** เอกสาร R Markdown เป็น PDF ได้ทันทีโดยใช้ template ที่มีให้ และ

- **ผู้ที่ใช้งาน [LaTeX](https://www.latex-project.org) เป็น** สามารถเรียกใช้ LaTeX preamble ที่มีการตั้งค่าภาษาไทยมาให้แล้ว มา customize เพิ่มเติมอย่างที่ต้องการได้

โดยจะพยามคง option ต่างๆ ของ R Markdown ไว้ให้ได้มากที่สุด ซึ่งสามารถส่งต่อ YAML parameter ไปยัง R Markdown หรือ bookdown ได้ด้วย

# Install

**Install thaipdf:**

- ติดตั้งจาก CRAN ด้วย:

``` r
install.packages("thaipdf")
```

- หรือติดตั้ง development version จาก [GitHub](https://github.com/Lightbridge-KS/thaipdf) ด้วย:

``` r
# install.packages("remotes")
remotes::install_github("Lightbridge-KS/thaipdf")
```

**Install XeLaTeX และ LaTeX package** ที่จำเป็นสำหรับการใช้ภาษาไทย อาจทำได้อย่างง่ายโดยใช้ [{tinytex}](https://yihui.org/tinytex/) R package:

``` r
install.packages("tinytex")

# For using R Markdown
tinytex::install_tinytex()

# Install LaTeX PKG required by `thaipdf`
tinytex::tlmgr_install(c(
"fontspec", "ucharclasses", "polyglossia"
))
```

**Check font:** ตรวจสอบว่าในเครื่องมีฟอนท์ [TH Sarabun New](https://www.f0nt.com/release/th-sarabun-new/) ถ้าไม่มีให้ติดตั้งด้วย (เนื่องจาก thaipdf ใช้ font นี้เป็นตัวหลัก)

# Usage

วิธีใช้ที่ง่ายที่สุด คือสร้าง R Markdown ที่รองรับภาษาไทยจาก template ที่ package นี้มีให้

ถ้าท่านใช้ RStudio ให้ไปที่ `File -> New File -> R Markdown... -> From Template`

New R Markdown Template

เลือก template **Thai PDF R Markdown** หรือ **Thai PDF Bookdown** จากเมนู

กดปุ่ม **`OK`** จะเปิดไฟล์ R Markdown template ที่รองรับกับภาษาไทย

thaipdf R Markdown in RStudio

จากนั้นกดปุ่ม **`Knit`** (cmd/ctr + shift + K) ได้เลย จะได้เอกสารเป็น PDF ภาษาไทยที่มี เนื้อหา โค้ด และ กราฟ อยู่รวมกัน

![ตัวอย่าง R Markdown PDF ภาษาไทย](man/figures/pdf-doc-1.png)

# Learn more

- [**Get Started with thaipdf**](https://lightbridge-ks.github.io/thaipdf/articles/thaipdf.html)

------------------------------------------------------------------------

Last Updated: `r Sys.Date()`