Type: | Package |
Title: | Right to Left Dynamic Documents Using 'knitr' |
Version: | 1.0.0 |
Maintainer: | Foad Esmaeili <foadesmaeili5@gmail.com> |
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>. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
URL: | https://github.com/FoadEsmaeili5/RTLknitr |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
Depends: | R (≥ 4.1) |
Imports: | knitr, magrittr, gt, bookdown |
NeedsCompilation: | no |
Packaged: | 2023-08-24 11:25:02 UTC; foad |
Author: | Foad Esmaeili |
Repository: | CRAN |
Date/Publication: | 2023-08-25 07:40:05 UTC |
Centering Caption of LaTeX Table
Description
This function adds the "\centering" command to the caption of a LaTeX table, allowing the caption to be centered in the final output.
Usage
Centering(x)
Arguments
x |
LaTeX-formatted table with a caption. |
Value
LaTeX-formatted table with a centered caption.
Examples
latex_table <- "\\begin{table}\\caption{This is a caption.}\\end{table}"
centered_table <- Centering(latex_table)
print(centered_table)
Customize knitr Hooks for Right-to-Left (RTL) Text Formatting
Description
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.
Usage
hooks_rtl(fontcolor = "black", backcolor = "gray")
Arguments
fontcolor |
Font color for inline output. Default is "black". |
backcolor |
Background color for inline output. Default is "gray". |
Value
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.
References
Xie, Y. (2014). Dynamic Documents with R and knitr. Chapman & Hall/CRC. ISBN: 978-1482203530.
See Also
Use markdown_rtl
to enable RTL formatting for Markdown documents.
Examples
# 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.
Enable Right-to-Left (RTL) Formatting for Markdown Documents
Description
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.
Usage
markdown_rtl(...)
Arguments
... |
Additional arguments to be passed to the underlying |
Details
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.
Value
The function has no explicit return value. It modifies the behavior of knit_hooks
for RTL formatting.
References
Xie, Y. (2014). Dynamic Documents with R and knitr. Chapman & Hall/CRC. ISBN: 978-1482203530.
See Also
Use hooks_rtl
for handling RTL formatting within code chunks.
Examples
# 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.
Generate a YAML header for an R Markdown document with RTL support
Description
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.
Usage
markdown_rtl_header()
Value
A character string containing the YAML header.
Remove Escaped LaTeX Formulas from Text
Description
This function removes escaped LaTeX formulas and formatting commands from LaTeX-formatted text.
Usage
remove_escape_latex(x)
Arguments
x |
A character vector or string containing LaTeX-formatted text. |
Value
A character vector with escaped LaTeX formulas and formatting commands removed.
Examples
# Remove escaped LaTeX formulas from a string
cleaned_text <- remove_escape_latex("\\\\textbf\\{Hello\\}, $\\\\alpha$ formula")
print(cleaned_text)
Create a Labeled Header for gt Tables
Description
This function enhances the gt package's tab_header function by allowing the inclusion of a label for referencing the table in LaTeX documents.
Usage
tab_header_lbl(data, title, subtitle = NULL, label = NULL)
Arguments
data |
A gt table object. |
title |
Title of the table. |
subtitle |
Subtitle of the table. |
label |
Label for referencing the table in LaTeX. |
Details
Be sure to use this function at the end of gt format functions. This function returns a LaTeX-formatted table header.
Value
LaTeX-formatted table header.
Examples
require(gt)
head(iris) |> gt() |> tab_header_lbl(title = "iris",label = "tab:iris") |> cat()