1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
<%@meta language="R-vignette" content="--------------------------------
DIRECTIVES FOR R:
%\VignetteIndexEntry{RSP Markup Language - Reference Card}
%\VignetteAuthor{Henrik Bengtsson}
%\VignetteKeyword{RSP markup language}
%\VignetteKeyword{Quick Reference Card}
%\VignetteEngine{R.rsp::rsp}
%\VignetteTangle{FALSE}
--------------------------------------------------------------------"%>
\documentclass[a4paper,10pt]{article}
\usepackage[landscape]{geometry}
<%
R.rsp <- R.oo::Package("R.rsp");
%>
<%@logical twocolumn="${twocolumn}" default="FALSE" description="Specifies whether a two- or one-column layout should be used."%>
<%@if twocolumn="TRUE"%>
\usepackage{multicol}
\setlength{\columnsep}{20pt}
<%@endif%>
<%-------------------------------------------------------------------
Assign PDF metadata
-------------------------------------------------------------------%>
% PDF metadata
\usepackage{hyperref}
% Ideally \hypersetup{hidelinks}, but for backward compatibility:
\hypersetup{pdfborder={0 0 0}}
\hypersetup{
pdfauthor={<%@meta name="author"%>},
pdftitle={<%@meta name="title"%>},
pdfsubject={},
pdfkeywords={<%@meta name="keywords"%>},
pdfproducer={R.rsp v<%=R.rsp$version%> by <%=R.rsp$author%>}
}
% Drop PTEX metadata (for reproducbility)
\pdfsuppressptexinfo=-1
\usepackage{xspace}
\usepackage{xcolor}
\usepackage{alltt}
% Do not display section numbers
\setcounter{secnumdepth}{0}
<%-------------------------------------------------------------------
DOCUMENT MODE SPECIFIC SETTINGS
-------------------------------------------------------------------%>
% Adjust margins
\addtolength{\oddsidemargin}{-1.0in}
\addtolength{\evensidemargin}{-1.0in}
\addtolength{\textwidth}{2in}
\addtolength{\topmargin}{-0.5in}
\addtolength{\textheight}{1.5in}
% Shrink white space around section headers ({left}{above}{below})
\usepackage[compact]{titlesec}
\titlespacing{\section}{0pt}{2.0ex}{0.5ex}
\titlespacing{\subsection}{0pt}{2.0ex}{0.5ex}
% No paragraph indentation
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}
% Line spacing
\linespread{0.95}
\usepackage{calc}
% No page numbers
\pagestyle{empty}
\newcommand{\keywords}[1]{\footnotesize{\textbf{Keywords: }#1}\xspace}
\newcommand{\pkg}[1]{\textsl{#1}\xspace}
\newcommand{\code}[1]{\texttt{#1}\xspace}
\newcommand{\content}[1]{$\langle${#1}$\rangle$}
\newcommand{\bs}{$\backslash$}
\newcommand{\lb}{\linebreak[0]}
\newenvironment{remark}{\vspace{1.0ex}\hspace{-\parindent}\textbf{Remark:}}{\vspace{0.5ex}}
\newenvironment{rspVerbatim}{\vspace{-\parskip}\begin{alltt}\color{blue}}{\end{alltt}}
\newenvironment{escapeRspVerbatim}{\vspace{-\parskip}\begin{alltt}}{\end{alltt}}
%%\title{<%@meta name="title"%>}
%%\author{<%@meta name="author"%>}
\date{<%=format(as.Date(R.rsp$date), format="%B %d, %Y")%>}
\begin{document}
%%\maketitle
\section{<%@meta name="title"%>}
\small{
An RSP document consists of text with RSP-embedded markup.
When \emph{compiled}, independently of programming language,
(i)~comments are dropped,
(ii)~preprocessing directives are processed, and
(iii)~text and code expressions are translated into a code script.
The translated code script can then be (iv)~evaluated, which generates
the output document, which in turn may be (v)~postprocessed.
[The R.rsp package knows how to postprocess output such as TeX, Markdown, Sweave, knitr etc.]
%
Examples (in R):
(1)~main.tex.rsp $\rightarrow$ (main.tex.R) $\rightarrow$ main.tex $\rightarrow$ main.pdf.
(2)~main.md.rsp $\rightarrow$ (main.md.R) $\rightarrow$ main.md $\rightarrow$ main.html.
(3)~main.Rnw.rsp $\rightarrow$ (main.Rnw.R) $\rightarrow$ main.Rnw $\rightarrow$ main.tex $\rightarrow$ main.pdf.
}
<%@if twocolumn="TRUE"%>
\vspace{1.5ex}
\hrule
\begin{multicols}{2}
<%@endif # twocolumn%>
\subsection{Comments, Trimming \& Escapes}
\small{
Comments can be used to exclude text, code expressions and preprocessing directives.
}\\[1ex]
%%
\begin{tabular}{p{38ex}p{\columnwidth-38ex-7ex}}
\textit{Markup} & \textit{Description} \\
\hline
%%
\code{<\%--\content{anything}--\%>}
<%-- \code{<\%---\content{anything}---\%>} --%>
&
Drops \content{anything}.
Number ($\geq 2$) of hyphens must match.
Comments can be nested, if different number of hyphens.\\
%%
\code{<\%-\%>},
\code{<\%--\%>},
$\ldots$
&
``Empty'' comments. Like above comments, these ones force following white space and line break to be dropped.\\
\hline
%%
\code{<\%} $\ldots$ \code{-\%>},
\code{<\%} $\ldots$ \code{+\%>}
&
A hyphen (plus) attached to the end tag, forces following white space (including the line break) to be dropped (kept).\\
\hline
%%
\code{<\%\%} and \code{\%\%>}
&
Inserts \code{<\%} and \code{\%>}.\\
\end{tabular}
\subsection{Preprocessing directives}
\small{
Preprocessing directives are independent of programming language used.
They are applied after dropping comments and before translating text and code expressions to a code script.
It is not possible to tell from the translated code script whether preprocessing directives have been used or not, nor are their variables accessible (except metadata).
}\\[1ex]
\begin{tabular}{p{38ex}p{\columnwidth-38ex-7ex}}
\textit{Markup} & \textit{Description} \\
%%
\hline
\code{<\%@include file="\content{file|URL}"\%>} &
Inserts the content of file \content{file$|$URL} into the document before RSP-to-script translation. \\
%%
\hline
\code{<\%@meta \content{name}="\content{content}"\%>} &
Assigns \content{content} to metadata variable \content{name}.
Metadata may be used by preprocessors, e.g. including HTML title. \\
%%
\code{<\%@meta name="\content{name}"\%>} &
Inserts the content of metadata variable \content{name}. \\
%%
\hline
\code{<\%@\content{type} \content{name}="\content{content}"\%>} &
Assigns \content{content} to preprocessing variable \content{name} of type \content{type}.
Supported types are `string', `numeric', `integer' and `logical'.\\
%%
\code{<\%@\content{type} name="\content{name}"\%>} &
Inserts the content of preprocessing variable \content{name}. \\
%%
\hline
\code{<\%@ifeq \content{name}"="\content{content}"\%>} \linebreak
<%@if twocolumn="TRUE"%>
\hphantom{x}\content{incl} \linebreak
\code{<\%@else\%>} \linebreak
\hphantom{x}\content{excl} \linebreak
<%@else%>
\content{incl}~\code{<\%@else\%>}~\content{excl}
<%@endif%>
\code{<\%@endif\%>} &
If preprocessing variable \content{name} \emph{equals} \content{content},
then \content{incl} is inserted otherwise \content{excl}.
\code{<\%@else\%>} is optional. \raggedright \linebreak
\code{<\%@ifneq ...\%>} negates the test. \\
\end{tabular}
\subsection{Code expressions}
\small{
Code expressions are evaluated \emph{after} translation. They may be of any programming language as long as there is a code translator for it.
Code expressions have no access to preprocessing variables (except metadata).
Output written to standard output is inserted into the final document.
}\\[1ex]
\begin{tabular}{p{38ex}p{\columnwidth-38ex-7ex}}
\textit{Markup} & \textit{Description} \\
%%
\hline
%%
\code{<\%\content{code}\%>} &
Inserts \content{code} (may be an incomplete expression) into the
translated code script without including content in the output document.\\
%%
\code{<\%=\content{code chunk}\%>} &
Inserts \content{code chunk} (must be a complete expression) into
the translated code script and includes the returned value in the
output document. \\
\end{tabular}
\subsection{Example of text file with RSP-embedded R code}
<%@string file="incl/example.txt.rsp"%>
%%%
\begin{minipage}[t]{42ex}
\footnotesize%
\textbf{1.~RSP~document:}%
\begin{verbatim}
<%@include file="${file}" type="text/plain"%>
\end{verbatim}%
\end{minipage}
%%%
%%% \parbox[t]{6ex}{$\rightarrow$}%%
%%%
\begin{minipage}[t]{51ex}
\footnotesize%
\textbf{2.~Without comments and preprocessed:}%
\begin{verbatim}
<%@include file="${file}" type="application/x-rsp; until=expressions"%>
\end{verbatim}%
\end{minipage}
%%%
%%% \parbox[t]{6ex}{$\rightarrow$}%%
%%%
\begin{minipage}[t]{42ex}
\footnotesize%
\textbf{3.~Translated~code~script:}%
\begin{verbatim}
<%@string name="doc" file="${file}"%>
<%@eval language="R" content="
## This utilizes the RSP `eval' preprocessing directive to
## translate the example into R code.
code <- R.rsp::rcode('${doc}', output=RspSourceCode());
code <- R.rsp::tidy(code, format='unsafedemo');
"%>
<%@string name="code"%>
\end{verbatim}%
\end{minipage}
%%%
%%% \parbox[t]{6ex}{$\rightarrow$}%%
%%%
\begin{minipage}[t]{44ex}
\footnotesize%
\textbf{4.~Output document:}%
\begin{verbatim}
<%@include file="${file}"%>
\end{verbatim}%
\end{minipage}
\subsection{R.rsp commands}
\begin{minipage}[t]{40ex}
\footnotesize%
\code{rcat('Today is <\%=Sys.Date()\%>')}\linebreak
\code{rcat(file='\content{file|URL}')}\linebreak
\end{minipage}
<%@if twocolumn="FALSE"%>%%<%@endif%>
\begin{minipage}[t]{48ex}
\footnotesize%
\code{s <- rstring('Today is <\%=Sys.Date()\%>')}\linebreak
\code{s <- rstring(file='\content{file|URL}')}\linebreak
\end{minipage}
<%@if twocolumn="FALSE"%>%%<%@endif%>
\begin{minipage}[t]{56ex}
\footnotesize%
\code{output <- rfile('\content{file|URL}')}\linebreak
\code{output <- rfile('\content{file|URL}', postprocess=FALSE)}\linebreak
\end{minipage}
\begin{minipage}[t]{30ex}
\footnotesize%
\code{rsource('\content{file|URL}')}\linebreak
\end{minipage}
<%@if twocolumn="TRUE"%>
\end{multicols}
<%@endif%>
\vfill
\hfill{\footnotesize \href{https://cran.r-project.org/package=R.rsp}{R.rsp v<%=R.rsp$version%>} (<%=R.rsp$date%>) by Henrik Bengtsson}
\end{document}
|