texor is a package that deals with multiple challenges that occour in conversion of LaTeX source files (which typically generate a PDF) to a web friendly RJ-web-article format.
Currently texor can handle R-Journal structured LaTeX files with support for:
- RJournal based LaTeX files with macros such as
\pkg{}
,\CRANpkg{}
,\BIOpkg{}
,\code{}
,\acronym{}
- Reading Metadata from LaTeX file as well as DESCRIPTION.
- Reading bibliography from bibtex files and ignoring
\thebibliography
- Supports code environments like
Sinput
,Soutput
,example
,example*
,verbatim
,smallverbatim
with code highlight. - Supports graphics included as PDF, PNG, JPG, tikz, algorithm2e graphics supported (some figures might not work).
- Functions to convert PDF graphics to PNG.
- Almost all tables are supported with a few exceptions.
- Other things like citations,links,footnotes,math,CTV,package references are also supported.
- Bibliography management and aggregation.(moved to rebib)
- Figure/Table/Equation numbering
- Stream Editor to rename alien commands/environments to accepted defaults.
- Pre and Post conversion statistics of environments for verification.
- Support for included files (1 degree related to main article only).
- Logging of events.
Installation
Install Pandoc v3.1 or greater, ideally latest version. If you are using Rstudio, it should be pre-installed.
# To check the version of pandoc
rmarkdown::pandoc_version()
# or to simply check if you are good to go in terms of pandoc
texor::pandoc_version_check()
# TRUE if pandoc is good to go
# FALSE if pandoc is too old for texor
For included PDF conversions also install poppler-utils (used with pdftools package) Ideally install the latest version of poppler-utils.
Install the mainline version from CRAN with:
install.packages('texor')
Install the development version from GitHub with:
# install.packages("remotes")
remotes::install_github("Abhi-1U/texor")
# install.packages("pak")
pak::pak("Abhi-1U/texor")
General Usage
here is a quick example to use texor package with a sample RJournal article (included with the package inst/article)
# for a single LaTeX article
texor::latex_to_web(article_dir)
# A running example
article_dir <- system.file("examples/article", package = "texor")
dir.create(your_article_folder <- file.path(tempdir(), "tempdir"))
x <- file.copy(from = article_dir, to = your_article_folder,recursive = TRUE,)
your_article_path <- paste(your_article_folder,"article",sep="/")
# view your original article at
your_article_path
texor::latex_to_web(your_article_path,log_steps = FALSE, example = TRUE)
# view your converted and original article at
paste0(your_article_path,"/web")
Using texor over multiple files
# for multiple articles in RJ folder structure
#base dir
<- "C:/Users/abhis/path/to/base"
article_dir # list of journal number directories
<- list.dirs(article_dir,recursive = FALSE)
journal_dirs # list of individual slug directories
<- lapply(journal_dirs,function(journal_dir) {
slug_dirs list.dirs(journal_dir,recursive = FALSE)
})# creating a single list of all slug directories
<- unlist(slug_dirs)
slug_dirs # Calling
for (dir in slug_dirs) {
#print(dir)
getwd()
# below function will create a log file of success/error in current
# working directory while running the texor::latex_to_web() function
:::convert_to_html(dir)
texor }