Skip to contents

Find or drop captions

Usage

find_captions(items)

drop_captions(items, idx = NULL)

path_to_caption(items)

Arguments

items

A LaTeX2 or other list of LaTeX2items.

idx

NULL or a vector of the same length as items

Value

find_captions() returns the indices within the items of any caption text, with an attribute extra holding indices of associated macros and whitespace.

drop_captions() returns the items with captions dropped as a LaTeX2 object. It has an attribute named idx that is the idx argument with corresponding elements dropped.

path_to_caption() returns a path containing the location of the first caption block within items. It has an attribute idx containing a LaTeX2range object for the associated macros and whitespace.

Examples

parsed <- parseLatex("before \\caption{This is a caption} \\\\ after")
idx <- find_captions(parsed)
parsed[idx]
#> [[1]]
#> BLOCK: {This is a caption}
#> 
parsed[attr(idx, "extra")[[1]]]
#> [[1]]
#> MACRO: \caption
#> 
#> [[2]]
#> BLOCK: {This is a caption}
#> 
#> [[3]]
#> SPECIAL:  
#> 
#> [[4]]
#> MACRO: \\
#> 
drop_captions(parsed)
#> before  after
path_to_caption(parsed)
#> [1] 4
#> attr(,"idx")
#> path= range=all