From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- macros/latex/contrib/sasnrdisplay/README | 48 + macros/latex/contrib/sasnrdisplay/SASnRdisplay.cfg | 116 ++ macros/latex/contrib/sasnrdisplay/SASnRdisplay.pdf | Bin 0 -> 202937 bytes macros/latex/contrib/sasnrdisplay/SASnRdisplay.sty | 735 ++++++++++++ macros/latex/contrib/sasnrdisplay/SASnRdisplay.tex | 1176 ++++++++++++++++++++ 5 files changed, 2075 insertions(+) create mode 100644 macros/latex/contrib/sasnrdisplay/README create mode 100644 macros/latex/contrib/sasnrdisplay/SASnRdisplay.cfg create mode 100644 macros/latex/contrib/sasnrdisplay/SASnRdisplay.pdf create mode 100644 macros/latex/contrib/sasnrdisplay/SASnRdisplay.sty create mode 100644 macros/latex/contrib/sasnrdisplay/SASnRdisplay.tex (limited to 'macros/latex/contrib/sasnrdisplay') diff --git a/macros/latex/contrib/sasnrdisplay/README b/macros/latex/contrib/sasnrdisplay/README new file mode 100644 index 0000000000..3415240e89 --- /dev/null +++ b/macros/latex/contrib/sasnrdisplay/README @@ -0,0 +1,48 @@ +% (C) Lars Madsen, daleif@math.au.dk, 2017/12/01 +% This material is subject to the LaTeX Project Public License. +% See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html +% for the details of that license. + +Where I work statisticians mostly use SAS and R when doing +calculations or simulations. Thus they need to be able to import +results or source code into their LaTeX projects. + +This package is an extension to an earlier (unreleased) package which +only handled SAS. The package simply serve as a sort of front end to +the listings package, creating some new lstlisting like environments +and import macros similar to \lstinputlisting. + +All configuration is handled via a hierarchy of listings style. + +The is package also capable of overloading the Sweave and SASweave +packages. + + +HISTORY: + +2017/12/01 + +* now requires a listings newer than 2015/06/04, so we have the R lang spec +* Added R lang calls to the base R style +* Added countbylistings option +* A few extra things added to the manual (utf8) + +2014/03/07 +* bad test for \chapter, fix by using \ifundef instead + +2012/10/10 + +* Added a test for the legacy (unpublished) SASdisplay package. Users + should not be using both packages + +2012/03/27 + +* Fixed typo within \inputSASoutput configuration + +2011/12/01 + +* First public release + + +/Lars Madsen +daleif@math.au.dk diff --git a/macros/latex/contrib/sasnrdisplay/SASnRdisplay.cfg b/macros/latex/contrib/sasnrdisplay/SASnRdisplay.cfg new file mode 100644 index 0000000000..3749c8f3a1 --- /dev/null +++ b/macros/latex/contrib/sasnrdisplay/SASnRdisplay.cfg @@ -0,0 +1,116 @@ +\ProvidesFile{SASnRdisplay.cfg}[2011/07/22 v0.1 by J\o rgen Granfeldt and Lars Madsen] +%% +%% This file can be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3 +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% and version 1.3 or later is part of all distributions of LaTeX +%% version 2003/12/01 or later. +%% +%% This work has the LPPL maintenance status "maintained". +%% +%% The Current Maintainer of this work is Lars Madsen (daleif@math.au.dk) +%% Data supplied by J\o rgen Granfeldt (jqrgen@math.au.dk) +%% +% how to use: +% +% the style sas-more-keywords is used by the ...SAScode macros to +% add extra user defined stuff, this will usually be extra SAS +% keywords, the standard SAS ones for listings can be seen in lstlang3.sty +% +% the normal use goes like this: +% +% morekeywords={comma separated list of words}, +% +% it might not be a good idea to use spaces. If part of one word is +% included in another and each word is contained in different classes +% (see below) then the longer of the two words should be mentioned first +% +% the keywords can be devided into classes of keywords, and each class +% can have their own style / appearance, this is done using the +% following syntax: +% +% morekeywords=[]{keywords}, +% +% if you do not specify any style for level / class [] then it +% will get the default keywordstyle, which is defined in +% SASdisplay.sty as +% +% keywordstyle=\normalfont\bfseries\ttfamily, +% +% that is a bold typewriter, since Computer Modern does not have a +% bold typewriter, might might be a good idea to use the luximono +% package or any other typewrite (monospaced) font that allowes boldface +% To specify a default keywordstyle for class [] simply use +% +% keywordstyle=[]{code}, +% +% example: keywordstyle=[7]{\normalfont\ttfamily}, which means that +% this class of keywords normally appears as if they were normal +% non-keywords. This behavior can the be changed locally, like this +% +% \inputSAScode[keywordstyle={[7]{\normalfont\bfseries\ttfamily}}]{..} +% +% the extra set of braces a required in this case because of the +% outer {}-set. The above code the locally sets the 7-class of keywords to +% appear as keywords and not as normal words / variables. +% +% Please note that strictly speaking keywords and functions in SAS +% does not the to be in uppercase. But J\o rgen Granfeldt (for whom +% SASdisplay and now SASnRdisplay was originally written) uses +% uppercase keywords / functions as a educational tool, and therefore +% writes userdefined variables etc. in lowercase. Therefore this +% configuration file might suit you particular needs. Feel free to +% rewrite it as your own. +% +% sasmorekeywords +\lstdefinestyle{sas-more-keywords}{% +morekeywords={SASAUTOS,LABEL}, +morekeywords={PROC,INSIGHT,SCATTER,QUIT,FORMAT,VALUE}, +morekeywords={DISCRIM,WCOV,WSSCP,METHOD,POOL}, +morekeywords={DATALINES,WITH,OPTIONS,GPLOT,LS,PS}, +morekeywords={SYSLIN,INSTRUMENTS,ENDOGENOUS,EXOGENOUS,IDENTITY,% +WEIGHT,OLS,2SLS,LIML,SUR,ITSUR,3SLS,IT3SLS,FIML,MELO}, +morekeywords={MODEL,OUT,STDR,STDP,H,R,STUDENT,RSTUDENT,PRESS,% +UCL,LCL,UCLM,LCLM,CL}, +morekeywords={FREQ,TABLES}, +morekeywords={GLM,CLASS,LSMEANS,MANOVA,MTEST,REG,PRINTE,% +FILENAME,GOPTIONS,DEV,CTEXT,GACCESS,NOPRINT,CONTRAST,ESTIMATE,RANDOM}, +morekeywords={SS1,SS2,SS3,SSD,SS4,CLI,CLM,CLPARM}, +morekeywords={NOUNI,OUTPUT}, +morekeywords={E,E1,E2,E3,SOLUTION,TEST},% +morekeywords={IML,USE,READ,ALL,INTO,PRINT,COLNAME,ROWNAME,CREATE,% +FROM,APPEND}, +morekeywords={MIXED,DDFM,REPEATED,PARMS,PRIOR,ALPHA,TYPE}, +morekeywords={GREPLAY,NOFS,NOBYLINE,IGOUT,TC,TEMPLATE,TREPLAY,GOUT}, +morekeywords={GSFMODE,TARGETDEVICE,ROTATE,CBACK,GUNIT,HTITLE,HTEXT,% +FTEXT,CSYMBOL,ANNOTATE}, +morekeywords={SYMBOL,SYMBOL1,SYMBOL2,SYMBOL3,SYMBOL4,SYMBOL5,SYMBOL6,% +SYMBOL7,SYMBOL8}, +morekeywords={LEGEND1,LEGEND2,LEGEND3,ANGLE}, +morekeywords={INTERPOL,I}, +morekeywords={AXIS,AXIS1,AXIS2,AXIS3,AXIS4,AXIS5,AXIS6,AXIS7,AXIS8,% +HAXIS,VAXIS,ORDER}, +morekeywords={MINOR,WIDTH,COLOR,GPLOT,PLOT,OVERLAY}, +morekeywords={I,V,L,H,C,ANGLE,NOLEGEND,USS,OF}, +morekeywords={TITLE,TITLE1,TITLE2,TITLE3,TITLE4,TITLE5,TITLE6}, +morekeywords={PRINCOMP,COV}, +morekeywords={GSFNAME,GSASFILE,INCLUDE}, +morekeywords={GENMOD,LINK,FWDLINK,INVLINK,ASSESS,ASSESSMENT,OBSTATS,% + SCALE,DSCALE,PSCALE}, +morekeywords={TYPE1,TYPE3,WALD,WALDCI,XVARS}, +morekeywords={DIST,TOTAL,NOINT,OFFSET}, +morekeywords={ODS, LISTING,ParameterEstimates,RESDEV,STDRESDEV,% + PREDICTED,RESCHI,RESLIK,STDRESCHI}, +morekeywords={XBETA,STDXBETA,LOWER,UPPER,HESSWGT}, +morekeywords={FWDLINK,INVLINK,VARIANCE,DEVIANCE}, +morekeywords=[7]{P}, +keywordstyle=[7]{\normalfont\ttfamily}, +% Listings setup for SAS include / and * in the keyword list, +% meaning we cannot style comments in SAS, we therefore remove +% remove them from the keyword list + otherkeywords={!,!=,~,$,\&,_,<,>=,=<,>}, +} +% end sasmorekeywords +%$ for emacs diff --git a/macros/latex/contrib/sasnrdisplay/SASnRdisplay.pdf b/macros/latex/contrib/sasnrdisplay/SASnRdisplay.pdf new file mode 100644 index 0000000000..ebc1b9aa47 Binary files /dev/null and b/macros/latex/contrib/sasnrdisplay/SASnRdisplay.pdf differ diff --git a/macros/latex/contrib/sasnrdisplay/SASnRdisplay.sty b/macros/latex/contrib/sasnrdisplay/SASnRdisplay.sty new file mode 100644 index 0000000000..d3a26dab11 --- /dev/null +++ b/macros/latex/contrib/sasnrdisplay/SASnRdisplay.sty @@ -0,0 +1,735 @@ +\ProvidesPackage{SASnRdisplay}[2017/12/01 v0.95 by daleif] + +\newcommand\SnRversion{v0.95 2017/12/01} + +%% $LastChangedDate: 2017-12-01 15:09:40 +0100 (Fri, 01 Dec 2017) $ +%% $LastChangedRevision: 1924 $ +%% $LastChangedBy: daleif@math.au.dk $ + +%% +%% This package can be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3 +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% and version 1.3 or later is part of all distributions of LaTeX +%% version 2003/12/01 or later. +%% +%% This work has the LPPL maintenance status "maintained". +%% +%% The Current Maintainer of this work is Lars Madsen (daleif@math.au.dk). +%% + + + +\RequirePackage{listings}[2015/06/04] +\RequirePackage{xkeyval,xcolor,etoolbox,caption,needspace} + + + +\def\SR@special@num{0} + +% we start by messing a little with listings + +\newtoggle{capactive} +% this is a direct copy of listings caption key. We just add a toggle +% such we can know when it is being used +\lst@Key{caption}\relax{% + \lstKV@OptArg[{#1}]{#1}% + {\def\lst@caption{##2}\def\lst@@caption{##1}}% + \toggletrue{capactive}% + \def\SR@special@num{1}% + \let\lst@title\@empty} + +% we also need to mess with title, because, if there is not explicit +% caption, we would still like to overwrite the auto title with a +% simple title +\newtoggle{titleactive} +\lst@Key{title}\relax{% + \def\lst@title{#1}% + \toggletrue{titleactive}% + \def\SR@special@num{2}% + \let\lst@caption\relax} + + + + +% replica of the original caption key without the toggle. We will use this +% internally to be able to auto number our constuctions when there is +% no direct caption. +\lst@Key{nocaption}\relax{\lstKV@OptArg[{#1}]{#1}% + {\def\lst@caption{##2}\def\lst@@caption{##1}}% + \let\lst@title\@empty} + +% This next bit is caption configuration. The code is due to Ulrike Fischer +% we define a text formatting which will eat the caption +\DeclareCaptionTextFormat{gobble}{} + +% now in the numbered constructions we would like to have 'Name +% number' when there is no caption, and 'Name number text' when +% there is a caption. +% +% This can be done using \lstset{nocaption=x,#1} inside our +% constructions, and then after \lstset issuing +% \iftoggle{capactive}{}{% +% \captionsetup[lstlisting]{labelsep=none,textformat=gobble}} + + + + + + + + +% some default colors +\definecolor{SnRBG} {rgb} {0.94,0.97,1} +\definecolor{SnRFrame} {rgb} {0.79,0.88,1} +\definecolor{SnRBGGray} {gray}{0.9} +\definecolor{SnRFrameGray}{gray}{0} + + + +\DeclareOptionX{grayscale}{ + \colorlet{SnRBG}{SnRBGGray} + \colorlet{SnRFrame}{SnRFrameGray} +} + + + + +\newtoggle{SnRcountbysection} +\newtoggle{SnRcountbychapter} +\newtoggle{SnRcountconsecutive} +\newtoggle{SnRcountbylistings} +\DeclareOptionX{consecutive}{\toggletrue{SnRcountconsecutive}} +\DeclareOptionX{countbysection}{\toggletrue{SnRcountbysection}} +\DeclareOptionX{countbychapter}{% + % if \chapter is not available specify section instead + \ifundef\chapter{ + \toggletrue{SnRcountbysection} + }{ + \toggletrue{SnRcountbychapter} + } +} + + +% added 2017/12/01 in response to +% https://tex.stackexchange.com/q/181110/3929 +\DeclareOptionX{countbylistings}{\toggletrue{SnRcountbylistings}} + + +\let\SnRneedspaceCommand\@gobble +\newlength\SnRneedspace +\let\SnRneedspaceSAScode \SnRneedspace +\let\SnRneedspaceSASoutput\SnRneedspace +\let\SnRneedspaceRcode \SnRneedspace +\let\SnRneedspaceRoutput \SnRneedspace + +\DeclareOptionX{noneedspace}{ + \let\SnRneedspaceCommand\@gobble +} + +\DeclareOptionX{needspace}{ + \setlength\SnRneedspace{#1} + \let\SnRneedspaceCommand\needspace +} + + +\providecommand*\SnRRcodename{} +\providecommand*\SnRSAScodename{} +\providecommand*\SnRRoutputname{} +\providecommand*\SnRSASoutputname{} + +\DeclareOptionX{danish}{ +% danishnames + \renewcommand*\SnRRcodename{R-kode} + \renewcommand*\SnRSAScodename{SAS-kode} + \renewcommand*\SnRRoutputname{R-udskrift} + \renewcommand*\SnRSASoutputname{SAS-udskrift} +% end danishnames +} +\DeclareOptionX{english}{ +% englishnames + \renewcommand*\SnRRcodename{R~code} + \renewcommand*\SnRSAScodename{SAS~code} + \renewcommand*\SnRRoutputname{R~output} + \renewcommand*\SnRSASoutputname{SAS~output} +% end englishnames +} + +\DeclareOptionX{babel}{ + \@ifpackageloaded{babel}{ + \addto\captionsdanish{ + \renewcommand*\SnRRcodename{R-kode} + \renewcommand*\SnRSAScodename{SAS-kode} + \renewcommand*\SnRRoutputname{R-udskrift} + \renewcommand*\SnRSASoutputname{SAS-udskrift} + } + \addto\captionsenglish{ + \renewcommand*\SnRRcodename{R~code} + \renewcommand*\SnRSAScodename{SAS~code} + \renewcommand*\SnRRoutputname{R~output} + \renewcommand*\SnRSASoutputname{SAS~output} + } + }{ + \PackageError{SASnRdisplay}{To use the 'babel' option, please load + SASnRdisplay after babel}{} + } +} + + + + + +\newtoggle{SnRnoautotitles-R} +\newtoggle{SnRnoautotitles-SAS} +\DeclareOptionX{noautotitles-r}{\toggletrue{SnRnoautotitles-R}} +\DeclareOptionX{noautotitles-sas}{\toggletrue{SnRnoautotitles-SAS}} + +\newtoggle{SnRoverloadSweave} +\DeclareOptionX{sweave} {\toggletrue{SnRoverloadSweave}} +\newtoggle{SnRoverloadSASweave} +\DeclareOptionX{sasweave}{\toggletrue{SnRoverloadSASweave}} + + + +\DeclareOptionX*{ + \PassOptionsToPackage{\CurrentOption}{listings} +} +\ExecuteOptionsX{danish,countbychapter,needspace=3\baselineskip} +\ProcessOptionsX*\relax + + +\@ifpackageloaded{SasWeave}{ + \iftoggle{SnRoverloadSASweave}{}{ + \PackageError{SASnRdisplay}{SasWeave detected,^^J% + please use the 'sasweave' option to SASnRdisplay + to overwrite the SASinput,^^J% + SASoutput and SAScode environments}{} + }{} +}{} + + + + + +\listadd\SnRtypes{Rcode} +\listadd\SnRtypes{Routput} +\listadd\SnRtypes{SAScode} +\listadd\SnRtypes{SASoutput} + + + + +\newcommand\SnRsetupcounters[1]{ + % #1 dominant countername + \def\do##1{ + % create counter + \ifblank{#1}{\newcounter{##1}}{\newcounter{##1}[#1]} + % create \the... part, with dominator if needed + \csdef{the##1}{\ifblank{#1}{}{\csuse{the#1}.}\arabic{##1}} + } + \dolistloop\SnRtypes +} + +% added 2017/12/01, if option given, then don't create or mess with counters +\iftoggle{SnRcountbylistings}{}{ + + \iftoggle{SnRcountconsecutive}{ + \SnRsetupcounters{}% no dominant counter + }{ + \iftoggle{SnRcountbysection}{ + \SnRsetupcounters{section} + }{ % must be after chapter + \SnRsetupcounters{chapter} + } + } + +} + +% This is inspired from the memoir class, it enables us to alias the +% listings counter such that we can have different series +% It will locally make one counter behave like another counter +% it also handles the \the +\iftoggle{SnRcountbylistings}{ + \let\SnRletcountercounter\@gobbletwo +}{ + \newcommand*{\SnRletcountercounter}[2]{% + \csletcs{c@#1}{c@#2} + \csletcs{the#1}{the#2} + \SnRHrefNumber{#2} + } +} + + +\newcommand*{\SnRHrefNumber}[1]{% + \begingroup + \global\let\gtmp@theHlstnumber\theHlstnumber + \toks@\expandafter{\theHlstnumber}% + \xdef\gtmp@theHlstnumber{#1-\the\toks@}% + \endgroup + \let\theHlstnumber\gtmp@theHlstnumber + \def\theHlstlisting{% + lst.#1-\csname the\@ifundefined{theH#1}{}{H}#1\endcsname + }% +} + + + + +\newcommand\SnRCaptionSetupIfEmpty{% + \ifboolexpr{ not togl{capactive} and not togl{titleactive} }{% + \captionsetup[lstlisting]{labelsep=none,textformat=gobble}% + }{}% +} + +\newcommand\SnRautocaption[1]{% + \iftoggle{SnRnoautotitles-#1}{}{\lstset{nocaption=x}}} + +% generator macro +\newcommand\SnREnvGenerator[2]{ + % #1 = output type + % #2 = env type + \lstnewenvironment{#1#2}[1][]{ + \csuse{SnRInitial#1#2Setup} + \SnRautocaption{#1} + \lstset{##1} + \SnRCaptionSetupIfEmpty + }{} + \lstnewenvironment{#1#2*}[1][]{ + \csuse{SnRInitial#1#2Setup} + \lstset{##1} + }{} +} + +\newcommand\SnREnvGeneratorAlias[3]{ + % #1 = output type + % #2 = alias output type + % #3 = env type + \typeout{Redefining #1#3} + \csundef{#1#3} + \csundef{end#1#3} + \csundef{#1#3*} + \csundef{end#1#3*} + \lstnewenvironment{#1#3}[1][]{ + \csuse{SnRInitial#2#3Setup} + \SnRautocaption{#2} + \lstset{##1} + \SnRCaptionSetupIfEmpty + }{} + \lstnewenvironment{#1#3*}[1][]{ + \csuse{SnRInitial#2#3Setup} + \lstset{##1} + }{} +} + + +\newcommand\SnRInputGenerator[3]{ + % #1 = output type + % #2 = type + % #3 = extra input listings style + \expandafter\newcommand\csname SnRinput@#1@#2@normal\endcsname[2][]{ + \begingroup + \csuse{SnRInitial#1#2Setup}[#3] + \SnRautocaption{#1} + \lstset{##1} + \SnRCaptionSetupIfEmpty + \def\SnR@args{##1} + \expandafter\lstinputlisting\expandafter[\SnR@args]{##2} + \endgroup + } + \expandafter\newcommand\csname SnRinput@#1@#2@starred\endcsname[2][]{ + \begingroup + \csuse{SnRInitial#1#2Setup}[#3] + \def\SnR@args{##1} + \expandafter\lstinputlisting\expandafter[\SnR@args]{##2} + \endgroup + } + \expandafter\newcommand\csname input#1#2\endcsname{% + \@ifstar{\csuse{SnRinput@#1@#2@starred}}% + {\csuse{SnRinput@#1@#2@normal}}} +} + + + +% +% BASIC SETTINGS FOR R +% + +% this is for basic configuration of the inline version +% rinline +\lstdefinestyle{r-inline}{ + basicstyle = \ttfamily, + language = R, % R lang added 2017/12/01 +} +% end rinline +% Spaces above and after, plus caption and internal lineskip (note +% lineskip is marked experimental in listings) +% rvskips +\lstdefinestyle{r-vskips}{ + aboveskip = 10pt plus 3pt minus 5pt, + belowskip = 10pt plus 3pt minus 5pt, + belowcaptionskip = 7pt, + lineskip = 0pt plus 0.1em, % help with blank lines and page stretch +} +% end rvskips +% basic colors +% rcolors +\lstdefinestyle{r-colors}{ + backgroundcolor = \color{SnRBG}, + rulecolor = \color{SnRFrame}, +} +% end rcolors +% basic fonts +% rfonts +\lstdefinestyle{r-fonts}{ + basicstyle = \small\ttfamily, +} +% end rfonts +% Columns, characters and line breaks +% rcharsandbreaks +\lstdefinestyle{r-chars-and-breaks}{ + columns = fixed, % chars vertivally aligned + breaklines, % lines can be broken + breakatwhitespace, % at white space + extendedchars = true, % special chars allowed, be aware of utf8 +} +% end rcharsandbreaks + + %morecomment = [s]{\#}{\^^M}, % comment from # to the end of the line + +% rmarkup +\lstdefinestyle{r-markup}{ % this only make sense for code + language = R, % R lang added 2017/12/01 + commentstyle = \normalfont\slshape\ttfamily\footnotesize, +} +% end rmarkup +% rframe +\lstdefinestyle{r-frame}{ + frame = single, % single frame all the way round, box broken at page break + framesep = 0.5em, % sep from frame to text +} +% end rframe +% general stuff from the user, applying to all R +% ruser +\lstdefinestyle{r-user}{} +% end ruser +% collector style +% rstyle +\lstdefinestyle{r-style}{ + style = r-vskips, % vertical spacing + style = r-fonts, % fonts + style = r-colors, % colors + style = r-chars-and-breaks, % special chars and line breaks + style = r-frame, % framing + style = r-user, % user defined configuration +} +% end rstyle +% rcode +\lstdefinestyle{r-code}{ + style = r-style, + style = r-markup, % markup only make sense for code + style = r-code-user, +} +% end rcode +% routput +\lstdefinestyle{r-output}{ + style = r-style, + style = r-output-user, +} +% end routput +% rincludecode +\lstdefinestyle{r-include-code}{ + style = r-code, + style = r-include-user, + style = r-include-code-user, +} +% end rincludecode +% rincludeoutput +\lstdefinestyle{r-include-output}{ + style = r-output, + style = r-include-user, + style = r-include-output-user, +} +% end rincludeoutput +% rcodeuser +\lstdefinestyle{r-code-user}{} +% end rcodeuser +% routputuser +\lstdefinestyle{r-output-user}{} +% end routputuser +% rincludecodeuser +\lstdefinestyle{r-include-code-user}{} +% end rincludecodeuser +% rincludeoutputuser +\lstdefinestyle{r-include-output-user}{} +% end rincludeoutputuser +% rincludeuser +\lstdefinestyle{r-include-user}{} +% end rincludeuser + + +% just to save some code +\newcommand\SnRInitialRcodeSetup[1][r-code]{ + \let\lstlistingname\SnRRcodename% + \SnRletcountercounter{lstlisting}{Rcode}% + \lstset{style=#1}% + \SnRneedspaceCommand\SnRneedspaceRcode +} + +\newcommand\SnRInitialRoutputSetup[1][r-output]{ + \let\lstlistingname\SnRRoutputname% + \SnRletcountercounter{lstlisting}{Routput}% + \lstset{style=#1}% + \SnRneedspaceCommand\SnRneedspaceRcode +} + +% for Sweave +\def\SnRInitialRinputSetup{% + \SnRInitialRcodeSetup% + \lstset{style=Sinput}% +} + + +\SnREnvGenerator{R}{code} % -> Rcode and Rcode* +\SnREnvGenerator{R}{output} % -> Routput and Routput* + +\lstdefinestyle{Sinput}{} + +\iftoggle{SnRoverloadSweave}{ + \AtBeginDocument{ + % overload Sweave. There are three envs to deal with Sinput, + % Scode, Soutput, Sinput and Scode are more or less the same thing +% \let\Sinput\relax +% \let\endSinput\relax +% \let\Soutput\relax +% \let\endSoutput\relax +% \let\Scode\relax +% \let\endScode\relax +% \csundef{Sinput*} +% \csundef{endSinput*} +% \csundef{Soutput*} +% \csundef{endSoutput*} +% \csundef{Scode*} +% \csundef{endScode*} +% \let\SnRInitialScodeSetup\SnRInitialRcodeSetup +% \def\SnRInitialSinputSetup{% +% \SnRInitialRcodeSetup% +% \lstset{style=Sinput}% +% } +% \let\SnRInitialSoutputSetup\SnRInitialRoutputSetup + \SnREnvGeneratorAlias{S}{R}{code} + \SnREnvGeneratorAlias{S}{R}{output} + \SnREnvGeneratorAlias{S}{R}{input} + } +}{} + + +% a \verb like macro for Rcode in the normal text +\newcommand\Rinline[1][]{\lstinline[style=r-inline,#1]} + + + +% input external R files +% we need something a bit special here. Some options have to be given +% to \lstinputlisting's optional argument. But we also need to know if +% the caption has been set, thus we set the user specified options twice! + + +\SnRInputGenerator{R}{code}{r-include-code} % -> \inputRcode(*) +\SnRInputGenerator{R}{output}{r-include-output} % -> \inputRoutput(*) + + +% +% END R CODE SETTINGS +% + + + +% +% SETUP FOR SAS +% + +% sasinline +\lstdefinestyle{sas-inline}{ + basicstyle = \ttfamily, + style = sas-more-keywords, + language = SAS, +} +% end sasinline +% sasvskips +\lstdefinestyle{sas-vskips}{ + aboveskip = 10pt plus 3pt minus 5pt, + belowskip = 10pt plus 3pt minus 5pt, + belowcaptionskip = 7pt, + lineskip = 0pt plus 0.1em, % help with blank lines and page stretch +} +% end sasvskips +% sascolors +\lstdefinestyle{sas-colors}{ + backgroundcolor = \color{SnRBG}, + rulecolor = \color{SnRFrame}, +} +% end sascolors +% sascharsandbreaks +\lstdefinestyle{sas-chars-and-breaks}{ + columns = fixed, % chars vertivally aligned + breaklines, % lines can be broken + breakatwhitespace, % at white space + extendedchars = true, % special chars allowed, be aware of utf8 +} +% end sascharsandbreaks +% sasmarkup +\lstdefinestyle{sas-markup}{ + language = SAS, + keywordstyle = \bfseries, + comment = [s]{/*}{*/}, + commentstyle = \slshape\footnotesize, +} +% end sasmarkup +% sasframe +\lstdefinestyle{sas-frame}{ + frame = single, + framesep = 0.5em, +} +% end sasframe +% sasuser +\lstdefinestyle{sas-user}{} +% end sasuser +% sasstyle +\lstdefinestyle{sas-style}{ + style = sas-vskips, + style = sas-frame, + style = sas-colors, + style = sas-chars-and-breaks, + style = sas-user, +} +% end sasstyle +% sascode +\lstdefinestyle{sas-code}{ + style = sas-style, + style = sas-code-fonts, + style = sas-markup, % there is no markup of the output + style = sas-more-keywords, % has to come after markup when loading styles + style = sas-code-user, +} +% end sascode +% sasoutput +\lstdefinestyle{sas-output}{ + style = sas-style, + style = sas-output-fonts, + style = sas-output-user, +} +% end sasoutput +% sascodeuser +\lstdefinestyle{sas-code-user}{} +% end sascodeuser +% sasoutputuser +\lstdefinestyle{sas-output-user}{} +% end sasoutputuser +% sascodefonts +\lstdefinestyle{sas-code-fonts}{ + basicstyle = \ttfamily\small, +} +% end sascodefonts +% sasoutputfonts +\lstdefinestyle{sas-output-fonts}{ + basicstyle = \ttfamily\footnotesize, +} +% end sasoutputfonts +% sasinputcodeuser +\lstdefinestyle{sas-input-code-user}{} +% end sasinputcodeuser +% sasinputoutputuser +\lstdefinestyle{sas-input-output-user}{} +% end sasinputoutputuser +% sasincludecode +\lstdefinestyle{sas-include-code}{ + style = sas-code, + style = sas-include-user, + style = sas-include-code-user, +} +% end sasincludecode +% sasincludeoutput +\lstdefinestyle{sas-include-output}{ + style = sas-output, + style = sas-include-user, + style = sas-include-output-user, +} +% end sasincludeoutput +% sasincludeuser +\lstdefinestyle{sas-include-user}{} +% end sasincludeuser +% sasincludecodeuser +\lstdefinestyle{sas-include-code-user}{} +% end sasincludecodeuser +% sasincludeoutputuser +\lstdefinestyle{sas-include-output-user}{} +% end sasincludeoutputuser + + + + +% MACROS AND ENVIRONMENTS + +\newcommand\SnRInitialSAScodeSetup[1][sas-code]{ + \let\lstlistingname\SnRSAScodename% + \SnRletcountercounter{lstlisting}{SAScode}% + \lstset{style = #1}% + \SnRneedspaceCommand\SnRneedspaceSAScode +} + +\newcommand\SnRInitialSASoutputSetup[1][sas-output]{ + \let\lstlistingname\SnRSASoutputname% + \SnRletcountercounter{lstlisting}{SASoutput}% + \lstset{style = #1}% + \SnRneedspaceCommand\SnRneedspaceSASoutput +} + +\iftoggle{SnRoverloadSASweave}{ + % overload SASweave. There are three envs to deal with: SASinput, + % SAScode, SASoutput, SASinput and SAScode are more or less the same + % thing. Since we use the same names, only SASinput is missing + \let\SASinput\relax + \let\endSASinput\relax + \let\SASoutput\relax + \let\endSASoutput\relax + \let\SAScode\relax + \let\endSAScode\relax + \let\SnRInitialSASinputSetup\SnRInitialSAScodeSetup + \SnREnvGenerator{SAS}{input} +}{} + + +\SnREnvGenerator{SAS}{code} +\SnREnvGenerator{SAS}{output} + + +% a \verb like macro for SAScode in the normal text +\newcommand\SASinline[1][]{\lstinline[style=sas-inline,#1]} +% SASdisplay had this macro, so we add it, but do not mention it in +% the manual. +\newcommand\SAScodeinline[1][]{\lstinline[style=sas-inline,#1]} + +% inclusion macros +\SnRInputGenerator{SAS}{code}{sas-include-code} +\SnRInputGenerator{SAS}{output}{sas-include-output} + + +\InputIfFileExists{SASnRdisplay.cfg}{}{} +\InputIfFileExists{SASnRdisplayuser.cfg}{}{} + +\AtBeginDocument{ + \@ifpackageloaded{SASdisplay}{ + \PackageError{SASnRdisplay}{SASnRdisplay cannot be loaded at the + same time as the legacy SASdisplay package.}{Please remove the + SASdisplay package} + }{} +} + + +\endinput + + + + diff --git a/macros/latex/contrib/sasnrdisplay/SASnRdisplay.tex b/macros/latex/contrib/sasnrdisplay/SASnRdisplay.tex new file mode 100644 index 0000000000..b51648e6dc --- /dev/null +++ b/macros/latex/contrib/sasnrdisplay/SASnRdisplay.tex @@ -0,0 +1,1176 @@ +% $LastChangedDate: 2017-12-01 15:08:05 +0100 (Fri, 01 Dec 2017) $ +% $LastChangedRevision: 1923 $ +% $LastChangedBy: daleif@math.au.dk $ + + +\documentclass[a4paper,article]{memoir} +\setlrmarginsandblock{3cm}{3cm}{*} +\setulmarginsandblock{2.5cm}{3cm}{*} +\checkandfixthelayout[nearest] +\usepackage[T1]{fontenc} +\usepackage{kpfonts} +\usepackage{xspace,calc,listings,enumitem,url,ragged2e} +\setlist{ + listparindent=\parindent, + parsep=0pt, +} +\usepackage[scaled=0.8]{beramono} + +\hfuzz=5pt + +%\setlength\cftbeforechapterskip{0em plus 0.2em} + +\AtBeginDocument{\providecommand\href[2]{#2}} + +\DeclareUrlCommand\mypath{\urlstyle{sf}} +%\urlstyle{rm} +\newcommand\addCTAN[2][\textsf{CTAN}:]{% + {\footnotesize\href{http://mirror.ctan.org/#2}{#1\:{\mypath{#2}}}}% +} + +\newcommand\CTAN[1]{% + {\footnotesize\href{http://mirror.ctan.org/#1}{\textsf{CTAN:}~{\mypath{#1}}}}} + + +\newcommand\pkg{\texttt{SASnRdisplay}\xspace} +\setsecnumdepth{subsection} +\settocdepth{subsection} +\setsecheadstyle{\large\slshape\bfseries\memRTLraggedright} + +\usepackage[svgnames,dvipsnames]{xcolor} + \definecolor{felinesrcbgcolor}{rgb}{0.94,0.97,1} + \definecolor{felineframe}{rgb}{0.79,0.88,1} + + +\usepackage[ +english, +%grayscale, +%noautotitles-sas, +noneedspace +]{SASnRdisplay} + +\captionsetup[lstlisting]{ + font=small, + labelfont=bf +} + + + +\newcommand\R{\textsf{R}\xspace} +\newcommand\SAS{\textsf{SAS}\xspace} +\newcommand\sweave{\textsf{Sweave}\xspace} + +\usepackage{xkeyval} + + +\setlength\unitlength{\linewidth+1em} +\lstdefinestyle{Show}{ + basicstyle=\ttfamily\small, + breaklines, + breakatwhitespace, + columns=flexible, + backgroundcolor=\color{BrickRed!10}, + rulecolor=\color{BrickRed}, + frame=single, + framesep=0.25em, + escapeinside=||, +} +\lstdefinestyle{inShow}{ + style=Show, + basicstyle=\ttfamily\normalsize\color{BrickRed}, +} +\lstnewenvironment{Show}[1][]{ +\lstset{ + style=Show,#1 +} +}{} +%\setsecnumdepth{none} +\newcommand\error[1]{\textcolor{OliveGreen}{>>#1<<}} + +\def\NAME{SASnRdisplay.sty} +\newcommand\getsniplet[2]{ + \begingroup + \Needspace{4\onelineskip} + \ifblank{#2}{ + \lstinputlisting[style=Show, + rangeprefix=\%\ , + includerangemarker=false, + linerange=#1-end\ #1, + columns=fixed, + xleftmargin=0.5em, + framexleftmargin=0.5em, + ]{\NAME} + }{ + \lstinputlisting[style=Show, + rangeprefix=\%\ , + includerangemarker=false, + linerange=#1-end\ #1, + title={Style: #2}, + columns=fixed, + xleftmargin=0.5em, + framexleftmargin=0.5em, + ]{\NAME}} + \endgroup + \noindent\ignorespaces +} + +\newcommand\showcolor[1]{>>{\color{#1}\rule{1em}{0.5em}}<<} + +\newenvironment{question}[1]{ + \subsubsection*{\textnormal{\textit{\color{BrickRed}#1}}} + \phantomsection + \addcontentsline{toc}{subsubsection}{#1} +}{} +\lstnewenvironment{solution}[1][]{ + \lstset{style=Show,gobble=2,columns=fixed,#1} +}{} + + +\usepackage[ +colorlinks, +breaklinks, +plainpages=false, +pdfpagelabels, +pdfencoding = auto, +bookmarksnumbered, +unicode, +]{hyperref} + + +\title{The \textsf{SASnRdisplay} package} +\author{Lars Madsen\thanks{Email: daleif@math.au.dk, \SnRversion}} + +\definecolor{linkcolour}{rgb}{0,0.2,0.6} +\definecolor{citecolour}{rgb}{0,0.6,0.2} +\definecolor{urlcolour} {rgb}{0.8,0,0.8} + + +\hypersetup{ + pdftitle={The \textsf{SASnRdisplay} package}, + pdfauthor={\copyright\ Lars Madsen 2017}, + linkcolor=linkcolour, + citecolor=citecolour, + filecolor=urlcolour, + urlcolor=urlcolour, +} + + + +\settocdepth{subsection} + +\pagestyle{plain} +\begin{document} + +\maketitle + +\chapter*{Introdution} +\label{cha:introdution} + + +The \pkg package acts as a frontend to the versatile \texttt{listings} +package in order assist the user in typesetting \SAS or +\R code or output. The package replaces the similar +\texttt{SASdisplay} package, which was only available to my local +users. + +\fancybreak{} + +Please be aware that \pkg is \emph{not} fully compatible with +\texttt{SASdisplay}, the default settings are different and some +macros are named differently. + +\subsubsection*{Acknowledgements} +\label{sec:acknowledgements} + +I'd like to thank Ulrike Fischer for hints about some very useful +features in the \texttt{caption} package, Heiko Oberdiek for his help +with \texttt{hyperref} details. Plus a thanks to Jørgen Granfeldt and +Preben Blæsild for answering my various questions about details within +the \R or \SAS languages. + +\subsubsection*{Loaded package} +\label{sec:loaded-package} + +The following packages will be loaded (without any options): \texttt{listings}, +\texttt{xkeyval}, \texttt{xcolor}, \texttt{etoolbox}, +\texttt{caption}, \texttt{needspace}. If you need to pass options to +these packages, load them \emph{before} the \pkg package. + + + +\tableofcontents* + +\newpage + +\chapter{Interface} +\label{cha:interface} + +\section{Environments} +\label{sec:environments} + +\begin{solution}[escapeinside=XX] + \begin{env}[X\meta{options}X] + ... + \end{env} +\end{solution} +% +Each environment support an optional \oarg{options} argument. The +\meta{options} part should be listings related configuration. + +\renewcommand\descriptionlabel[1]{\hspace\labelsep\parbox{\textwidth-\labelsep}{\textbf{#1}}} +\begin{description}\firmlist +\item[SAScode, SAScode*] + For typesetting \SAS code. The starred version is not automatically + numbered. +\item[SASoutput, SASoutput*] + Similar for \SAS output. Note that it might be an idea to decrease the + width of the \SAS output from within the \SAS programme. +\item[Rcode, Rcode*] + Typesets \R code +\item[Routput, Routput*] + Typesets \R output +\end{description} + +\section{Input from external files} +\label{sec:input-from-external} + +General syntax: +\begin{quote} + \cs{macro}\oarg{options}\marg{filename} +\end{quote} +Available macros: +\begin{description}\firmlist +\item[\cs{inputSAScode}, \cs{inputSAScode*}] +Similar to the SAScode(*) environment, but get the data from external file. +\item[\cs{inputSASoutput}, \cs{inputSASoutput*}] +Similar to the SASoutput(*) environment. +\item[\cs{inputRcode}, \cs{inputRcode*}] +Similar to the Rcode(*) environment. +\item[\cs{inputRoutput}, \cs{inputRoutput*}] +Similar to the Rcode(*) environment. +\end{description} + +\section{Sniplets} +\label{sec:sniplets} + +To typeset inline sniplets we provide +\begin{description}\tightlist +\item[\cs{SASinline}] +\item[\cs{Rinline}] +\end{description} +They both behave like \cs{verb}, thus one can write +\begin{quote} + \cs{Rinline}\oarg{options}\verb+|x <- 34|+ +\end{quote} +% +Note that for \verb|\SASinline|, key words are marked, i.e.\ it is +\SAS aware. This is not the case for \R. + + + +\section{Package options} +\label{sec:package-options} + +\begin{solution}[escapeinside=XX] + \usepackage[X\meta{options}X]{SASnRdisplay} +\end{solution} +Available options: +\begin{description}\firmlist +\item[danish] + Loads Danish translations for some keywords. (Executed by default) +\item[english] Similar for English. +% \item[babel] Adding this option and we will bind the four \cs{...name} +% macros to their respective languages, i.e. automatically use +% \cs{addto}\cs{captionsX}. This will require that \pkg is loaded +% \emph{after} \texttt{babel}. +\item[grayscale] Changes some build in colors to monochrome. +\item[countbysection] Force counters to be dominated by the section counter. +\item[countbychapter] Force counters to be dominated by the chapter + counter. This is the default if \cs{chapter} exist, otherwise + \texttt{countbysection} will be used. +\item[consecutive] Use this if you just want consecutive + numbering throughout, that is the number of say \SAS code, is not + reset at every new chapter or section. +\item[countbylistings] Here we will leave the counters alone and just + use the one that comes with \texttt{listings}. This (of course) + disables \texttt{countbysection}, \texttt{countbychapter} and + \texttt{consecutive}. +\item[noautotitles-r, noautotitles-sas] Do not automatically add a + number to any of the code and outputs. It can still be added + manually by using the \texttt{caption=\marg{text}} option. +\item[needspace=\meta{length}] + This issue a \cs{needspace}\marg{length} before each code or output + environmnt or inclusion macro. It will ensure that if there is less + than \meta{length} space left on the page, a page break is issued + before the construction start. + + This feature is enabled by default with a default \meta{length} of + \verb|3\baselineskip|. +\item[noneedspace] This disables the \texttt{needspace} feature. +\item[sweave] Overloads the \sweave package, i.e.\ it makes + the \texttt{Sinput} and \texttt{Scode} environments behave as the + \texttt{Rcode} environment , and the \texttt{Soutput} like the + \texttt{Routput} environment. + + If \texttt{Sinput} should have a slightly different look than + \texttt{Rcode}, then use the \texttt{Sinput} style to add your extra + configuration. (The \sweave package typesets the contents of the + \texttt{Sinput} env to be in the typewriter/monospace font plus + italic, whereas we just set it in typewriter/monospace.) + +\item[sasweave] Similar for the sasweave package, adding this options, + we will overwrite \texttt{SASinput}, \texttt{SASoutput} and + \texttt{SAScode} environments with our versions. Note you will have + to load \pkg \emph{after} the \texttt{SasWeave} + package.\footnote{Because \texttt{SasWeave} use the same environment + names as we do.} + + Please note: This option has \emph{not} been throughly + tested. Please let me know if it works as advertised. + +\item[\meta{other}] Other options will be passed on to the + \texttt{listings} package. +\end{description} + + +\chapter{Configuration} +\label{cha:configuration} + +As a frontend to listings, the configuration is based upon listings +\emph{styles}, i.e.\ collections of listings configurations. These are +applied in left to right fashion, the last configuration loaded takes +precedence. + + +\section{Titles} +\label{sec:macros} + +These macros holds the titles for the four types of displays. English: +\getsniplet{englishnames}{} +And for Danish: +\getsniplet{danishnames}{} + + +\fancybreak{} + +Note if you are using \texttt{babel} and the \texttt{babel} option to +\pkg, then these names are added to the language setup, and thus if +you want to change then you will have to add your changes to the +language setup as well. + +\section{Handling listings configuration of our environments and macros} +\label{sec:handl-list-conf} + +The listings configuration we use in this package is based on the +listings concept of \emph{styles}. A style is basically just giving a +collection of listings key-value sets a more convenient name. At first +glance, this may seem a tedious method for configuration instead of +giving various features macro names and letting the user change those +macros. Been there, done that. Given the shear number of +\texttt{listings} options, this would make configuration very un-flexible. + + +The general listings syntax for styles is +\begin{Show} + \lstdefinestyle|\marg{name}|{ + |\meta{key-value set}| + } +\end{Show} +One drawback is that if \meta{name} already exist, then you will +replace the contents of this style. Currently there is \emph{no} +manner in which to \emph{add} to a style. + +Thus it is a rather bad idea to provide the configuration as one long +style, because then changing a small thing, would require the user to +retype the rest of the configuration. Instead we split the +configuration into smaller themed pieces. The user then have a choice +of either overwriting one of these pieces or override a special user +style which is executed as the last style (and thus overwrites any +former style). + +The settings can be seen in Section~\ref{cha:defa-list-style}. The +styles are broken into smaller pieces. In some cases it make sense to +change one of these smaller pieces, in other cases it is easier to +add stuff to the provided \texttt{\meta{name}-\meta{type}-user} +styles. + + + +\section{Configuration FAQ/Examples} +\label{sec:configuration-faq} + +Here follows a list of FAQs as to how one would make some +configuration changes. Again we remind the user, that it is not +possible to add to a \texttt{listings} style. Thus you will have to +add all your setting for, say, \texttt{r-user}, into one single call +to \cs{lstdefinestyle}. + + +\subsection{Font} + +\begin{question}{I'd like to change the font size} + The gereral fontsize (not comments) is handled by the keyword + \texttt{basicstyle}, so you can change the font size for SAS code + in two ways, + \begin{solution} + \lstdefinestyle{sas-code-user}{ + basicstyle=\ttfamily\footnotesize + } + \end{solution} + or by overwriting the default SAS code font setting: + \begin{solution} + \lstdefinestyle{sas-code-fonts}{ + basicstyle = \ttfamily\small, + } + \end{solution} +\end{question} + + + +\subsection{Colors} +\label{sec:colors} + +The default colors are \texttt{SnRFrame} \showcolor{SnRFrame} for the +frame, and \texttt{SnRBG} \showcolor{SnRBG} for the background. If the +\texttt{grayscale} option is used, the mentioned colored are mapped on +to \texttt{SnRFrameGray} \showcolor{SnRFrameGray} and \texttt{SnRBGGray} +\showcolor{SnRBGGray}. + +\begin{question}{I'd like other colors} + We automatically load the \texttt{xcolor} package for colors, so we + refer that package for details. If you just want to change, say, the + background color, try (\texttt{after} \pkg) + \begin{solution} + \definecolor{SnRBG}{gray}{0.8} + \end{solution} + for a gray tone (1 means white). If one loads the \texttt{xcolor} + package \emph{before} \pkg, then one can pass certain options to it + and get access to a lot of color names, a survey of these can be + found in the \texttt{xcolor} manual, \cite{xcolor}. + + The two default colores are defined as + \begin{solution} + \definecolor{SnRBG} {rgb}{0.94,0.97,1} + \definecolor{SnRFrame}{rgb}{0.79,0.88,1} + \end{solution} +\end{question} + +\begin{question}{I'd like different colors for code and output} + Since the \texttt{\meta{name}-\meta{type}-user} styles are executed + at the very end of the configuration, it will be suitable to add + them there. Here is how to make the \SAS code have a blue background + while leaving the \SAS output with the default. + \begin{solution} + \lstdefinestyle{sas-code-user}{ + backgroundcolor = \color{blue}, + } + \end{solution} + Note: Remember that there will only be one \texttt{sas-code-user}, + thus if you have several configurations to add to it, collect them + in one such \cs{lstdefinestyle}. +\end{question} + +\begin{question}{How about the color of the text} + This can be seen in three different ways: regular text, comments and + keyword. (In our case keywords only apply to \SAS code.) This means + that colors will have to be inserted into say the + \texttt{basicstyle} key to change the basic font color. Here is + instead how to make all \SAS comments green, note that we have to + copy the rest of the font settings for \SAS comments, as we cannot + add to a setting. + \begin{solution} + \lstdefinestyle{sas-code-user}{ + commentstyle = \normalfont\slshape\ttfamily\footnotesize\color{green}, + } + \end{solution} + When dealing with \SAS keywords one can even add different colors to separate + groups of keywords, though this is a bit out of our scope in this manual. +\end{question} + + + +\subsection{Frames} +\label{sec:frames} + +Listings supports a number of different types of frames, see the +manual (\cite{listings}) for details. + +\begin{question}{I like the settings from the old \protect\texttt{SASdisplay} + package with the line above and below} + Here we choose to simply overwrite a \texttt{frame} style. + \begin{solution} + \lstdefinestyle{r-frame}{ + frame = lines, + framesep = 0.5em, + framerule = 1mm, % thickness of the rule + } + \end{solution} +\end{question} + +\begin{question}{No rules} + \begin{solution} + \lstdefinestyle{r-frame}{} + \end{solution} +\end{question} + +\fancybreak{} + +\begingroup\sloppy +A user may want to experiment with the keys +\texttt{x\meta{left|right}margin} and +\texttt{framex\meta{left|right|\allowbreak top|\allowbreak bottom}margin}. + +\endgroup + +\subsection{Captions} +\label{sec:captions-1} + +This is not a configuration as such but rather a hint to how one adds +a caption. + +If the \texttt{noautotitles} is not activated, all non-starred +environments and input macros will get an automatic caption, including +a number. If one wish to add extra text use the following to the +options of the environment or input macro. +\begin{solution}[gobble=0] + caption=|\marg{My text}| +\end{solution} +Remember the \texttt{\{\}} pair around the text. + +\fancybreak{} + +In this version of \pkg `list of \dots' are not supported due to +technical difficulties. + +\fancybreak{} + +If you want to configure captions related to \texttt{listings}, please +use +\begin{solution}[gobble=0] + \captionsetup[lstlisting]{|\meta{options}|} +\end{solution} +For example, in this document we use +\begin{solution}[gobble=0] + \captionsetup[lstlisting]{ + font=small, + labelfont=bf + } +\end{solution} +to make the label text bold, and the entire caption text in \cs{small}. + + + +Note that numbered construction without a caption are typeset as +\verb|Name Num|, with a caption this change into \verb|Name Num: Caption|. + +\begin{question}{I do not like numbers, but I'd like to add some + titling info for some of my code.} + If you do not want to use the auto numbering scheme, then use the + \texttt{noautotitles-sas} or \texttt{noautotitles-r} package + options. Then to add just a title, add the following to the + \meta{options} + \begin{solution} + title={My title text} + \end{solution} + It is simular to the \texttt{caption} option, but has no numbers or + preceeding text. +\end{question} + +\begin{question}{How do I refer to code or output?} + First of all, as with floats, it is the caption that provide the + number that one can refer to. So as long as the code or output is + numbered, then one can just add + \begin{Show} + label=|\meta{keyname}| + \end{Show} + to the environment or inclusion macro \meta{options}. + + You can of course also add a label even if it is not numbered, then + \cs{ref}\marg{key} will just not be weldefined. But + \cs{pageref}\marg{key} will! +\end{question} + + +\subsection{Keywords} +\label{sec:keywords} + +\begin{question}{In a presentaion, I'd like to highlight a word} + See the \texttt{emph} and \texttt{emphstyle} keys. Here is an + example. + \begin{solution} + \begin{SAScode*}[emph={INSIGHT},emphstyle=\color{red}\bfseries] + PROC INSIGHT DATA data=fisk; + \end{SAScode*} + \end{solution} + resulting in + \begin{SAScode*}[emph={INSIGHT},emphstyle=\color{red}\bfseries,gobble=2] + PROC INSIGHT DATA data=fisk; + \end{SAScode*} +\end{question} + +\begin{question}{How do I disable the keyword marking?} + You could either specify en empty language, i.e.\ \texttt{language=} + to eithor the \meta{options} or to a global style. + + Or you could redefine the keyword style: + \begin{solution} + keywordstyle= + \end{solution} +\end{question} + + +\begin{question}{I typeset SAS code, but keywords are not being marked!?} + This is usually because the mono space font (i.e.\ the font behind + \cs{ttfamily}) does not support boldface (as that is the default + manner which we mark keywords). + + One such example is the default \LaTeX\ font: Computer Modern. Its + mono space has no bold version. + + Solutions: see + \url{http://www.tug.dk/FontCatalogue/typewriterfonts.html}, you will + need to look for fonts that are shown to support + \cs{bfseries}. + + In this manual we use \texttt{beramono}. Another interesting + solution is to use + \begin{solution} + \renewcommand\ttdefault{txtt} + \end{solution} +\end{question} + + +\subsection{Escape to \LaTeX} +\label{sec:escape-latex} + +This is a very handy feature and can e.g.\ be used to get formatted +\LaTeX\ code inside, say, a comment. For example using +\begin{Show}[escapeinside={}] + escapeinside=||, +\end{Show} +means that if one write \verb+|$a_{ij}$|+ in a comment one would get +$a_{ij}$ typeset in the output. + +A feature like this is \emph{not} enabled by default. Though a user +can always add it globally to the settings of his/her document, say using +\begin{Show}[escapeinside=] + \lstdefinestyle{sas-code-user}{ + escapeinside=||, + } +\end{Show} +It does not have to be >>\texttt{|}<< that is the escape character. + +It can be locally disabled by adding +\begin{Show} + escapeinside={}, +\end{Show} +in the \meta{options} for the environment or the input macro. + +\fancybreak{} + +The \texttt{listings} manual, \cite[Section~4.14]{listings} list other +features related to escaping back to normal \LaTeX\ formatting. + + +\subsection{Input encodings (e.g. UTF8)} +\label{sec:input-encodings} + + +\begin{question}{I keep getting errors when I include my program, + something about undefined chars!?} + + The problem here is that \texttt{listings} cannot cope with so-called two two-byte characters, + \texttt{listings} needs to do a lot of parsing which may break when dealing with e.g. two-byte + UTF8 chars (essentially all non-acsii chars). + + At the moment, no-one have made a UTF8 compatible version of \texttt{listings}, so we need to cope + somehow. + + We will be assuming you are working with UTF8 files (both on the LaTeX side, and any including + source code), UTF8 is recommended nowadays, so we will ignore working purely in latin1 (which + \texttt{listings} has no issues with at all). + + \fancybreak{} + + First scenario: Assuming all your \texttt{listings} presented material comes from external + sources, e.g. they are inputted, and assuming your UTF8 sources code is compatible with the latin1 + encoding (aka Western European languages), then you can simply additionally use the package + \texttt{listingsutf8}. It extends the file inclusion feature and extend the input encoding + syntax. Add \texttt{listingsutf8} to your preamble, and using + \begin{solution} + \lstdefinestyle{r-include-code-user}{ + inputencoding=utf8/latin1 + } + \end{solution} + will attempt to auto convert the included code into latin1 before handing it off to + \texttt{listings}. See \cite{listingsutf8} for a bit more details. + + \fancybreak{} + + Another solution, which works very well is using the the \texttt{literate} option. The value of + this key is read in triples, and is basically saying, if you see this char, typeset this + instead. Here is an example with the Danish æøå: + \begin{solution} + \lstdefinestyle{r-code-user}{ + literate={æ}{\ae}1% + {Æ}{\AE}1% + {ø}{\o}1% + {Ø}{\O}1% + {å}{\aa}1% + {Å}{\AA}1,% + } + \end{solution} + (add the comma after the last one). There are several examples on + \url{http://tex.stackexchange.com} if you search for + ``\texttt{listings literate}''. + + As for the syntax of the triple: \marg{input}\marg{typeset output}\marg{length}. + +\end{question} + + +\subsection{Other} +\label{sec:other} + +\begin{question}{I'd like to have line numbers} + Here is how to add line numbers to all \R code. + \begin{solution} + \lstdefinestyle{r-code-user}{ + numbers = left, + numberstyle = \tiny + } + \end{solution} + Line numbers can be configured further, see section 4.8 in the + \texttt{listings} manual, \cite{listings}. + + Line numbers can be very handy when displaying source code. For + output, it might not be that relevant. + + It \emph{is} possible to actually label and refer to specific lines + in a piece of code, see section 7 in the \texttt{listings} manual, + \cite{listings}. +\end{question} + + + + +\begin{question}{I have many blank lines, can some be ignored?} + Yes with the \texttt{emptylines} key. It determine the number of + consecutive blank lines to allow in the output. By default + \texttt{listings} will already ignore blank lines at the end of what + ever is shown. To show only one blank line in the output for \R, try + \begin{solution} + \lstdefinestyle{r-user}{ + emptylines=1, + } + \end{solution} + If you are also using line numbers, you may want to use + \begin{solution} + \lstdefinestyle{r-user}{ + emptylines=*1, + } + \end{solution} + then the line numbers `jump' correctly in regards to the blank lines. +\end{question} + +\begin{question}{Can also blank space at the start of lines be + ignored?} + Of course, that key is called \texttt{gobble}, its value will + indicate the number of characters to eat (from the left). Note that + it will not distinguish between spaces and non-spaces, it will just + eat a set number of characters at the start of each line. +\end{question} + +\begin{question}{By the way, can one control the width of the \SAS + output from within a \SAS programme?} + Yes, try the >>\SASinline|OPTIONS LS=80;|<< setting. +\end{question} + + +\begin{question}{Can I show sniplets of code?} + Sure. See the \texttt{firstline} and \texttt{lastline} keys or the + \texttt{linerange}. They cannot be set globally, so can only be + added into environment or input macro options. + + \fancybreak{} + + There is also an experimental feature where instead of line numbers + one specify certain strings inside the external file. This can be + quite handy if the contents of the external file may + change.\footnote{Then one does not have to manually change the line + number references all the time.} Section 5.7 in the + \texttt{listings} manual (\cite{listings}) has more details. +\end{question} + + +\begin{question}{The quotes look odd in my code listings, can it look + more like keyboard keys?} + Of course. Add the \texttt{textcomp} package, and issue + \begin{solution} + \lstdefinestyle{r-user}{ + upquote=true, + } + \lstdefinestyle{sas-user}{ + upquote=true, + } + \end{solution} +\end{question} + + +\begin{question}{I use the \sweave package and overload the look using + \pkg. . I'd like \texttt{Sinput} to look more like the default in + \sweave.} + This can be done by using the extra \texttt{Sinput} style to + overload the basic style: + \begin{solution} + \lstdefinestyle{Sinput}{ + basicstyle = \ttfamily\itshape + } + \end{solution} +\end{question} + + +\chapter{Examples} +\label{sec:examples} + + +\section{\SAS} +\label{sec:sas} + +inline: \verb+\SASinline|RANGE xxx|+ results in +\SASinline|RANGE xxx|. + +Personally I often add >>\dots<< around inline sniplets to indicate +where they start and end. Sadly this is apparently not something one +can add into the inline macro definition because of its \cs{verb}-like +nature. + +\begin{SAScode}[caption={Test of caption}] +PROC INSIGHT DATA data=fisk; +SCATTER x1 x2 x3 x4 x5 * dosis vgt; +RUN; +OUTPUT +QUIT; /* a standard SAS comment */ +\end{SAScode} +was typeset via +\begin{Show} +\begin{SAScode}[caption={Test of caption}] +PROC INSIGHT DATA data=fisk; +SCATTER x1 x2 x3 x4 x5 * dosis vgt; +RUN; +OUTPUT +QUIT; /* a standard SAS comment */ +\end{SAScode} +\end{Show} +% +whereas + +\begin{SASoutput} + TABLE OF NIVEAU BY SUBJECT + + NIVEAU SUBJECT + + Frequency| + Percent | + Row Pct | + Col Pct |kem |mat |mus |samf | Total + ---------+--------+--------+--------+--------+ + h | 0 | 1 | 1 | 0 | 2 + | 0.00 | 20.00 | 20.00 | 0.00 | 40.00 + | 0.00 | 50.00 | 50.00 | 0.00 | + | 0.00 | 50.00 | 100.00 | 0.00 | + ---------+--------+--------+--------+--------+ + m | 0 | 1 | 0 | 1 | 2 + | 0.00 | 20.00 | 0.00 | 20.00 | 40.00 + | 0.00 | 50.00 | 0.00 | 50.00 | + | 0.00 | 50.00 | 0.00 | 100.00 | + ---------+--------+--------+--------+--------+ + o | 1 | 0 | 0 | 0 | 1 + | 20.00 | 0.00 | 0.00 | 0.00 | 20.00 + | 100.00 | 0.00 | 0.00 | 0.00 | + | 100.00 | 0.00 | 0.00 | 0.00 | + ---------+--------+--------+--------+--------+ + Total 1 2 1 1 5 + 20.00 40.00 20.00 20.00 100.00 + +\end{SASoutput} +% +comes from +\begin{Show} +\begin{SASoutput} + TABLE OF NIVEAU BY SUBJECT + + NIVEAU SUBJECT + + Frequency| + Percent | + Row Pct | + Col Pct |kem |mat |mus |samf | Total + ---------+--------+--------+--------+--------+ + h | 0 | 1 | 1 | 0 | 2 + | 0.00 | 20.00 | 20.00 | 0.00 | 40.00 + | 0.00 | 50.00 | 50.00 | 0.00 | + | 0.00 | 50.00 | 100.00 | 0.00 | + ---------+--------+--------+--------+--------+ + m | 0 | 1 | 0 | 1 | 2 + | 0.00 | 20.00 | 0.00 | 20.00 | 40.00 + | 0.00 | 50.00 | 0.00 | 50.00 | + | 0.00 | 50.00 | 0.00 | 100.00 | + ---------+--------+--------+--------+--------+ + o | 1 | 0 | 0 | 0 | 1 + | 20.00 | 0.00 | 0.00 | 0.00 | 20.00 + | 100.00 | 0.00 | 0.00 | 0.00 | + | 100.00 | 0.00 | 0.00 | 0.00 | + ---------+--------+--------+--------+--------+ + Total 1 2 1 1 5 + 20.00 40.00 20.00 20.00 100.00 + +\end{SASoutput} +\end{Show} + + + +\section{\R} +\label{sec:r} + + + +\verb+\Rinline|x <- a|+ result in \Rinline|x <- a| + +\inputRcode[ + emptylines=*1, + numbers=left, + numberstyle=\tiny, + caption={With just one blank line showing, plus line numbers. Note we + only show the first 25 lines.}, + linerange=1-25, +]{opg_G17.R} +\noindent +was typeset via +\begin{Show} +\inputRcode[ + emptylines=*1, + numbers=left, + numberstyle=\tiny, + caption={With just one blank line showing, plus line numbers. Note we + only show the first 25 lines.}, + linerange=1-25 +]{opg_G17.R} +\end{Show} + + + +\begin{Routput}[caption={Copied from an Sweave result.}] + [1] 0.0495 +\end{Routput} +is just sumple use of the \texttt{Routput} environment. + + +\chapter{Default style settings for \R and \SAS} +\label{cha:defa-list-style} + + + + + + +\section{Style settings for \R} +\label{sec:style-settings-r} + +Note how there are three user styles. The style \texttt{r-user} apply +to both \R code and \R output, whereas \texttt{r-code-user} and +\texttt{r-output-user} apply only to code and output +respectively. This means that if, say, the user want to change the +framing to a line above and below instead of the default box, the user +can either overwrite the \texttt{r-frame} style, or the +\texttt{r-user} style. + +The style settings are divided into three separate groups: (a) the +settings themselves, (b) user styles and (c) collector styles, which +are just a common name and loading order for other styles and + +\subsection{\R configuration styles} +\label{sec:r-conf-styl} + + +\getsniplet{rvskip}{\texttt{r-vskips}} +\getsniplet{rfonts}{\texttt{r-fonts}} The font is the base font for +the rest. If for example one make use of \texttt{emphstyle=\bfseries}, +then one will get the \texttt{basicstyle} plus bold face (if possible) +for things that are emphasized. +\getsniplet{rcharsandbreaks}{\texttt{r-chars-and-breaks}} +\getsniplet{rmarkup}{\texttt{r-markup}} +\R lang setting was added 2017/12/01 and requires a \texttt{listings} +newer from 2015 or later. +\getsniplet{rframe}{\texttt{r-frame}} +\getsniplet{rcolors}{\texttt{r-colors}} +\noindent +The colors being used as standard have special names. By default they +are in color. If the \texttt{monochrome} option is issued they are +mapped onto \texttt{SnRBGGray} and \texttt{SnRFrameGray}, the later +being black by default. + + +\getsniplet{rinline}{\texttt{r-inline}} +Note that by default, the inline style for \verb|\Rinline|, shares +nothing with the rest of the \R configuration and is loaded on its own. + +\R lang setting was added 2017/12/01 and requires a \texttt{listings} +newer from 2015 or later. + + +\subsection{\R user styles} +\label{sec:user-styles} + +These are all empty by default. There are two types of these: (i) +styles applying to both types (code and output) in one go, and (ii) +ones that are specific to either code or output. We also have a third +level \emph{file include} versus \emph{in document}. The more specific +the name, the later it will come in the collector styles (i.e.\ its +settings will apply last). + +\getsniplet{ruser}{\texttt{r-user} -- user stuff for everything \R} +\getsniplet{rcodeuser}{\texttt{r-code-user} -- only for \R code} +\getsniplet{routputuser}{\texttt{r-output-user} -- only for \R output} + +\fancybreak{} + +These three apply only to inclusion macros. Can be handy to specify an +input encoding for, say, all included code files. + +\getsniplet{rincludeuser}{\texttt{r-include-user}} +\getsniplet{rincludecodeuser}{\texttt{r-include-code-user}} +\getsniplet{rincludeoutputuser}{\texttt{r-include-output-user}} + +\subsection{\R collector styles} +\label{sec:r-collector-styles} + +Please note the calling sequence. + +\getsniplet{rstyle}{\texttt{r-style} -- all common code for \R} + +\getsniplet{rcode}{\texttt{r-code} -- specific for \R code} +\getsniplet{routput}{\texttt{r-output} -- specific for \R output} + + +\fancybreak{} + +Next we have the extra styles used for inclusion macros. They are the +same as for \R code and \R output, with the addition of two extra styles. + +\getsniplet{rincludecode}{\texttt{r-include-code}} +\getsniplet{rincludeoutput}{\texttt{r-include-output}} + + +\section{Style settings for \SAS} +\label{sec:style-settings-sas} + +The structure is similar to the one used for \R, though the font +settings are split in two. + +\subsection{\SAS configuration styles} + +\getsniplet{sasinline}{\texttt{sas-inline}} +\getsniplet{sasvskips}{\texttt{sas-vskips}} +\getsniplet{sascolors}{\texttt{sas-colors}} +\getsniplet{sascodefonts}{\texttt{sas-code-fonts}} +\getsniplet{sasoutputfonts}{\texttt{sas-output-fonts}} +\noindent +Note how we actually split the font settings in two. This is because +it is common to have \SAS code and \SAS output i different font +sizes. As \R output is not that common, this split has not been made +with \R, it will be up to the user. +\getsniplet{sascharsandbreaks}{\texttt{sas-chars-and-breaks}} +\getsniplet{sasmarkup}{\texttt{sas-markup}} +Note that only the \texttt{/*...*/} style \SAS comments are supported +for styling. The \texttt{*...;} syntax is \emph{not} supported. Also +note we had to change the \SAS settings for \texttt{listings} +otherwise we would be unable to style \SAS comments. + +\getsniplet{sasframe}{\texttt{sas-frame}} + + +\subsection{\SAS user styles} + +\getsniplet{sasuser}{\texttt{sas-user} -- user stuff for everything \SAS} +\getsniplet{sascodeuser}{\texttt{sas-code-user} -- only for \SAS code} +\getsniplet{sasoutputuser}{\texttt{sas-output-user} -- only for \SAS output} + +\fancybreak{} + +These three apply only to inclusion macros. Can be handy to specify an +input encoding for, say, all included code files. + +\getsniplet{sasincludeuser}{\texttt{sas-include-user}} +\getsniplet{sasincludecodeuser}{\texttt{sas-include-code-user}} +\getsniplet{sasincludeoutputuser}{\texttt{sas-include-output-user}} + + + + +\subsection{\SAS collector styles} + +\getsniplet{sasstyle}{\texttt{sas-style} -- all common code for \SAS} +\getsniplet{sascode}{\texttt{sas-code} -- specific for \SAS code} +\getsniplet{sasoutput}{\texttt{sas-output} -- specific for \SAS output} +\getsniplet{sasincludecode}{\texttt{sas-include-code}} +\getsniplet{sasincludeoutput}{\texttt{sas-include-output}} + + + +\subsection{Extra SAS keywords} +\label{sec:extra-sas-keywords} + +Jørgen Granfeldt supplied extra \SAS keywords to supplement those +supported by \texttt{listings}. The keywords are found in +\texttt{\pkg.cfg} and is labelled as the \texttt{sas-more-keywords} +style. Note that even though not required by \SAS, all supported +keywords are written in upper case. JG explains that this is +encouraged because that it makes it easier to tell the difference +between build in \SAS commands and user supplied (lower case) +variables and procedure names. + +Please note that we also change a list of \emph{other} keywords, +otherwise we will be unable to style \SAS comments. + + +Here is the current list. +\def\NAME{SASnRdisplay.cfg} +\getsniplet{sasmorekeywords}{\texttt{sas-more-keywords}, from \texttt{\pkg.cfg}} + +\begin{thebibliography}{9} +\RaggedRight +\bibitem{xcolor} Uwe Kern, \emph{Extending \LaTeX's color facilities: + the \textsf{xcolor} package}, 2016. + \addCTAN{/macros/latex/contrib/xcolor/}. + +\bibitem{listings} Various, \emph{The \textsf{listings} Package}, + 1996--2015. \addCTAN{/macros/latex/contrib/listings/}. + +\bibitem{etoolbox} + Philipp Lehman, Joseph Wright, +\emph{The etoolbox Package -- An e-TeX Toolbox for Class and Package + Authors}, 2017. \addCTAN{/macros/latex/contrib/listings/etoolbox}. + + +\bibitem{listingsutf8} + Heiko Oberdiek, \emph{The \textsf{listingsutf8} package}, 2016. + \addCTAN{/macros/latex/contrib/oberdiek/}. + +\bibitem{caption} Axel Sommerfelt, \emph{Customizing captions of + floating environments using the caption package}, 2011. + \addCTAN{/macros/latex/contrib/caption}. + + + + +\end{thebibliography} + + +\end{document} + +%%% Local Variables: +%%% mode: latex +%%% TeX-master: t +%%% End: + -- cgit v1.2.3