ltx_caption: Process LaTeX Table Header with Caption, Label, and Note

View source: R/ltx_caption.R

ltx_captionR Documentation

Process LaTeX Table Header with Caption, Label, and Note

Description

The ltx_caption function processes LaTeX table code by modifying the header, including the caption, label, and table notes. It removes unnecessary lines, captures the table title, and optionally appends a label and table note, while also printing the table if specified.

Usage

ltx_caption(x, tbl_note = "", print_tbl = FALSE)

Arguments

x

A character vector representing the LaTeX table code that needs to be processed.

tbl_note

A character string for an optional table note that will be added to the table header.

print_tbl

Logical. If TRUE, the processed LaTeX table will be printed to the console. Defaults to FALSE.

Details

This function refines LaTeX table code by removing unwanted ⁠\\usepackage⁠ commands and blank lines, capturing and modifying the ⁠\\caption⁠ and ⁠\\label⁠, and optionally adding a custom table note. The function identifies the LaTeX table title and reformats it into a custom format. If a table label is present in the title, it is extracted and repositioned before the table content. If a table note is provided, it is appended after the caption.

Value

The function returns the processed LaTeX table code as an invisible character vector. If print_tbl is set to TRUE, it also prints the modified table code to the console and copies it to the clipboard for easy pasting into a latex editor.

See Also

ltx_print_tbl(), ltx_capture_output()

Examples

## Not run: 
# Example LaTeX table with caption, label, and table note
tbl_code <- c("\\usepackage{booktabs}",
              "\\caption{Sample Table}",
              "\\label{tab:example}",
              "\\begin{tabular}{|c|c|}",
              "\\hline",
              "A & B \\\\",
              "\\hline",
              "1 & 2 \\\\",
              "\\hline",
              "\\end{tabular}")

# Process the table header with a table note and print the table
ltx_caption(tbl_code, tbl_note = "Table Note", print_tbl = TRUE)

## End(Not run)

AndreSjuve/texaid documentation built on Oct. 20, 2024, 6:17 a.m.