[Rcpp-commits] r3960 - pkg/Rcpp/inst/doc/Rcpp-attributes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 13 15:31:31 CET 2012


Author: jjallaire
Date: 2012-11-13 15:31:31 +0100 (Tue, 13 Nov 2012)
New Revision: 3960

Modified:
   pkg/Rcpp/inst/doc/Rcpp-attributes/Rcpp-attributes.Rnw
Log:
improved syntax highlighting for attributes vignette

Modified: pkg/Rcpp/inst/doc/Rcpp-attributes/Rcpp-attributes.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-attributes/Rcpp-attributes.Rnw	2012-11-13 14:07:50 UTC (rev 3959)
+++ pkg/Rcpp/inst/doc/Rcpp-attributes/Rcpp-attributes.Rnw	2012-11-13 14:31:31 UTC (rev 3960)
@@ -31,6 +31,7 @@
 \title{\pkg{Rcpp} Attributes}
 \date{\pkg{Rcpp} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}}
 
+
 %% highlights macros
 %% Style definition file generated by highlight 2.7, http://www.andre-simon.de/
 % Highlighting theme definition:
@@ -42,8 +43,8 @@
 \newcommand{\hlstr}[1]{\textcolor[rgb]{0.90,0.15,0.15}{#1}}
 %green: \newcommand{\hlstr}[1]{\textcolor[rgb]{0.13,0.67,0.13}{#1}} % 0.74 -> % 0.90; 0.55 -> 0.25
 \newcommand{\hldstr}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
-\newcommand{\hlslc}[1]{\textcolor[rgb]{0.67,0.13,0.13}{\it{#1}}}
-\newcommand{\hlcom}[1]{\textcolor[rgb]{0.67,0.13,0.13}{\it{#1}}}
+\newcommand{\hlslc}[1]{\textcolor[rgb]{0.67,0.13,0.13}{#1}}
+\newcommand{\hlcom}[1]{\textcolor[rgb]{0.67,0.13,0.13}{#1}}
 \newcommand{\hldir}[1]{\textcolor[rgb]{0,0,0}{#1}}
 \newcommand{\hlsym}[1]{\textcolor[rgb]{0,0,0}{#1}}
 \newcommand{\hlline}[1]{\textcolor[rgb]{0.33,0.33,0.33}{#1}}
@@ -54,6 +55,27 @@
 \definecolor{bgcolor}{rgb}{1,1,1}
 \newcommand{\hlppc}[1]{\textcolor[rgb]{0,0.51,0}{#1}}
 
+\usepackage{framed}
+\definecolor{shadecolor}{RGB}{242, 242, 242}
+\makeatletter
+\newenvironment{kframe}{%
+ \def\at at end@of at kframe{}%
+ \ifinner\ifhmode%
+  \def\at at end@of at kframe{\end{minipage}}%
+  \begin{minipage}{\columnwidth}%
+ \fi\fi%
+ \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
+ \colorbox{shadecolor}{##1}\hskip-\fboxsep
+     % There is no \\@totalrightmargin, so:
+     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
+ \MakeFramed {\advance\hsize-\width
+   \@totalleftmargin\z@ \linewidth\hsize
+   \@setminipage}}%
+ {\par\unskip\endMakeFramed%
+ \at at end@of at kframe}
+\makeatother
+
+
 \begin{document}
 \maketitle
 
@@ -146,7 +168,7 @@
 
 %% can use "figure" or "quote" or ...
 %% converted via 'highlight --enclose-pre --no-doc --out-format=latex --syntax=C++'
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
 \hlstd{}\hlppc{\#include\ $<$Rcpp.h$>$}\hspace*{\fill}\\
@@ -164,11 +186,11 @@
 \hlstd{}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ }\hlstd{xab}\hlopt{{[}}\hlstd{i\ }\hlopt{+\ }\hlstd{j}\hlopt{{]}\ +=\ }\hlstd{a}\hlopt{{[}}\hlstd{i}\hlopt{{]}\ {*}\ }\hlstd{b}\hlopt{{[}}\hlstd{j}\hlopt{{]};}\hspace*{\fill}\\
 \hlstd{\hspace*{\fill}\\
 }\hlstd{\ \ \ \ }\hlstd{}\hlkwa{return\ }\hlstd{xab}\hlopt{;}\hspace*{\fill}\\
-\hlstd{}\hlopt{\}}\hlstd{}\hspace*{\fill}\\
+\hlstd{}\hlopt{\}}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 The addition of the export attribute allows us to do this from the \proglang{R}
 prompt:
@@ -179,15 +201,15 @@
 % \end{verbatim}
 
 %% converted via 'highlight --enclose-pre --no-doc --out-format=latex --syntax=R'
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
-\hlstd{}\hlopt{$>$\ }\hlstd{}\hlkwd{sourceCpp}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"convolve.cpp"}\hlstd{}\hlopt{)}\hspace*{\fill}\\
-\hlstd{}\hlopt{$>$\ }\hlstd{}\hlkwd{convolveCpp}\hlstd{}\hlopt{(}\hlstd{x}\hlopt{,\ }\hlstd{y}\hlopt{)}\hlstd{}\hspace*{\fill}\\
+\hlstd{}\hlopt{>\ }\hlstd{}\hlkwd{sourceCpp}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"convolve.cpp"}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+\hlstd{}\hlopt{>\ }\hlstd{}\hlkwd{convolveCpp}\hlstd{}\hlopt{(}\hlstd{x}\hlopt{,\ }\hlstd{y}\hlopt{)}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 
 We can now write \proglang{C++} functions using standard \proglang{C++} types
@@ -205,15 +227,15 @@
 % NumericVector convolveCpp(NumericVector a, NumericVector b)
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
 \hlstd{}\hlslc{//\ {[}{[}Rcpp::export(".convolveCpp"){]}{]}}\hspace*{\fill}\\
-\hlstd{NumericVector\ }\hlkwd{convolveCpp}\hlstd{}\hlopt{(}\hlstd{NumericVector\ a}\hlopt{,\ }\hlstd{NumericVector\ b}\hlopt{)}\hlstd{}\hspace*{\fill}\\
+\hlstd{NumericVector\ }\hlkwd{convolveCpp}\hlstd{}\hlopt{(}\hlstd{NumericVector\ a}\hlopt{,\ }\hlstd{NumericVector\ b}\hlopt{)}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 The \texttt{sourceCpp} function performs caching based on the last
 modified date of the source file so as long as the source file does not
@@ -252,7 +274,7 @@
 % }
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
 \hlstd{}\hlslc{//\ {[}{[}Rcpp::depends(RcppArmadillo){]}{]}}\hspace*{\fill}\\
@@ -277,11 +299,11 @@
 \hlstd{\hspace*{\fill}\\
 }\hlstd{\ \ \ \ }\hlstd{}\hlkwa{return\ }\hlstd{List}\hlopt{::}\hlstd{}\hlkwd{create}\hlstd{}\hlopt{(}\hlstd{}\hlkwd{Named}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"coefficients"}\hlstd{}\hlopt{)\ =\ }\hlstd{coef}\hlopt{,}\hspace*{\fill}\\
 \hlstd{}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlstd{}\hlkwd{Named}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"stderr"}\hlstd{}\hlopt{)}\hlstd{\ \ \ \ \ \ \ }\hlopt{=\ }\hlstd{stderrest}\hlopt{);}\hspace*{\fill}\\
-\hlstd{}\hlopt{\}}\hlstd{}\hspace*{\fill}\\
+\hlstd{}\hlopt{\}}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 The inclusion of the \texttt{Rcpp::depends} attribute causes \texttt{sourceCpp}
 to configure the build environment to correctly compile and link against the
@@ -292,14 +314,14 @@
 % // [[Rcpp::depends(Matrix, RcppArmadillo)]]
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
-\hlstd{}\hlslc{//\ {[}{[}Rcpp::depends(Matrix,\ RcppArmadillo){]}{]}}\hlstd{}\hspace*{\fill}\\
+\hlstd{}\hlslc{//\ {[}{[}Rcpp::depends(Matrix,\ RcppArmadillo){]}{]}}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 Dependencies are discovered both by scanning for package include directories
 and by invoking \pkg{inline} plugins if they are available for a package.
@@ -328,23 +350,23 @@
 % > evalCpp('std::numeric_limits<double>::max()')
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
-\hlstd{}\hlopt{$>$\ }\hlstd{}\hlkwd{cppFunction}\hlstd{}\hlopt{(}\hlstd{}\hlstr{'}\hspace*{\fill}\\
+\hlstd{}\hlopt{>\ }\hlstd{}\hlkwd{cppFunction}\hlstd{}\hlopt{(}\hlstd{}\hlstr{\textquotesingle}\hspace*{\fill}\\
 \hlstr{}\hlstd{\ \ \ \ }\hlstr{int\ fibonacci(const\ int\ x)\ \{}\hspace*{\fill}\\
 \hlstr{}\hlstd{\ \ \ \ \ \ \ \ }\hlstr{if\ (x\ $<$\ 2)}\hspace*{\fill}\\
 \hlstr{}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ }\hlstr{return\ x;}\hspace*{\fill}\\
 \hlstr{}\hlstd{\ \ \ \ \ \ \ \ }\hlstr{else}\hspace*{\fill}\\
 \hlstr{}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ }\hlstr{return\ (fibonacci(x\ {-}\ 1))\ +\ fibonacci(x\ {-}\ 2);}\hspace*{\fill}\\
 \hlstr{}\hlstd{\ \ \ \ }\hlstr{\}}\hspace*{\fill}\\
-\hlstr{'}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+\hlstr{\textquotesingle}\hlstd{}\hlopt{)}\hspace*{\fill}\\
 \hlstd{}\hspace*{\fill}\\
-\hlopt{$>$\ }\hlstd{}\hlkwd{evalCpp}\hlstd{}\hlopt{(}\hlstd{}\hlstr{'std::numeric\textunderscore limits$<$double$>$::max()'}\hlstd{}\hlopt{)}\hlstd{}\hspace*{\fill}\\
+\hlopt{>\ }\hlstd{}\hlkwd{evalCpp}\hlstd{}\hlopt{(}\hlstd{}\hlstr{\textquotesingle std::numeric\textunderscore limits$<$double$>$::max()\textquotesingle}\hlstd{}\hlopt{)}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 You can also specify a depends parameter to \texttt{cppFunction} or \texttt{evalCpp}:
 
@@ -352,14 +374,14 @@
 % > cppFunction(depends = 'RcppArmadillo', code = '...')
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
-\hlstd{}\hlopt{$>$\ }\hlstd{}\hlkwd{cppFunction}\hlstd{}\hlopt{(}\hlstd{depends\ }\hlopt{=\ }\hlstd{}\hlstr{'RcppArmadillo'}\hlstd{}\hlopt{,\ }\hlstd{code\ }\hlopt{=\ }\hlstd{}\hlstr{'...'}\hlstd{}\hlopt{)}\hlstd{}\hspace*{\fill}\\
+\hlstd{}\hlopt{>\ }\hlstd{}\hlkwd{cppFunction}\hlstd{}\hlopt{(}\hlstd{depends\ }\hlopt{=\ }\hlstd{}\hlstr{\textquotesingle RcppArmadillo\textquotesingle}\hlstd{}\hlopt{,\ }\hlstd{code\ }\hlopt{=\ }\hlstd{}\hlstr{\textquotesingle ...\textquotesingle}\hlstd{}\hlopt{)}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 Note that using \texttt{sourceCpp}, \texttt{cppFunction}, and \texttt{evalCpp}
 require that \proglang{C++} development tools be available to build the code.
@@ -383,14 +405,14 @@
 % > compileAttributes()
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
-\hlstd{}\hlopt{$>$\ }\hlstd{}\hlkwd{compileAttributes}\hlstd{}\hlopt{()}\hlstd{}\hspace*{\fill}\\
+\hlstd{}\hlopt{>\ }\hlstd{}\hlkwd{compileAttributes}\hlstd{}\hlopt{()}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 Results in the generation of the following two source files:
 
@@ -416,14 +438,14 @@
 % // [[Rcpp::interfaces(r, cpp)]]
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
-\hlstd{}\hlslc{//\ {[}{[}Rcpp::interfaces(r,\ cpp){]}{]}}\hlstd{}\hspace*{\fill}\\
+\hlstd{}\hlslc{//\ {[}{[}Rcpp::interfaces(r,\ cpp){]}{]}}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 The \texttt{Rcpp::interfaces} attribute is specified on a per-source file basis.
 If you request a \texttt{cpp} interface for a source file then \texttt{compileAttributes}
@@ -457,7 +479,7 @@
 % }
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
 \hlstd{}\hlslc{//\ {[}{[}Rcpp::depends(MyPackage){]}{]}}\hspace*{\fill}\\
@@ -466,11 +488,11 @@
 \hlstd{}\hspace*{\fill}\\
 \hlkwb{void\ }\hlstd{}\hlkwd{foo}\hlstd{}\hlopt{()\ \{}\hspace*{\fill}\\
 \hlstd{}\hlstd{\ \ \ \ }\hlstd{MyPackage}\hlopt{::}\hlstd{}\hlkwd{bar}\hlstd{}\hlopt{();}\hspace*{\fill}\\
-\hlstd{}\hlopt{\}}\hlstd{}\hspace*{\fill}\\
+\hlstd{}\hlopt{\}}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 Note that the default behavior if an \texttt{Rcpp::interfaces} attribute
 is not included in a source file is to generate an R interface only.
@@ -497,19 +519,19 @@
 % NumericVector strLength(CharacterVector str)
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
-\hlstd{}\hlslc{//'\ The\ length\ of\ a\ string\ (in\ characters).}\hspace*{\fill}\\
-\hlstd{}\hlslc{//'}\hspace*{\fill}\\
-\hlstd{}\hlslc{//'\ @param\ str\ input\ character\ vector}\hspace*{\fill}\\
-\hlstd{}\hlslc{//'\ @return\ characters\ in\ each\ element\ of\ the\ vector}\hspace*{\fill}\\
+\hlstd{}\hlslc{//\textquotesingle\ The\ length\ of\ a\ string\ (in\ characters).}\hspace*{\fill}\\
+\hlstd{}\hlslc{//\textquotesingle}\hspace*{\fill}\\
+\hlstd{}\hlslc{//\textquotesingle\ @param\ str\ input\ character\ vector}\hspace*{\fill}\\
+\hlstd{}\hlslc{//\textquotesingle\ @return\ characters\ in\ each\ element\ of\ the\ vector}\hspace*{\fill}\\
 \hlstd{}\hlslc{//\ {[}{[}Rcpp::export{]}{]}}\hspace*{\fill}\\
-\hlstd{NumericVector\ }\hlkwd{strLength}\hlstd{}\hlopt{(}\hlstd{CharacterVector\ str}\hlopt{)}\hlstd{}\hspace*{\fill}\\
+\hlstd{NumericVector\ }\hlkwd{strLength}\hlstd{}\hlopt{(}\hlstd{CharacterVector\ str}\hlopt{)}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 Results in the following code in the generated \proglang{R} source file:
 
@@ -521,18 +543,18 @@
 % strLength <- function(str)
 % \end{verbatim}
 
-\begin{quote}
+\begin{kframe}
 \noindent
 \ttfamily
-\hlstd{}\hlslc{\#'\ The\ length\ of\ a\ string\ (in\ characters).}\hspace*{\fill}\\
-\hlstd{}\hlslc{\#'}\hspace*{\fill}\\
-\hlstd{}\hlslc{\#'\ @param\ str\ input\ character\ vector}\hspace*{\fill}\\
-\hlstd{}\hlslc{\#'\ @return\ characters\ in\ each\ element\ of\ the\ vector}\hspace*{\fill}\\
-\hlstd{strLength\ }\hlopt{$<${-}\ }\hlstd{}\hlkwa{function}\hlstd{}\hlopt{(}\hlstd{str}\hlopt{)}\hlstd{}\hspace*{\fill}\\
+\hlstd{}\hlslc{\#\textquotesingle\ The\ length\ of\ a\ string\ (in\ characters).}\hspace*{\fill}\\
+\hlstd{}\hlslc{\#\textquotesingle}\hspace*{\fill}\\
+\hlstd{}\hlslc{\#\textquotesingle\ @param\ str\ input\ character\ vector}\hspace*{\fill}\\
+\hlstd{}\hlslc{\#\textquotesingle\ @return\ characters\ in\ each\ element\ of\ the\ vector}\hspace*{\fill}\\
+\hlstd{strLength\ }\hlopt{$<${-}\ }\hlstd{}\hlkwa{function}\hlstd{}\hlopt{(}\hlstd{str}\hlopt{)}\hlstd{}\hspace*{\fill}
 \mbox{}
 \normalfont
 \normalsize
-\end{quote}
+\end{kframe}
 
 \subsection{Packages and sourceCpp}
 



More information about the Rcpp-commits mailing list