lstsetLanguage(pkgs, posIdx, keywordstyles, overwrite = FALSE)
search()
list from which the
symbols are to be registered.Keywordstyle
is read off
by using
getSweaveListingOption("Keywordstyle")
.
Internally, it is being cast to the same linvisible()
pkgs
and posIdx
can be used independently from each other:
If there is an argument pkgs
, after checking whether these packages are
already on the search list, we unite the corresponding search list positions
with those of argument posIdx
(if the latter is given);
the positions corresponding to packages already in the .alreadyDefinedPkgs
vector (see below), are filtered out, however. If argument
pkgs
is missing, by default the whole list of attached packages gained
from .packages()
is taken in the beginning.
For registering the new symbols, we write out a
\lstdefinelanguage{R}%
{morekeywords=[
is
a comma-separated list of the keywords to be registered printed out as
five items per line; we get this list by a corresponding
ls(pos=)
command. If argument overwrite
is FALSE
,
before registration, we filter out the keywords already in the original
may be a string containing
any sequence of TeX formatting commands like
"\\bfseries\\footnotesize"
. Note that backslashes have to be escaped.
To be able to distinguish/manage several keyword format styles on R-side, we
append the name of each package, the symbols of which are registered, to the
(non-exported) vector object .alreadyDefinedPkgs
, which is hidden in the
namespace of this package.
On TeX/
information in the
morekeywords
tag; it is identified with num+2
where num
is the index of the package in the .alreadyDefinedPkgs
vector.
The settings of these format styles may afterwords be overwritten
using changeKeywordstyles
.
For use in an .Rnw
file, the call to lstsetlanguage
should be
wrapped into a corresponding Sweave chunk in the form
<< /chunkname/, results=tex, echo=FALSE>>=
lstsetLanguage( ..... )
@
for example
<require(MASS)
lstsetLanguage(pkgs = c("MASS","stats"),
keywordstyles = paste("\\bfseries\\color{",c("blue","red"),"}",
sep="", collapse=""))
### not to be used:
print(SweaveListingUtils:::.alreadyDefinedPkgs)
print(SweaveListingUtils:::.keywordsR)
Run the code above in your browser using DataLab