returnCommandArg: returnCommandArg

Description Usage Arguments Details Value Examples

Description

Return an argument of a Tex command.

Usage

1
returnCommandArg(x, cmd, argNum = 1, optArg = FALSE)

Arguments

x

An array of character strings (lines from a Latex file) to process.

cmd

A character string naming the command to look for in x. This is the command, without the "\". cmd is simply pasted to the end of two slashes "\" and the results becomves a regular expression. Hence, regular expressions like "(ref|label)" will return arguments for the first \ref or \label command in x. cmd = "[0-9]" will return arguments of any command with a number in it. Etc.

argNum

The number of the argument to cmd that is desired.

optArg

True or false depending on whether one of the optional arguments or one of the required arguments is desired.

Details

Tex command is something like "\comand[opt1]arg1arg2", and this routine returns one of those arguments, either optional or required.

Value

The desired argument as a single text string. If the command does not exist in x, a string of length 0 (i.e., "") is returned. If the requested argument does not exist (e.g., argNum too big), a string of length 0 (i.e., "") is returned.

Examples

1
2
3
4
5
6
7
8
x <- c("kdkdk", "kdkd  \\title{My Title", "is Sir} dkdk")
returnCommandArg(x, "title")

x <- c("\\cmd[opt1][opt2]{arg1}{arg2}")
returnCommandArg(x, "cmd", 1)  # "arg1"
returnCommandArg(x, "cmd", 2)  # "arg2"
returnCommandArg(x, "cmd", 1, TRUE)  # "opt1"
returnCommandArg(x, "cmd", 2, TRUE)  # "opt2"

tmcd82070/tex2rmd documentation built on May 27, 2019, 8:46 a.m.