cites_replace_author: Add Parentheses to Citation Commands in LaTeX Text

View source: R/cites_replace_author.R

single_replace_authorR Documentation

Add Parentheses to Citation Commands in LaTeX Text

Description

single_replace_author function modifies LaTeX citation commands to add parentheses around them, transforming commands such as \cite{...} into (\cite{...}).

cites_replace_author function processes a LaTeX document to transform all numeric citations into author-year style by wrapping citation commands in parentheses.

single_replace_number function transforms LaTeX citation commands from an author-year style (e.g., (\cite{...})) back to their original form (e.g., \cite{...}).

cites_replace_number function processes a LaTeX document to remove parentheses around citation commands, converting citations from an author-year style back to numeric style.

Usage

single_replace_author(
  text,
  latex_prefix = c("cite", "upcite", "citep", "citet")
)

cites_replace_author(tex)

single_replace_number(
  text,
  latex_prefix = c("cite", "upcite", "citep", "citet")
)

cites_replace_number(tex)

Arguments

text

A single string of LaTeX content.

latex_prefix

A character vector of LaTeX citation commands to be matched (default: c("cite", "upcite", "citep", "citet")).

tex

A character vector where each element represents a line or section of LaTeX content.

Details

The function searches for LaTeX citation commands using regular expressions. For each matched command, it appends and prepends parentheses to create the author-year citation style. Excessive whitespace in the resulting text is removed to ensure formatting consistency.

If no matching citation commands are found, the input text is returned unchanged.

This function applies single_replace_author to each line or section of the LaTeX document, ensuring that citation commands such as \cite{...} and \citet{...} are converted into (\cite{...}) and (\citet{...}), respectively.

The function identifies citation commands enclosed in parentheses and removes the parentheses, restoring the original citation format. Excessive whitespace in the resulting text is removed for formatting consistency.

If no matching citation commands are found, the input text is returned unchanged.

This function applies single_replace_number to each line or section of the LaTeX document, ensuring that citations like (\cite{...}) are transformed back into \cite{...}.

Value

A string where all matched citation commands are wrapped in parentheses.

A character vector with LaTeX content where all citation commands are converted to author-year style.

A string where parentheses around matched citation commands are removed.

A character vector with LaTeX content where parentheses around citation commands are removed.

See Also

single_replace_author

single_replace_number

Examples

tex= c("This is a citation \\upcite{key1,key2} and \\citep{key3-a }",
       "This is a citation \\citet{key1,key2} and \\citet{key3-a }",
       "this is no citation",
       "",
       "This is a citation \\upcite{key1,key4} and \\cite{key3-a }")


tex = cites_replace_author(tex)

print(tex)


tex2 = cites_replace_number(tex)
print(tex2)

zoushucai/journalabbr documentation built on Dec. 6, 2024, 4:41 p.m.