knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file()) # Set WD to Root
here::i_am("dev/use-th-pre-impr.Rmd")
library(here)

Desired Behavior of use_thai_preamble()

Relative to WD

Create at arbitrary location

We need to test rmarkdown::pandoc_template()

plan using fs::path_abs() to wrap output since, it accept both relative path to WD and absolute path

getwd()

Works

rmarkdown::pandoc_template(
  metadata = list(thai_font = "Somefonts", line_spacing = 2),
  template = thaipdf:::thaipdf_paths()[["path_temp"]],
  # To Relative Location to WD
  output = fs::path_abs("dev/test_data/test-thai-preamble.tex")
  )

Works

# rmarkdown::pandoc_template(
#   metadata = list(thai_font = "Somefonts", line_spacing = 2),
#   template = thaipdf:::thaipdf_paths()[["path_temp"]],
#   # To Absolute Location 
#   output = fs::path_abs("/Users/kittipos/my_pkg/test-thai-preamble.tex")
#   )

HowTo: Write Template to Temp file

tmpdir <- tempdir()

file.path(tempdir(), "thai-preamble.tex")
# the same
fs::file_show(tmpdir)
fs::file_show(tempdir())
rmarkdown::pandoc_template(
  metadata = list(thai_font = "Somefonts", line_spacing = 2),
  template = thaipdf:::thaipdf_paths()[["path_temp"]],
  # To Relative Location to WD
  output = fs::path_abs(file.path(tempdir(), "thai-preamble.tex"))
  )

# fs::file_show(tempdir())
fs::file_exists(file.path(tempdir(), "thai-preamble.tex"))
tmp_file <- file.path(tempdir(), "thai-preamble.tex")

thaipdf::use_thai_preamble(tmp_file)

fs::file_exists(tmp_file)
# fs::file_show(tempdir())
#unlink(tmp_file)
.old_wd <- setwd(tempdir())

thaipdf::use_thai_preamble()

fs::file_exists("thai-preamble.tex")
#fs::file_show("thai-preamble.tex")
unlink("thai-preamble.tex")
setwd(.old_wd)
.old_wd <- setwd(tempdir())

thaipdf::use_thai_preamble()


Lightbridge-KS/thaipdf documentation built on June 18, 2022, 6:58 a.m.