cites_replace_order: Replace Citation Order in LaTeX Text

View source: R/cites_replace_order.R

single_replace_orderR Documentation

Replace Citation Order in LaTeX Text

Description

single_replace_order function modifies LaTeX citation commands to reorder citation keys based on a provided order.

cites_replace_order function processes a LaTeX document to reorder all citation keys within citation commands based on their first appearance in the document.

Usage

single_replace_order(
  text,
  citesall = NULL,
  latex_prefix = c("cite", "upcite", "citep", "citet")
)

cites_replace_order(tex, citesall = NULL)

Arguments

text

A single string of LaTeX content.

citesall

A character vector containing all citation keys in the desired order. If not provided, default applies cites_extract.

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 identifies LaTeX citation commands and reorders their arguments (e.g., \cite{key1,key2}) to match the order specified in citesall. If a citation contains only one key, it remains unchanged.

Matched citation keys not found in citesall are excluded from the reordered result.

The function extracts all citation keys using cites_extract, determines their order based on first occurrence, and applies single_replace_order to reorder keys in each citation command.

Value

A string with citation keys reordered within the specified citation commands.

A character vector with updated LaTeX content where citation keys in commands are reordered.

See Also

single_replace_order, cites_extract

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 }")
citesall = cites_extract(tex)

citesall = c("key2", "key1", "key3-a", "key4")

cites_replace_order(tex, citesall)

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