[Rcpp-commits] r3247 - pkg/RcppEigen/inst/doc

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Oct 30 03:15:09 CET 2011


Author: edd
Date: 2011-10-30 03:15:08 +0100 (Sun, 30 Oct 2011)
New Revision: 3247

Modified:
   pkg/RcppEigen/inst/doc/RcppEigen-Intro.Rnw
Log:
as a suggestion, consider this alternative to listings: using the external
highlight program by Andre Simon to generate latex code -- easy even from within emacs
the colors may need redefining though


Modified: pkg/RcppEigen/inst/doc/RcppEigen-Intro.Rnw
===================================================================
--- pkg/RcppEigen/inst/doc/RcppEigen-Intro.Rnw	2011-10-29 21:26:39 UTC (rev 3246)
+++ pkg/RcppEigen/inst/doc/RcppEigen-Intro.Rnw	2011-10-30 02:15:08 UTC (rev 3247)
@@ -18,6 +18,29 @@
 \newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}}
 \newcommand{\code}[1]{\texttt{#1}}
 \newcommand{\rank}{\operatorname{rank}}
+
+%% highlights macros
+%% Style definition file generated by highlight 2.7, http://www.andre-simon.de/
+% Highlighting theme definition:
+\newcommand{\hlstd}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlnum}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlesc}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+%\newcommand{\hlstr}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+\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{\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}}
+\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.61,0.13,0.93}{\bf{#1}}}
+\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.13,0.54,0.13}{#1}}
+\newcommand{\hlkwc}[1]{\textcolor[rgb]{0,0,1}{#1}}
+\newcommand{\hlkwd}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\definecolor{bgcolor}{rgb}{1,1,1}
+
+
 <<version,echo=FALSE,print=FALSE>>=
 prettyVersion <- packageDescription("RcppEigen")$Version
 prettyDate <- format(Sys.Date(), "%B %e, %Y")
@@ -53,10 +76,10 @@
 %% Below is what DE currently uses somewhere else -- I am not religuous about
 %% the grey background etc -- comment out and see if you like any of it
 %% Just like DB below, DE also uses  frame=tb  for top+bottom frame lines
-% \definecolor{darkgray}{rgb}{0.95,0.95,0.95}
-% \lstset{backgroundcolor=\color{darkgray}}
+\definecolor{lightgray}{rgb}{0.975,0.975,0.975}
+\lstset{backgroundcolor=\color{lightgray}}
 % \lstset{numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt}
-% \lstset{keywordstyle=\color{black}\bfseries\tt}
+\lstset{keywordstyle=\color{black}\bfseries\tt}
 % \lstset{ %
 %   %language=Octave,                % the language of the code
 %   %basicstyle=\footnotesize,       % the size of the fonts that are used for the code
@@ -91,7 +114,8 @@
   numerical linear algebra. \pkg{Rcpp} \citep{JSS:Rcpp} classes and
   specializations of the \proglang{C++} templated functions \code{as} and
   \code{wrap} from \pkg{Rcpp} provide the ``glue'' for passing objects from
-  \proglang{R} to \proglang{C++} and back.  }
+  \proglang{R} to \proglang{C++} and back.
+}
 
 \section{Introduction}
 \label{sec:intro}
@@ -201,9 +225,25 @@
 \code{Eigen} namespace, which means that they must be written as
 \code{Eigen::MatrixXd}.  However, if we preface our use of these class
 names with a declaration like
-\begin{lstlisting}[language=C++]
-using Eigen::MatrixXd;
-\end{lstlisting}
+
+% \begin{lstlisting}[language=C++]
+%using Eigen::MatrixXd;
+%\end{lstlisting}
+%
+%% Alternatively, use 'highlight --enclose-pre --no-doc --latex --style=emacs --syntax=C++'
+%% as the command invoked from C-u M-|
+%%
+%% keep one copy to redo later
+%%
+%% using Eigen::MatrixXd;
+%%
+\begin{quote}
+  \noindent
+  \ttfamily
+  \hlstd{}\hlkwa{using\ }\hlstd{Eigen}\hlsym{::}\hlstd{MatrixXd}\hlsym{;}\hlstd{}\hspace*{\fill}\\
+  \mbox{}
+  \normalfont
+\end{quote}
 we can use these names without the qualifier.
 
 \subsection{Mapped matrices in Eigen}
@@ -258,13 +298,24 @@
 \end{enumerate}
 
 An idiom for the first step is
-\begin{lstlisting}[language=C++]
-using Eigen::Map;
-using Eigen::MatrixXd;
-using Rcpp::as;
+%\begin{lstlisting}[language=C++]
+% using Eigen::Map;
+% using Eigen::MatrixXd;
+% using Rcpp::as;
 
-const Map<MatrixXd>  A(as<Map<MatrixXd> >(AA));
-\end{lstlisting}
+% const Map<MatrixXd>  A(as<Map<MatrixXd> >(AA));
+%\end{lstlisting}
+\begin{quote}
+  \noindent
+  \ttfamily
+  \hlstd{}\hlkwa{using\ }\hlstd{Eigen}\hlsym{::}\hlstd{Map}\hlsym{;}\hspace*{\fill}\\
+  \hlstd{}\hlkwa{using\ }\hlstd{Eigen}\hlsym{::}\hlstd{MatrixXd}\hlsym{;}\hspace*{\fill}\\
+  \hlstd{}\hlkwa{using\ }\hlstd{Rcpp}\hlsym{::}\hlstd{as}\hlsym{;}\hspace*{\fill}\\
+  \hlstd{}\hspace*{\fill}\\
+  \hlkwb{const\ }\hlstd{Map}\hlsym{$<$}\hlstd{MatrixXd}\hlsym{$>$}\hlstd{\ \ }\hlsym{}\hlstd{}\hlkwd{A}\hlstd{}\hlsym{(}\hlstd{as}\hlsym{$<$}\hlstd{Map}\hlsym{$<$}\hlstd{MatrixXd}\hlsym{$>$\ $>$(}\hlstd{AA}\hlsym{));}\hlstd{}\hspace*{\fill}\\
+  \mbox{}
+  \normalfont
+\end{quote}
 where \code{AA} is the name of the R object (called an \code{SEXP} in
 \proglang{C} and \proglang{C++}) passed to the \proglang{C++} function.
 
@@ -315,12 +366,30 @@
 return wrap(At);
 '
 @
-\begin{lstlisting}[frame=tb,caption={transCpp: Transpose a matrix of integers},label=trans]
-<<transCppLst,results=tex,echo=FALSE >>=
-cat(transCpp, "\n")
-@
-\end{lstlisting}
+%\begin{lstlisting}[frame=tb,caption={transCpp: Transpose a matrix of integers},label=trans]
+%<<transCppLst,results=tex,echo=FALSE >>=
+%cat(transCpp, "\n")
+%@
+%\end{lstlisting}
 
+\begin{figure}[h]
+  \caption{\code{transCpp}: Transpose a matrix of integers}
+  \label{trans}
+  \begin{quote}
+    \noindent
+    \ttfamily
+    \hlstd{}\hlkwa{using\ }\hlstd{Eigen}\hlsym{::}\hlstd{Map}\hlsym{;}\hspace*{\fill}\\
+    \hlstd{}\hlkwa{using\ }\hlstd{Eigen}\hlsym{::}\hlstd{MatrixXi}\hlsym{;}\hspace*{\fill}\\
+    \hlstd{}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlstd{}\hlslc{//\ Map\ the\ integer\ matrix\ AA\ from\ R}\hspace*{\fill}\\
+    \hlstd{}\hlkwb{const\ }\hlstd{Map}\hlsym{$<$}\hlstd{MatrixXi}\hlsym{$>$}\hlstd{\ \ }\hlsym{}\hlstd{}\hlkwd{A}\hlstd{}\hlsym{(}\hlstd{as}\hlsym{$<$}\hlstd{Map}\hlsym{$<$}\hlstd{MatrixXi}\hlsym{$>$\ $>$(}\hlstd{AA}\hlsym{));}\hspace*{\fill}\\
+    \hlstd{}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlstd{}\hlslc{//\ evaluate\ and\ return\ the\ transpose\ of\ A}\hspace*{\fill}\\
+    \hlstd{}\hlkwb{const\ }\hlstd{MatrixXi}\hlstd{\ \ \ \ \ \ }\hlstd{}\hlkwd{At}\hlstd{}\hlsym{(}\hlstd{A}\hlsym{.}\hlstd{}\hlkwd{transpose}\hlstd{}\hlsym{());}\hspace*{\fill}\\
+    \hlstd{}\hlkwa{return\ }\hlstd{}\hlkwd{wrap}\hlstd{}\hlsym{(}\hlstd{At}\hlsym{);}\hlstd{}\hspace*{\fill}\\
+    \mbox{}
+    \normalfont
+  \end{quote}
+\end{figure}
+
 We compile and link this code segment (stored as text in a variable named
 \code{transCpp}) into an executable function \code{ftrans} and check that it
 works as intended.



More information about the Rcpp-commits mailing list