Title: | Right to Left Dynamic Documents Using 'knitr' |
---|---|
Description: | Provide seamless support for right-to-left (RTL) languages, such as Persian and Arabic, in R Markdown documents and 'LaTeX' output. It includes functions and hooks that enable easy integration of RTL language content, allowing users to create documents that adhere to RTL writing conventions. For in-depth insights into dynamic documents and the 'knitr' package, consider referring to Xie, Y (2014) <ISBN: 978-1-482-20353-0>. |
Authors: | Foad Esmaeili [aut, cre, cph] |
Maintainer: | Foad Esmaeili <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.0 |
Built: | 2024-11-21 03:49:58 UTC |
Source: | https://github.com/foadesmaeili5/rtlknitr |
This function adds the "\centering" command to the caption of a LaTeX table, allowing the caption to be centered in the final output.
Centering(x)
Centering(x)
x |
LaTeX-formatted table with a caption. |
LaTeX-formatted table with a centered caption.
latex_table <- "\\begin{table}\\caption{This is a caption.}\\end{table}" centered_table <- Centering(latex_table) print(centered_table)
latex_table <- "\\begin{table}\\caption{This is a caption.}\\end{table}" centered_table <- Centering(latex_table) print(centered_table)
This function defines customized knitr
hooks to handle RTL (right-to-left)
text formatting for languages like Persian and Arabic for Sweave
. It allows you to modify
the appearance of output, messages, warnings, and errors when producing RTL documents.
hooks_rtl(fontcolor = "black", backcolor = "gray")
hooks_rtl(fontcolor = "black", backcolor = "gray")
fontcolor |
Font color for inline output. Default is "black". |
backcolor |
Background color for inline output. Default is "gray". |
The function returns a list of customized knit_hooks
that handle RTL text formatting.
It modifies the output, messages, warnings, errors, inline expressions, and source code
to include appropriate commands for RTL languages.
Xie, Y. (2014). Dynamic Documents with R and knitr. Chapman & Hall/CRC. ISBN: 978-1482203530.
Use markdown_rtl
to enable RTL formatting for Markdown documents.
# Define custom RTL hooks rtl_hooks <- hooks_rtl() # Apply custom RTL hooks to `knit_hooks` knitr::knit_hooks$set(rtl_hooks) # After setting the hooks, knit your document as usual to produce RTL formatting.
# Define custom RTL hooks rtl_hooks <- hooks_rtl() # Apply custom RTL hooks to `knit_hooks` knitr::knit_hooks$set(rtl_hooks) # After setting the hooks, knit your document as usual to produce RTL formatting.
This function modifies the behavior of knitr
output hooks to handle RTL (right-to-left)
text formatting for Markdown documents, particularly for languages like Persian and Arabic.
markdown_rtl(...)
markdown_rtl(...)
... |
Additional arguments to be passed to the underlying |
The markdown_rtl
function wraps the existing knit_hooks
with custom commands that switch
the text direction between Latin and Persian. It enhances the appearance of the output,
messages, warnings, and errors in RTL languages.
The function has no explicit return value. It modifies the behavior of knit_hooks
for RTL formatting.
Xie, Y. (2014). Dynamic Documents with R and knitr. Chapman & Hall/CRC. ISBN: 978-1482203530.
Use hooks_rtl
for handling RTL formatting within code chunks.
# Enable RTL formatting for the current R Markdown document markdown_rtl() # After enabling RTL formatting, proceed to knit the R Markdown document as usual. # The output and messages will be formatted for RTL languages.
# Enable RTL formatting for the current R Markdown document markdown_rtl() # After enabling RTL formatting, proceed to knit the R Markdown document as usual. # The output and messages will be formatted for RTL languages.
This function generates a YAML header for an R Markdown document that will produce a PDF output
with support for Persian typesetting using the xepersian
package and the Arial
font.
markdown_rtl_header()
markdown_rtl_header()
A character string containing the YAML header.
This function removes escaped LaTeX formulas and formatting commands from LaTeX-formatted text.
remove_escape_latex(x)
remove_escape_latex(x)
x |
A character vector or string containing LaTeX-formatted text. |
A character vector with escaped LaTeX formulas and formatting commands removed.
# Remove escaped LaTeX formulas from a string cleaned_text <- remove_escape_latex("\\\\textbf\\{Hello\\}, $\\\\alpha$ formula") print(cleaned_text)
# Remove escaped LaTeX formulas from a string cleaned_text <- remove_escape_latex("\\\\textbf\\{Hello\\}, $\\\\alpha$ formula") print(cleaned_text)
This function enhances the gt package's tab_header function by allowing the inclusion of a label for referencing the table in LaTeX documents.
tab_header_lbl(data, title, subtitle = NULL, label = NULL)
tab_header_lbl(data, title, subtitle = NULL, label = NULL)
data |
A gt table object. |
title |
Title of the table. |
subtitle |
Subtitle of the table. |
label |
Label for referencing the table in LaTeX. |
Be sure to use this function at the end of gt format functions. This function returns a LaTeX-formatted table header.
LaTeX-formatted table header.
require(gt) head(iris) |> gt() |> tab_header_lbl(title = "iris",label = "tab:iris") |> cat()
require(gt) head(iris) |> gt() |> tab_header_lbl(title = "iris",label = "tab:iris") |> cat()