ReplacePreambleCommand: ReplacePreambleCommand

Description Usage Arguments Details Value See Also Examples

View source: R/PreambleAdjustment.R


This functions gets a character vector in which each element represents a line of a preamble of a 'LaTeX' document, and it replaces the definition of the command \commandName to have the value commandValue.


ReplacePreambleCommand(x, commandName, commandValue)



A character vector, each element is suppose to represent a line


A string identifying either the command name


Replacement for the definition of commandName


It only modifies the value of the command by replacing instances of

\newcommand{\commandName}{<previous definition>} with instances of


Keep in mind that both commandName and commandValue are placed directly inside a regex.

If you want to "hide" a certain definition of a command from being found and replaced by this function, simply define it by using \def or \newcommand* or a \renewcommand when you define them.

Make sure you are using a one-line definition in commands that you want replaced, since this won't be able to detect commands that are defined in multiple lines in 'LaTeX'.

Also, note how certain invalid things in 'LaTeX' would still be matched by this regex, however you should find those errors before you start using this program since those errors would not allow you to compile the 'LaTeX' document on the first place.

Lastly, if it doesn't find a command on the document, it silently ignores it.


A character vector, with the preamble, replacing all instances of \newcommand\commandName{<random text>} with \newcommand\commandName{commandValue}

See Also

Other Preamble adjustment: ReplaceFromTable


new_preamble <- ReplacePreambleCommand( TexExamRandomizer::testdoc$preamble, "nickname", "Alex")

TexExamRandomizer documentation built on May 2, 2019, 3:18 a.m.