Title: | Parses LaTeX Documents for Errors |
---|---|
Description: | Checks LaTeX documents and .bib files for typing errors, such as spelling errors, incorrect quotation marks. Also provides useful functions for parsing and linting bibliography files. |
Authors: | Hugh Parsonage [aut, cre] |
Maintainer: | Hugh Parsonage <[email protected]> |
License: | GPL-2 |
Version: | 0.8.1 |
Built: | 2024-11-03 06:22:56 UTC |
Source: | https://github.com/hughparsonage/texcheckr |
Checks LaTeX documents and .bib
files for typing errors, such as spelling errors, incorrect quotation marks. Also provides useful functions for parsing and linting bibliography files.
Are any bib entries duplicated?
any_bib_duplicates(bib.files, .report_error, rstudio = FALSE)
any_bib_duplicates(bib.files, .report_error, rstudio = FALSE)
bib.files |
Files to check for duplicates |
.report_error |
How errors should be logged. |
rstudio |
Use the RStudio API? |
This function is very fastidious about the format of bib.files
.
Run lint_bib
(noting that this will overwrite your bibliography) if it complains.
This function finds exact duplicates in the author title date/year and volume fields. Note that it is not possible in general to detect actual duplicates; you will still need to inspect the printed bibliography.
Called for its side-effect. If duplicates are detected, the first six are printed as a data.table
;
otherwise, NULL
, invisibly.
Replace nth arguments
replace_nth_LaTeX_argument( tex_lines, command_name, n = 1L, replacement = "correct", optional = FALSE, warn = TRUE, .dummy_replacement = "Qq" ) nth_arg_positions( tex_lines, command_name, n = 1L, optional = FALSE, star = TRUE, data.tables = TRUE, allow_stringi = TRUE )
replace_nth_LaTeX_argument( tex_lines, command_name, n = 1L, replacement = "correct", optional = FALSE, warn = TRUE, .dummy_replacement = "Qq" ) nth_arg_positions( tex_lines, command_name, n = 1L, optional = FALSE, star = TRUE, data.tables = TRUE, allow_stringi = TRUE )
tex_lines |
A character vector of a LaTeX file (as read in from |
command_name |
The command name, or the pattern of the command, without the initial backslash. |
n |
Which argument of the command. |
replacement |
What to replace the |
optional |
If |
warn |
If the nth argument is not present, emit a warning? Set to |
.dummy_replacement |
An intermediate replacement value.
This value cannot be present in |
star |
Assume the starred version of the command. That is, assume that the contents of the argument lies on a single line. |
data.tables |
Should each element of the list be a |
allow_stringi |
(logical, default: |
nth_arg_positions
reports the starts and stops of the command for every line.
This includes the braces (in order to accommodate instances where the argument is empty).
If the line is empty or does not contain the command the values of starts
and stops
are NA_integer_
.
nth_arg_positions("This is a \\textbf{strong} statement.", "textbf") replace_nth_LaTeX_argument("This is a \\textbf{strong} statement.", "textbf")
nth_arg_positions("This is a \\textbf{strong} statement.", "textbf") replace_nth_LaTeX_argument("This is a \\textbf{strong} statement.", "textbf")
Functions for parsing .bib files
fread_bib( file.bib, check.dup.keys = TRUE, strip.braces = TRUE, check.unescaped.percent = TRUE, .bib_expected = TRUE, halt = TRUE, rstudio = FALSE, .report_error ) bib2DT(file.bib, to_sort = FALSE) reorder_bib(file.bib, outfile.bib = file.bib)
fread_bib( file.bib, check.dup.keys = TRUE, strip.braces = TRUE, check.unescaped.percent = TRUE, .bib_expected = TRUE, halt = TRUE, rstudio = FALSE, .report_error ) bib2DT(file.bib, to_sort = FALSE) reorder_bib(file.bib, outfile.bib = file.bib)
file.bib |
|
check.dup.keys |
If |
strip.braces |
If |
check.unescaped.percent |
If |
.bib_expected |
(logical, default: |
halt |
Whether to halt on error. If |
rstudio |
(logical, default: |
.report_error |
A function like |
to_sort |
Include only author, title, year, and date. |
outfile.bib |
File to write the reordered bib to. Defaults to |
bib2DT
returns a data.table
of the entries in file.bib
. The function
reorder_bib
rewrites file.bib
, to put it in surname, year, title, line number order.
Where do braces close?
braces_closes_at(tex_line, position_of_opening_brace)
braces_closes_at(tex_line, position_of_opening_brace)
tex_line |
A single line. |
position_of_opening_brace |
An integer giving the position of the opening brace in question. |
The positions of the closing brace matching the opening braces at position_of_opening_brace
.
Check biber
check_biber(path = ".", rstudio = FALSE)
check_biber(path = ".", rstudio = FALSE)
path |
The path containing the |
rstudio |
Use the RStudio API? |
Check consecutive typeset words
check_consecutive_words( path = ".", latex_file = NULL, md5sum.ok = NULL, outfile = NULL, outfile.append = FALSE )
check_consecutive_words( path = ".", latex_file = NULL, md5sum.ok = NULL, outfile = NULL, outfile.append = FALSE )
path |
Path containing the LaTeX file. |
latex_file |
The LaTeX file (without path) whose output will be checked. |
md5sum.ok |
The output of |
outfile |
A file to which the output can be saved. If |
outfile.append |
(logical, default: |
NULL
if the LaTeX
document does not create a PDF with lines repeated.
An error if words are repeated on consecutive lines, together with cat()
output of the offending lines. The output is presented in 'stanzas':
'<Repeated word>' <Context>
for example a document that results in the following lines, notably the repetition of household, the output would be:
'household' affordable. This `mortgage burden' is often defined as the proportion of household income spent on repaying a mortgage. Depending on the household income measure used, the mortgage burden on a newly purchased first home, assuming a person borrows 80 per cent of the value of the home, is currently lower than much of the period between
Lastly the error message contains the md5sum
of the file is returned in the error message, so it can be supplied to md5sum.ok
.
Check dashes entered as hyphens
check_dashes( filename, .report_error, dash.consistency = c("en-dash", "em-dash"), protases_ok = TRUE, rstudio = TRUE )
check_dashes( filename, .report_error, dash.consistency = c("en-dash", "em-dash"), protases_ok = TRUE, rstudio = TRUE )
filename |
A tex or Rnw file. |
.report_error |
How errors should be reported. |
dash.consistency |
Character vector permitted dash types. |
protases_ok |
(logical, default: |
rstudio |
(logical, default: |
File stops and cat()
s on any line where a hyphen is surrounded by a space.
Excludes dashes in knitr chunks and LaTeX math mode \(...\)
but not in TeX math mode $...$
.
Checks file for unescaped dollar signs.
With these present, there is a risk of constructions like We gave $10 to a million people at a cost of $10~million dollars.
,
which is valid syntax, but incorrectly formatted. Accordingly, math-mode must be more assertively requested using \(..\)
.
check_escapes(filename, .report_error)
check_escapes(filename, .report_error)
filename |
File in which to report the error |
.report_error |
How the errors should be reported. |
An error if unescaped dollar signs are present in filename
. Otherwise, NULL
invisibly.
Check footnote typography
check_footnote_typography( filename, ignore.lines = NULL, .report_error, rstudio = FALSE )
check_footnote_typography( filename, ignore.lines = NULL, .report_error, rstudio = FALSE )
filename |
A LaTeX file. |
ignore.lines |
Lines to ignore (for example, those using the word 'footnote'). |
.report_error |
A function to provide context to any errors. |
rstudio |
(logical, default: |
See https://github.com/grattan/grattex/blob/master/doc/grattexDocumentation.pdf for full set of error conditions.
Called for its side-effect.
## Not run: tex_file <- tempfile(fileext = ".tex") cat("Footnote not ending with full stop.\\footnote{No sentence}", file = tex_file) check_footnote_typography(tex_file) ## End(Not run)
## Not run: tex_file <- tempfile(fileext = ".tex") cat("Footnote not ending with full stop.\\footnote{No sentence}", file = tex_file) check_footnote_typography(tex_file) ## End(Not run)
Check labels
check_labels(filename, .report_error, check.chaprefs = TRUE)
check_labels(filename, .report_error, check.chaprefs = TRUE)
filename |
The LaTeX source file to check. |
.report_error |
The function to provide context to the error. |
check.chaprefs |
(logical, default: |
Checks each label has a prefix and the prefix is one of the following:
fig:
,
tbl:
,
box:
,
chap:
,
sec:
,
eq:
,
subsec:
,
subsubsec:
,
para:
paragraph:
.
Checks also that chapter labels are marked with chap:
.
(N.B. although each label must have a prefix, it must not necessarily the right prefix;
for example, a table caption may have prefix tbl:
.)
NULL
, invisibly if labels check out. An error otherwise.
Check that citations are all using cites
check_literal_citations(filename, .report_error)
check_literal_citations(filename, .report_error)
filename |
TeX document |
.report_error |
Function to report errors |
Check for hard-coded cross-references
check_literal_xrefs(filename, .report_error)
check_literal_xrefs(filename, .report_error)
filename |
The TeX file to check |
.report_error |
How errors should be reported. |
An error, or if none found, NULL
invisibly.
Checks whether a closing quote has been used at the start of a word.
check_quote_marks(filename, .report_error, rstudio = FALSE)
check_quote_marks(filename, .report_error, rstudio = FALSE)
filename |
LaTeX filename. |
.report_error |
A function determining how errors will be reported. |
rstudio |
Use the |
## Not run: tex_file <- tempfile(fileext = ".tex") cat("This is the wrong 'quote' mark.", file = tex_file) check_quote_marks(tex_file) file.remove(tex_file) ## End(Not run)
## Not run: tex_file <- tempfile(fileext = ".tex") cat("This is the wrong 'quote' mark.", file = tex_file) check_quote_marks(tex_file) file.remove(tex_file) ## End(Not run)
Spell checking
check_spelling( filename, tex_root = dirname(filename), pre_release = TRUE, ignore.lines = NULL, known.correct = NULL, known.correct.fixed = NULL, known.wrong = NULL, ignore_spelling_in = NULL, ignore_spelling_in_nth = NULL, bib_files, check_etcs = TRUE, dict_lang = "en_GB", rstudio = FALSE, .report_error )
check_spelling( filename, tex_root = dirname(filename), pre_release = TRUE, ignore.lines = NULL, known.correct = NULL, known.correct.fixed = NULL, known.wrong = NULL, ignore_spelling_in = NULL, ignore_spelling_in_nth = NULL, bib_files, check_etcs = TRUE, dict_lang = "en_GB", rstudio = FALSE, .report_error )
filename |
Path to a LaTeX file to check. |
tex_root |
The root path of the filename. Provide this if you are checking an |
pre_release |
Should the document be assumed to be final?
Setting to |
ignore.lines |
Integer vector of lines to ignore (due to possibly spurious errors). |
known.correct |
Character vector of patterns known to be correct (which will never be raised by this function). |
known.correct.fixed |
Character vector of words known to be correct (which will never be raised by this function). |
known.wrong |
Character vector of patterns known to be wrong. |
ignore_spelling_in |
Command whose first mandatory argument will be ignored. |
ignore_spelling_in_nth |
Named list of arguments to ignore; names are the commands to be ignored, values are the |
bib_files |
Bibliography files (containing possible clues to misspellings). If supplied, and
this function would otherwise throw an error, the |
check_etcs |
If |
dict_lang |
Passed to |
rstudio |
Use the RStudio API? |
.report_error |
A function to provide context to any errors. If missing, defaults to
|
Extends and enhances hunspell
:
You can add directives
in the document itself. To add a word foobaz
to the dictionary (so its presence does not
throw an error), write % add_to_dictionary: foobaz
on a single line. The advantage of
this method is that you can collaborate on the document without having to keep track of which
spelling errors are genuine.
The
directive % ignore_spelling_in: mycmd
which will ignore the spelling of words within the first argument
of \mycmd
.
ignore_spelling_in_file: <file.tex>
will skip the check of <file.tex>
if it
is input
or include
in filename
, as well as any files within it. Should
appear as it is within input
but with the file extension
Only the root document need be supplied;
any files that are fed via \input
or \include
are checked (recursively).
A historical advantages was that the contents of certain commands were not checked, the spelling of which need not be checked
as they are not printed, viz.
citation and cross-reference commands, and certain optional
arguments. Most of these
are now parsed correctly by hunspell
, though some still need to be
supplied (including, naturally, user-supplied macros).
Abbreviations and initialisms which are validly introduced will not throw errors. See
extract_valid_abbrevations
.
Words preceded by '[sic]' will not throw errors.
The package comes with a suite of correctly_spelled_words
that were not present in hunspell
's
dictionary.
This function should be quite fast, but slower than hunspell::hunspell
(which it invokes).
I aim for less than 500 ms on a real-world report of around 100 pages.
The function is slower when it needs to consult bib_files
, though I recommend adding authors, titles, etc.
to the dictionary
explicitly, or using citeauthor
and friends.
This function is forked from https://github.com/hughparsonage/grattanReporter to parse reports of the Grattan Institute, Melbourne for errors. See https://github.com/grattan/grattex/blob/master/doc/grattexDocumentation.pdf for the full spec. Some checks that package performs have been omitted in this package.
Called primarily for its side-effect. If the spell check fails, the line at which the
first error was detected, with an error message. If the check succeeds, NULL
invisibly.
## Not run: url_bib <- paste0("https://raw.githubusercontent.com/HughParsonage/", "grattex/e6cab97145d38890e44e83d122e995e3b8936fc6/", "Report.tex") check_spelling(url_bib) ## End(Not run)
## Not run: url_bib <- paste0("https://raw.githubusercontent.com/HughParsonage/", "grattex/e6cab97145d38890e44e83d122e995e3b8936fc6/", "Report.tex") check_spelling(url_bib) ## End(Not run)
Check cross-references that are repetitive or (in the case of cleveref
and varioref
) incorrect case.
check_xrefs(filename, permitted.case = c(NA, "upper", "lower"), .report_error)
check_xrefs(filename, permitted.case = c(NA, "upper", "lower"), .report_error)
filename |
A LaTeX file |
permitted.case |
One of |
.report_error |
The function to provide context to the error. |
List all unique commands in a document
commands_used(tex_lines)
commands_used(tex_lines)
tex_lines |
A LaTeX document as read from |
A character vector of unique commands used in tex_lines
.
commands_used(c("A \\abc{d}", "\\def{x}"))
commands_used(c("A \\abc{d}", "\\def{x}"))
List of correctly spelled words
correctly_spelled_words
correctly_spelled_words
A character vector of words as perl-regex patterns to skip during the spell check.
List of correctly spelled, case-sensitive words
CORRECTLY_SPELLED_WORDS_CASE_SENSITIVE
CORRECTLY_SPELLED_WORDS_CASE_SENSITIVE
A character vector of words as perl-regex case-sensitive patterns to skip during the spell check.
This is a simple wrapper around extract_mandatory_LaTeX_argument
and extract_optional_LaTeX_argument
.
extract_LaTeX_argument(tex_lines, command_name, n = 1L, optional = FALSE)
extract_LaTeX_argument(tex_lines, command_name, n = 1L, optional = FALSE)
tex_lines |
LaTeX text. |
command_name |
Name of command without backslash |
n |
Which argument to extract, if exists. |
optional |
Extract the optional argument, rather than the mandatory arguments. |
Extract mandatory argument II
extract_mandatory_LaTeX_argument( tex_lines, command_name, n = 1L, by.line = FALSE, parsed_doc = NULL )
extract_mandatory_LaTeX_argument( tex_lines, command_name, n = 1L, by.line = FALSE, parsed_doc = NULL )
tex_lines |
A character vector of lines as read from a LaTeX document. |
command_name |
The command name (no backslash or opening brace). |
n |
Which integer to |
by.line |
If |
parsed_doc |
A parsed document (from |
Extract optional argument
extract_optional_LaTeX_argument( tex_lines, command_name, n = 1L, by.line = FALSE )
extract_optional_LaTeX_argument( tex_lines, command_name, n = 1L, by.line = FALSE )
tex_lines |
A character vector reading from a LaTeX document. |
command_name |
Name of command (without backslash) |
n |
Which optional argument to extract. |
by.line |
Should the output be one row per command ( |
Extracts abbreviations which are preceded by the full text (e.g. 'The Quebec Xylophone Enterprise Foundation (QXEF)').
extract_validate_abbreviations(lines)
extract_validate_abbreviations(lines)
lines |
Lines to extract |
Only 'valid' abbreviations are extracted, viz. those abbreviations of the form (ABC)
where the first letters
of the preceding words
(excluding some common words like of
, and
, etc.) are 'a', 'b', 'c'.
Character vector of abbreviations of the form (ABC)
Useful for checking whether all the figures and tables in a document have been
referenced in the main text. You may exclude figures and tables from the check by using
the directive
% may_be_left_unreferenced:
in the preamble before the label that is to be excluded.
figs_tbls_unrefd(filename, .report_error, check.labels = TRUE)
figs_tbls_unrefd(filename, .report_error, check.labels = TRUE)
filename |
A LaTeX file. |
.report_error |
A function to provide context to any errors. |
check.labels |
if |
The labels of any figure or table left unreferenced in filename
(including inputs).
Inputs to files nested within LaTeX document
inputs_of(filename, exclude.preamble = TRUE, append.tex = TRUE)
inputs_of(filename, exclude.preamble = TRUE, append.tex = TRUE)
filename |
The file whose |
exclude.preamble |
(logical) If |
append.tex |
Should the result include the file extension |
A character vector of file paths relative to filename
that are
used as \input
s or \include
s within filename
. If
no such files are present within filename
, NULL
is returned.
Is a line in knitr R or not?
isR_line_in_knitr(lines)
isR_line_in_knitr(lines)
lines |
Lines to check, as in the result of |
TRUE
if in knitr chunk (including boundaries). FALSE
otherwise.
Tidy bibliography so equals signs align
lint_bib(bib_file, outfile = bib_file, leading_spaces = 2L)
lint_bib(bib_file, outfile = bib_file, leading_spaces = 2L)
bib_file |
The bib file to tidy. |
outfile |
Optionally, the tidied bib file to write to. |
leading_spaces |
The number of spaces before each field within an entry. |
Aligns the equals signs in bib_file
and ensures all fields have a trailing comma.
Provides the locations of LaTeX commands with mandatory arguments.
locate_mandatory_LaTeX_argument( tex_lines, command_name, n = 1L, parsed_doc = NULL )
locate_mandatory_LaTeX_argument( tex_lines, command_name, n = 1L, parsed_doc = NULL )
tex_lines |
A character vector of a LaTeX document,
– for example as obtained from |
command_name |
The command (without backslash) whose arguments' locations are desired. |
n |
Integer vector: which argument(s) to locate. If |
parsed_doc |
The result of |
Generate a minimal bibliography file
minimal_bib(path = ".", bbl.file = NULL, bib.files = NULL, out.bib = bib.files)
minimal_bib(path = ".", bbl.file = NULL, bib.files = NULL, out.bib = bib.files)
path |
A directory containing a document after it has been run with |
bbl.file |
A |
bib.files |
The |
out.bib |
The new file of bibliography. |
Parse LaTeX lines
parse_tex(tex_lines)
parse_tex(tex_lines)
tex_lines |
Character vector (as read from a |
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
.
parse_tex(c("A{}", "B[a]{b{c}{d}}z")) # 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..........
parse_tex(c("A{}", "B[a]{b{c}{d}}z")) # 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..........
Position of strings
position_of_string(tex_line_split, command_split, end = TRUE) positions_of_all_strings(tex_line, command_name, end = TRUE)
position_of_string(tex_line_split, command_split, end = TRUE) positions_of_all_strings(tex_line, command_name, end = TRUE)
tex_line_split |
A split line (via |
command_split |
The string the position of which is desired, split (via |
end |
(logical) Should the position of the end of the string.
By default, |
tex_line |
A line of text. |
command_name |
The string the position of which is desired. |
The end (or start if end = FALSE) of the location of command
Read a LaTeX document
read_tex_document(file_root)
read_tex_document(file_root)
file_root |
The root of the TeX file. |
Report errors to console
report2console( file = NULL, line_no = NULL, column = NULL, context = NULL, error_message = NULL, advice = NULL, build_status = NULL, extra_cat_ante = NULL, extra_cat_post = NULL, caret = FALSE, rstudio = FALSE, log_file = NULL, log_file_sep = "|", silent = FALSE, halt = getOption("TeXCheckR.halt_on_error", FALSE), as_tbl = getOption("TeXCheckR.error_as_tbl", FALSE) )
report2console( file = NULL, line_no = NULL, column = NULL, context = NULL, error_message = NULL, advice = NULL, build_status = NULL, extra_cat_ante = NULL, extra_cat_post = NULL, caret = FALSE, rstudio = FALSE, log_file = NULL, log_file_sep = "|", silent = FALSE, halt = getOption("TeXCheckR.halt_on_error", FALSE), as_tbl = getOption("TeXCheckR.error_as_tbl", FALSE) )
file |
The file in which the error occurred. |
line_no |
The line number locating the source of the error. |
column |
The position on the line to identify the error (usually following the error). |
context |
The content of the file, to provide context to the error. |
error_message |
The error message to display beyond the console. |
advice |
Advice to the user: how should the detected error be resolved in general? |
build_status |
What should the build status be reported as? |
extra_cat_ante |
Character vector extra messages (placed before |
extra_cat_post |
Character vector extra messages (placed after |
caret |
(logical, default: Length-one integer values of |
rstudio |
If available, should the report be allowed to modify the RStudio session (for example, to pop to the location of the error)? |
log_file |
Optionally, path to a log file on which |
log_file_sep |
How should the log file's fields be separated? By default, with a pipe (as tabs are common within error messages). |
silent |
(logical, default: |
halt |
Should failures halt via |
as_tbl |
Return a list. Experimental. |
Change text such as phas[e] out
to phase out
,
without removing square brackets denoting optional arguments.
rm_editorial_square_brackets(tex_lines)
rm_editorial_square_brackets(tex_lines)
tex_lines |
Lines (as from |
x <- "the BCA's call to `urgently phas[e] out all side deals'" rm_editorial_square_brackets(x)
x <- "the BCA's call to `urgently phas[e] out all side deals'" rm_editorial_square_brackets(x)
Put sentences on their own line
separate_sentences(filename, hanging_footnotes = FALSE)
separate_sentences(filename, hanging_footnotes = FALSE)
filename |
A tex or knitr file in which to separate sentences. |
hanging_footnotes |
(logical, default: |
NULL. The function is called for its side-effect: rewriting filename
with separated sentences.
Split report into include-able files
split_report( Report.tex, include = TRUE, subdir = "tex", use.chapter.title = TRUE, out.tex = Report.tex )
split_report( Report.tex, include = TRUE, subdir = "tex", use.chapter.title = TRUE, out.tex = Report.tex )
Report.tex |
File to split. |
include |
Should |
subdir |
What directory should each chapter file be written in? By default, a subdirectory of the folder containing |
use.chapter.title |
Should the chapter title be used to name the chapter files? If |
out.tex |
The new root file. By default, same as |
Strip comments from LaTeX lines
strip_comments(lines, retain.percent.symbol = TRUE)
strip_comments(lines, retain.percent.symbol = TRUE)
lines |
Character vector of a LaTeX document. |
retain.percent.symbol |
(logical, default: |
lines
but with all text to the right of every unescaped %
removed
some_lines <- c("Text. % A comment", "20\\% of comments are % useful") strip_comments(some_lines) strip_comments(some_lines, retain.percent.symbol = FALSE)
some_lines <- c("Text. % A comment", "20\\% of comments are % useful") strip_comments(some_lines) strip_comments(some_lines, retain.percent.symbol = FALSE)
Opening a brace increases the 'group' in TeX. For example, in a{bc}{d{e}}
a
is in group 0, bc
in group 1 as is d
and e
is in group 2.
tex_group_by_char(tex_lines, optional = FALSE)
tex_group_by_char(tex_lines, optional = FALSE)
tex_lines |
Character vector of a document LaTeX. |
optional |
If |
A list the same length as lines
. Each element an integer vector indicating the
TeX group at that position.
For positions at braces the upcoming group is returned.
So a{b}
should return 0 1 1 0
(in its first element).
tex_group_by_char("a{bc}{d{e}}")
tex_group_by_char("a{bc}{d{e}}")
List of words which should never raise a spelling error.
valid_English_contractions
valid_English_contractions
An object of class character
of length 110.
Validate bibliography according to Grattan style
validate_bibliography(path = ".", file = NULL, .report_error, rstudio = FALSE)
validate_bibliography(path = ".", file = NULL, .report_error, rstudio = FALSE)
path |
Containing the bib file. |
file |
The bib file if specified. |
.report_error |
How errors should be reported. |
rstudio |
Use the RStudio API to jump to errors. |
This is a highly fastidious test of the bibliography. Useful for collaboration to ensure consistent style.
NULL
if bibliography validated.
## Not run: bib_temp <- tempfile(fileext = ".bib") url_bib <- paste0("https://raw.githubusercontent.com/HughParsonage/", "grattex/e6cab97145d38890e44e83d122e995e3b8936fc6", "/bib/Grattan-Master-Bibliography.bib") download.file(url_bib, destfile = bib_temp) validate_bibliography(file = bib_temp) bib_temp <- tempfile(fileext = ".bib") url_bib <- paste0("https://raw.githubusercontent.com/HughParsonage/", "grattex/8f7f52a28789d12a363ceb30cea3b41f590ae58a", "/bib/Grattan-Master-Bibliography.bib") download.file(url_bib, destfile = bib_temp) validate_bibliography(file = bib_temp) ## End(Not run)
## Not run: bib_temp <- tempfile(fileext = ".bib") url_bib <- paste0("https://raw.githubusercontent.com/HughParsonage/", "grattex/e6cab97145d38890e44e83d122e995e3b8936fc6", "/bib/Grattan-Master-Bibliography.bib") download.file(url_bib, destfile = bib_temp) validate_bibliography(file = bib_temp) bib_temp <- tempfile(fileext = ".bib") url_bib <- paste0("https://raw.githubusercontent.com/HughParsonage/", "grattex/8f7f52a28789d12a363ceb30cea3b41f590ae58a", "/bib/Grattan-Master-Bibliography.bib") download.file(url_bib, destfile = bib_temp) validate_bibliography(file = bib_temp) ## End(Not run)
Vetoes words in a LaTeX document that are marked '[sic]' for the purpose of spell checking by replacing them (and '[sic]' itself) with white space of equal length.
veto_sic(tex_lines, quote = TRUE, sentence = !quote, words_ante = 1L)
veto_sic(tex_lines, quote = TRUE, sentence = !quote, words_ante = 1L)
tex_lines |
A character vector. |
quote |
(logical, default: |
sentence |
(logical, default: |
words_ante |
The number of words to exclude. Ignored if |
Unbreaking spaces between billion and million
weld_bmillion(filename, outfile = filename)
weld_bmillion(filename, outfile = filename)
filename |
A LaTeX or knitr file. |
outfile |
The file to write to, defaults to |
NULL. This function is called for its side-effect: rewriting filename
with 30 million
changed to 30~million
.
List of wrongly spelled words
wrongly_spelled_words
wrongly_spelled_words
A regex of patterns to raise as spelling errors.