Learn R Programming

parseLatex (version 0.4.1)

find_pattern: Find a pattern in deparsed items

Description

Searches a LaTeX2 list for text using grepl() on deparsed versions of parts of the code. It attempts to find the narrowest match(es) that lie within a single container.

Usage

find_pattern(items, pattern, ..., all = FALSE)

Value

find_pattern() returns a LaTeX2range object or (if all is TRUE) a list of them.

Arguments

items

A list of latex items.

pattern

Pattern to use in grepl().

...

Additional parameters to pass to grepl.

all

Find all matching, or the first?

Details

find_pattern() does a recursive search in the order items appear in the deparse. If the pattern matches, it attempts to narrow the match by recursing into containers and dropping earlier and later items. It should always return syntactically correct LaTeX code in which the pattern appears.

Examples

Run this code
latex <- kableExtra::kbl(mtcars[1:2, 1:2], format = "latex", caption = "Sample table")
parsed <- parseLatex(latex)
parsed
loc <- find_pattern(parsed, "RX4 Wag", fixed = TRUE)
loc
print(loc, source = parsed)

Run the code above in your browser using DataLab