Parse LaTeX lines

parse_tex(tex_lines)

Arguments

tex_lines

Character vector (as read from a .tex file).

Value

A data.table where each row identifies a unique character in tex_lines.

line_no

Matches the index of tex_lines.

char_no

The character within line_no.

char

The character. A single character.

tex_group

The TeX group by default. Any delimiters can be used.

optional_tex_group

(If any present), the optional TeX group.

tgi

The number of braces opened at the i-th current TeX group level.

GROUP_IDi

An integer identifying the unique contiguous block at the TeX group at or above the current group level.

GROUP_IDi

The analog for optional groups.

If tex_lines is zero-length, a null data.table.

Examples

parse_tex(c("A{}", "B[a]{b{c}{d}}z"))
#> char_no line_no column char openers closers opener_optional closer_optional #> 1: 1 1 1 A FALSE FALSE FALSE FALSE #> 2: 2 1 2 { TRUE FALSE FALSE FALSE #> 3: 3 1 3 } FALSE TRUE FALSE FALSE #> 4: 4 2 1 B FALSE FALSE FALSE FALSE #> 5: 5 2 2 [ FALSE FALSE TRUE FALSE #> 6: 6 2 3 a FALSE FALSE FALSE FALSE #> 7: 7 2 4 ] FALSE FALSE FALSE TRUE #> 8: 8 2 5 { TRUE FALSE FALSE FALSE #> 9: 9 2 6 b FALSE FALSE FALSE FALSE #> 10: 10 2 7 { TRUE FALSE FALSE FALSE #> 11: 11 2 8 c FALSE FALSE FALSE FALSE #> 12: 12 2 9 } FALSE TRUE FALSE FALSE #> 13: 13 2 10 { TRUE FALSE FALSE FALSE #> 14: 14 2 11 d FALSE FALSE FALSE FALSE #> 15: 15 2 12 } FALSE TRUE FALSE FALSE #> 16: 16 2 13 } FALSE TRUE FALSE FALSE #> 17: 17 2 14 z FALSE FALSE FALSE FALSE #> tex_group optional_tex_group tg1 GROUP_ID1 tg2 GROUP_ID2 og1 OPT_GROUP_ID1 #> 1: 0 0 0 NA 0 NA 0 NA #> 2: 1 0 1 1 0 NA 0 NA #> 3: 1 0 1 1 0 NA 0 NA #> 4: 0 0 1 NA 0 NA 0 NA #> 5: 0 1 1 NA 0 NA 1 1 #> 6: 0 1 1 NA 0 NA 1 1 #> 7: 0 1 1 NA 0 NA 1 1 #> 8: 1 0 2 2 0 NA 1 NA #> 9: 1 0 2 2 0 NA 1 NA #> 10: 2 0 NA 2 1 1 1 NA #> 11: 2 0 NA 2 1 1 1 NA #> 12: 2 0 NA 2 1 1 1 NA #> 13: 2 0 NA 2 2 2 1 NA #> 14: 2 0 NA 2 2 2 1 NA #> 15: 2 0 NA 2 2 2 1 NA #> 16: 1 0 2 2 2 NA 1 NA #> 17: 0 0 2 NA 2 NA 1 NA
# The version transposed: # #> char : A{}B[a]{b{c}{d}}z #> tg1 : 011111122......22 #> tg2 : 00000000011122222 #> og1 : 00001111111111111 #> GROUP_ID1 : .11....222222222. #> GROUP_ID2 : .........111222.. #> OPT_GROUP_ID1 : ....111..........