Some packages such as knitr::kable()
return relatively unformatted LaTeX markup such as in the example below:
begin{tabular}{l|r|r|r|r|r}
& mpg & cyl & disp & hp & drat\
Mazda RX4 & 21.0 & 6 & 160 & 110 & 3.90\
Mazda RX4 Wag & 21.0 & 6 & 160 & 110 & 3.90\
Datsun 710 & 22.8 & 4 & 108 & 93 & 3.85\
Hornet 4 Drive & 21.4 & 6 & 258 & 110 & 3.08\
Hornet Sportabout & 18.7 & 8 & 360 & 175 & 3.15\
end{tabular}
How can I post-process this markup (e.g., by indenting nested environments and aligning on the “&” character) to achieve something more like the example below within R?
begin{tabular}{l|r|r|r|r|r}
& mpg & cyl & disp & hp & drat \
Mazda RX4 & 21.0 & 6 & 160 & 110 & 3.90 \
Mazda RX4 Wag & 21.0 & 6 & 160 & 110 & 3.90 \
Datsun 710 & 22.8 & 4 & 108 & 93 & 3.85 \
Hornet 4 Drive & 21.4 & 6 & 258 & 110 & 3.08 \
Hornet Sportabout & 18.7 & 8 & 360 & 175 & 3.15 \
end{tabular}
I’m wondering whether there is some ready-to-use LaTeX linter available or if the formatting needs to be done by hand.