diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/includernw |
Initial commit
Diffstat (limited to 'macros/latex/contrib/includernw')
-rw-r--r-- | macros/latex/contrib/includernw/README.txt | 40 | ||||
-rw-r--r-- | macros/latex/contrib/includernw/includeRnw-doc.pdf | bin | 0 -> 156228 bytes | |||
-rw-r--r-- | macros/latex/contrib/includernw/includeRnw-doc.tex | 227 | ||||
-rw-r--r-- | macros/latex/contrib/includernw/includeRnw.sty | 181 |
4 files changed, 448 insertions, 0 deletions
diff --git a/macros/latex/contrib/includernw/README.txt b/macros/latex/contrib/includernw/README.txt new file mode 100644 index 0000000000..2499aad73e --- /dev/null +++ b/macros/latex/contrib/includernw/README.txt @@ -0,0 +1,40 @@ +includeRnw: +Makes commands for including external .Rnw files. + +├── README.txt +├── includeRnw-doc.pdf +├── includeRnw-doc.tex +└── includeRnw.sty + +Not tested on Windows! + +Quick start: + +\documentclass{article} +\usepackage{includeRnw} +\begin{document} + \includeRnw{path/to/my.Rnw} +\end{document} + + +Author: Storvik Strauman, Andreas + +For bug report, inquires, contributed or anything else: +https://github.com/Strauman/includeRnw/ + +Licence: + +The LaTeX package includeRnw - version v0.1.0 (2018/05/01) - build 11 +includeRnw.sty +------------------------------------------------------------------------------------------- +Copyright (c) 2018 by Andreas Storvik Strauman +------------------------------------------------------------------------------------------- +This work may be distributed and/or modified under the +conditions of the LaTeX Project Public License, either version 1.3c +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.3c or later is part of all distributions of LaTeX +version 2008/05/04 or later. +This work has the LPPL maintenance status `author-maintained'. +This work consists of all files listed in README.txt diff --git a/macros/latex/contrib/includernw/includeRnw-doc.pdf b/macros/latex/contrib/includernw/includeRnw-doc.pdf Binary files differnew file mode 100644 index 0000000000..a63b89d97b --- /dev/null +++ b/macros/latex/contrib/includernw/includeRnw-doc.pdf diff --git a/macros/latex/contrib/includernw/includeRnw-doc.tex b/macros/latex/contrib/includernw/includeRnw-doc.tex new file mode 100644 index 0000000000..78051eda66 --- /dev/null +++ b/macros/latex/contrib/includernw/includeRnw-doc.tex @@ -0,0 +1,227 @@ +%% includeRnw v0.1.0b11 - 2018/05/01 +%% The LaTeX package includeRnw - version v0.1.0 (2018/05/01) build 11 +%% Manual/Documentation for includeRnw.sty +%% ------------------------------------------------------------------------------------------- +%% Copyright (c) 2018 by Andreas Storvik Strauman +%% ------------------------------------------------------------------------------------------- +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% 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.3c or later is part of all distributions of LaTeX +%% version 2008/05/04 or later. +%% This work has the LPPL maintenance status `author-maintained'. +%% This work consists of all files listed in README.txt +\documentclass[a4paper]{article} +\usepackage[all]{tcolorbox} +\usepackage{needspace} +\usepackage{tabularx} +\usepackage{geometry} +\makeatletter +\def\input@path{{../../docs/}} +\lstdefinestyle{mydocumentation}{style=tcbdocumentation, + classoffset=0, + texcsstyle=*\color{blue}, + moretexcs={arrayrulecolor,draw,includegraphics,ifthenelse,isodd,lipsum,path,pgfkeysalso}, + classoffset=1, + moretexcs={% core + includeRnw + }, + texcsstyle=*\color{Definition}\bfseries, + classoffset=0,% restore default + } +\newtcolorbox{marker}[1][]{enhanced, + before skip=2mm,after skip=3mm, + boxrule=0.4pt,left=5mm,right=2mm,top=1mm,bottom=1mm, + colback=yellow!50, + colframe=yellow!20!black, + sharp corners,rounded corners=southeast,arc is angular,arc=3mm, + underlay={% + \path[fill=tcbcol@back!80!black] ([yshift=3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2); + \path[draw=tcbcol@frame,shorten <=-0.05mm,shorten >=-0.05mm] ([yshift=3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2); + \path[fill=yellow!50!black,draw=none] (interior.south west) rectangle node[white]{\Huge\bfseries !} ([xshift=4mm]interior.north west); + }, + drop fuzzy shadow,#1} + \def\l@macro#1#2{#1\hfill\newline} +\newcommand\macrotable{\hypersetup{linkcolor=black}\@starttoc{mac}\hypersetup{linkcolor=Definition}} +\newcommand\gh[1]{\href{#1}{https://github.com/#1}} +% --- CHANGELOG TABLE --- % +\newcommand*\l@version[2]{% + \ifnum \c@tocdepth >\z@ + \addpenalty\@secpenalty + \addvspace{1.0em \@plus\p@}% + \setlength\@tempdima{1.5em}% + \begingroup + \parindent \z@ \rightskip \@pnumwidth + \parfillskip -\@pnumwidth + \leavevmode \bfseries + \advance\leftskip\@tempdima + \hskip -\leftskip + #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{}\par + \endgroup + \fi} + \newcommand*\l@change[2]{% + \addvspace{0.5em \@plus\p@}% + \leftskip1em--\hspace{0.5em}\begin{minipage}{0.5\textwidth}#1\end{minipage}\hfill% + \begin{minipage}{0.3\textwidth}#2\end{minipage}\par% + } + +\newcommand\chlogtable{\begin{NoHyper}\@starttoc{chlog}\hypersetup{final}\end{NoHyper}} +\def\newversion#1{\addcontentsline{chlog}{version}{#1}} +\newcommand\change[2][]{\addtocontents{chlog}{\protect\contentsline{change}{#2}{#1}{section.\thepage}}} +% --- /CHANGELOG TABLE --- % + +\let\oldTOC\tableofcontents +\renewcommand\tableofcontents{\hypersetup{linkcolor=black}\oldTOC\hypersetup{linkcolor=Definition}} +\reversemarginpar +\def\updated#1{\tcbdocmarginnote{\bfseries{\color{blue}U}#1}} +\def\defnew#1{\tcbdocmarginnote{\bfseries{\color{green}N}#1}} + +\let\dac\docAuxCommand +\def\mdac#1{\docAuxCommand{\expandafter\@gobble\string#1}} + +\makeatother + +\long\def\keyDef#1#2#3#4{\begin{docKey}{#1}{=\meta{#2}}{\meta{default}=#3}#4\end{docKey}} +\long\def\optDef#1#2{\begin{docKey*}{#1}{}{}#2\end{docKey*}} +\tcbset{documentation listing style=mydocumentation} +% Magenta HREF style +\let\oldhref\href +\gdef\href#1#2{{\color{magenta}\oldhref{#1}{#2}}} +\tcbset{documentation listing style=mydocumentation,/tcb/color hyperlink=Definition} +\hypersetup{colorlinks=true} +% Give section some space +\let\oldsection\section +\gdef\section{\needspace{0.3\paperheight}\oldsection} +\let\oldsubsection\subsection +\gdef\subsection{\needspace{0.2\paperheight}\oldsubsection} + + +\setlength{\parindent}{0pt} +\title{{includeRnw - manual\\ v0.1.0{\\[-0.5em]\footnotesize(build 11)}}} +\author{Andreas Strauman} +\begin{document} +\maketitle +This package is for including \texttt{.Rnw}-files in normal \texttt{.tex}-files. +It invokes the command \texttt{R} from your command line.\\ + +If you found any bugs or want new functionality, to contribute, view the commented source, get latest version of this package or get in touch with me, you can do all of that at\\\url{https://github.com/Strauman/includeRnw/}. If you have questions of functionality, kindly direct them to the community\\ \url{http://tex.stackexchange.com}. The author is active on this site regularly. + +\tableofcontents +\clearpage +\section{Quick start} +\begin{dispListing} + \documentclass{article} + \usepackage{includeRnw} + \begin{document} + \includeRnw{path/to/my.Rnw} + \end{document} +\end{dispListing} + +The Rnw-file: +\begin{dispListing} + <<pChunk, echo=F, cache=F >>= + read_chunk('r/.r') + @ +\end{dispListing} +\begin{marker} +Path to \texttt{r}-files are relative to the path of the \texttt{.Rnw}-file +\end{marker} + \section{Reference} +\filbreak\subsection{Reference} +\begin{docCommand}{includeRnw}{\oarg{irw-options}\marg{path/to/file.Rnw}} +\updated{v0.1.0\\2018/05/01 }Compiles .Rnw-files using R. Assumes that \texttt{R} can be called +from the command line. It is optional to add the extension \texttt{.Rnw} +\end{docCommand} +\filbreak\subsection{Command Options} +Options to use with \refCom{includeRnw} +\optDef{h}{Use the \refKey{h} to prevent \dac{includeRnw} from +actually knitting the file, but only include the knitted \texttt{.tex} file} +\optDef{f}{\refKey{f} forces \dac{includeRnw} to actually knitting the file no matter, +what (as long as it exists).} +\filbreak\subsection{Package Options} +\dac{usepackage}[\oarg{options}] where the \meta{options} are:\\ +\optDef{halt}{If you do \dac{usepackage}[halt]\brackets{includeRnw}, +then \dac{includeRnw}\{my/file.Rnw\} will \emph{not} run knitr on it. +However, if the knitted file exists, it will include this. You can +override this with the f-option in the \refCom{includeRnw}: +\dac{includeRnw}[f]\brackets{my/file.Rnw}} +\optDef{new}{This option would make the \refCom{includeRnw} only +run knitr on the file if the knitted file does not exist. +} +\optDef{noknithead}{ +This option will prevent \dac{includeRnw} from building and including the knitr-preamble. +} +\optDef{texenv}{ +Using the \texttt{texenv} option disables the default Rnw syntax and allows for a new one. See example below +} + The two following examples do the exact same thing:\\ + This example use standard Rnw: +\begin{dispListing} +\documentclass[a4paper]{article} +\usepackage{includeRnw} +\begin{document} + <<pChunk, echo=F, cache=F >>= + read_chunk('r/myRScript.r') + @ +\end{document} +\end{dispListing} +The following chunk uses the \refKey{texenv} option: +\begin{dispListing} +\documentclass[a4paper]{article} +\usepackage[texenv]{includeRnw} +\begin{document} + \begin{Rnw}{myChunk, echo=F, cache=F} + read_chunk('r/myRScript.r') + \end{Rnw} +\end{document} +\end{dispListing} +\filbreak\subsection{User macros} + The default user macro settables are +\begin{dispListing} +\rnwInputDirectory{.} +\rnwKnittedSuffix{knitted} +\rnwKnitlogFile{\rnw@dir@output/knitlog.log} +\rnwKnitheadName{\rnw@dir@output/knithead} +\end{dispListing} +Where \dac{rnw@dir@output} is the value of the set \dac{rnwOutputDirectory} +\begin{docCommand}{rnwInputDirectory}{\marg{directory}} +\defnew{v0.0.2\\2018/04/28 } This command sets what directory \dac{includeRnw} will be using. If you e.g. + have all the Rnw-files inside a directory called \texttt{myRnws} then + \dac{rnwInputDirectory}\brackets{myRnws} would fix this. +\end{docCommand} +\begin{docCommand}{rnwKnittedSuffix}{\marg{text}} +\defnew{v0.0.2\\2018/04/28 } Set the default suffix of the filename of the knitted output +\end{docCommand} +\begin{docCommand}{rnwKnitlogFile}{\marg{filename}} +\defnew{v0.0.2\\2018/04/28 } Sets the filename of the log output by knitr. +\end{docCommand} +\begin{docCommand}{rnwKnitheadName}{\marg{filename}} +\defnew{v0.0.2\\2018/04/28 } Sets the filename of the preamble generated by knitr. +\end{docCommand} +\filbreak\subsection{List of all macros} + + \addcontentsline{mac}{macro}{\refCom{includeRnw}}{} +\addcontentsline{mac}{macro}{\refCom{rnwInputDirectory}}{} +\addcontentsline{mac}{macro}{\refCom{rnwKnitheadName}}{} +\addcontentsline{mac}{macro}{\refCom{rnwKnitlogFile}}{} +\addcontentsline{mac}{macro}{\refCom{rnwKnittedSuffix}}{} + + \macrotable + + +% \newgeometry{lmargin=0.7cm} +\section{Changelog} +\newversion{v0.0.1 2018/04/20} +\change{Created the package} +\newversion{v0.0.2 2018/04/28} +\change{Fixed wrong error message on no shell-escape} +\change{Added macros for setting custom values} +\change{Added \refKey{noknithead}} +\newversion{v0.1.0 2018/05/01} +\change{Added \refKey{texenv}} +\change{Fixed bug where \refKey{new} and \refKey{halt} package options didn't work} +\change{Fixed bug where \refKey{n}, \refKey{h} and \refKey{f} command options didn't work} +\chlogtable + \end{document} diff --git a/macros/latex/contrib/includernw/includeRnw.sty b/macros/latex/contrib/includernw/includeRnw.sty new file mode 100644 index 0000000000..b309ba4f96 --- /dev/null +++ b/macros/latex/contrib/includernw/includeRnw.sty @@ -0,0 +1,181 @@ +% Source (with comments) can be found at https://github.com/Strauman/includeRnw/ +%% The LaTeX package includeRnw - version v0.1.0 (2018/05/01) - build 11 +%% includeRnw.sty +%% ------------------------------------------------------------------------------------------- +%% Copyright (c) 2018 by Andreas Storvik Strauman <andreas dot s dot strauman at uit dot no> +%% ------------------------------------------------------------------------------------------- +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% 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.3c or later is part of all distributions of LaTeX +%% version 2008/05/04 or later. +%% This work has the LPPL maintenance status `author-maintained'. +%% This work consists of all files listed in README +\ProvidesPackage{includeRnw}[2018/05/01 v0.1.0 Makes commands for including external .Rnw files.] +\providecommand\rnw@loglevel{0} +\def\includeRnwVer{11 2018/05/01} +\RequirePackage{pdftexcmds} +\RequirePackage{kvoptions} +\let\incl\input +\def\insp#1{\texttt{\string#1:\meaning#1}} +\def\inspw#1{\@latex@warning{\string#1:\meaning#1}} +\providecommand\rnw@loglevel{3} +\newcommand\@dlog[2][1]{\ifnum\rnw@loglevel>#1\relax\PackageWarning{includeRnw}{#2}{}\fi} +\RequirePackage{kvoptions} +\SetupKeyvalOptions{ family=includeRnw, + prefix=rnw@opt@ +} +\DeclareBoolOption[true]{build} +\DeclareBoolOption[true]{classicenv} +\DeclareComplementaryOption{halt}{build} +\DeclareBoolOption[false]{new} +\DeclareBoolOption[true]{knithead} +\DeclareComplementaryOption{noknithead}{knithead} +\DeclareComplementaryOption{texenv}{classicenv} +\ProcessKeyvalOptions*\relax +\def\rnw@knitCommand@classic{% +R -e 'library("knitr"); +knit("\rnw@dir@input/\rnw@infile@fullpath", "\rnw@dir@output/\filename@base\rnw@suffix.tex")' &> \rnw@file@knitlog +}% +\def\rnw@knitCommand@texenv{% +R -e "library('knitr'); +knit_patterns\string\$set(list( +chunk.begin = '\doublebs s*\fourbs begin\doublebs{Rnw\doublebs}\doublebs{(.+)\doublebs}', +chunk.end = '\doublebs s*\fourbs end\doublebs {Rnw\doublebs}', +inline.code = '\fourbs Sexpr\doublebs{([^{}]+)\doublebs}', +ref.chunk = '\fourbs rCode\doublebs{([^{}]+)\doublebs}' +)); +knit('\rnw@dir@input/\rnw@infile@fullpath', '\rnw@dir@output/\filename@base\rnw@suffix.tex')" &> \rnw@file@knitlog% +}% +\ifrnw@opt@classicenv\relax +\global\let\rnw@knitCommand\rnw@knitCommand@classic +\@dlog[1]{Using classic environment} +\else +\@dlog[1]{Using tex environment} +\global\let\rnw@knitCommand\rnw@knitCommand@texenv +\fi +\ifrnw@opt@build\else + \ifrnw@opt@new + \@latex@warning{includeRnw: can't use halt and new together. Falling back to new.} + \rnw@opt@haltfalse + \fi +\fi +\providecommand\rnw@dir@input{.} +\providecommand\rnw@dir@output{./knitrout} +\providecommand\rnw@suffix{knitted} +\providecommand\rnw@file@knitlog{\rnw@dir@output/knitlog.log} +\providecommand\rnw@filebase@knithead{\rnw@dir@output/knithead} +\def\rnw@filename@parse#1{% + \filename@parse{#1} + \edef\rnw@filepath{\filename@area\filename@base} + \edef\rnw@filebase{\filename@base} + \edef\rnw@fileext{\ifx\filename@ext\relax Rnw\else\filename@ext\fi} + \edef\rnw@infile@fullpath{\filename@area\filename@base.\filename@ext} +} +\def\rnw@clear@knitlog{% +\immediate\write18{echo "" > \rnw@file@knitlog} +} +\def\rnw@check@ouput@file{\rnw@dir@output/.includeRnwShellEscapeCheck} +\def\check@shell@escape{% + \ifcase\pdf@shellescape% + \PackageError{includeRnw}{\string\includeRnw\space requires --shell-escape}{}\stop\or% + \message{Shell escape test passed}\or% + \PackageError{includeRnw}{\string\includeRnw\space requires --shell-escape. Current is restricted shell escape}{}\stop\fi% +} +\def\check@output@dir{% + \immediate\write18{touch \rnw@check@ouput@file} + \IfFileExists{\rnw@check@ouput@file}{}{% + \immediate\write18{mkdir \rnw@dir@output} +} + \immediate\write18{rm \rnw@check@ouput@file} +} +\def\rnw@include@knithead{% + \IfFileExists{\rnw@filebase@knithead.tex}{}{% + \@dlog[0]{Creating knithead} + \immediate\write18{% + echo "<<create-preamble,echo=FALSE,results='asis'>>=\string\ncat(knitr:::make_header_latex())\string\n@" > \rnw@filebase@knithead.Rnw +}% + \immediate\write18{R -e 'library("knitr");knit("\rnw@filebase@knithead.Rnw","\rnw@filebase@knithead.tex")' >> \rnw@file@knitlog} +} + \IfFileExists{\rnw@filebase@knithead.tex}{ \@dlog[0]{Including knithead} + \incl{\rnw@dir@output/knithead.tex} +}{ \PackageError{includeRnw}{Could not find knitr preamble: \rnw@dir@output/knithead.tex}{} +} +} +\xdef\rnw@gopt@halt{h} +\xdef\rnw@gopt@force{f} +\def\ifrnw@should@knitr{ \@dlog[2]{Deciding whether to do knitting on \filename@base.Rnw} + \newif\ifrnw@doknit + \rnw@doknittrue + \@dlog[2]{Decision is given option: \givenopt} + \ifnum\pdfstrcmp{\givenopt}{\rnw@gopt@force}=\z@\relax\rnw@doknittrue\@dlog[0]{Focing build}\else% + \@dlog[2]{Force not given} + \ifnum\pdfstrcmp{\givenopt}{\rnw@gopt@halt}=\z@\relax + \@dlog[0]{Halt option given. Not building!}% + \rnw@doknitfalse\else% + \@dlog[2]{Halt opt for command not given} + \ifrnw@opt@new% + \@dlog[1]{"new" package option is given, building if \knitOutfile exists} + \IfFileExists{\knitOutfile}{\rnw@doknitfalse}{\rnw@doknittrue} + \else% + \@dlog[1]{No "new" given, falling back to package option "halt"} + \ifrnw@opt@build\rnw@doknittrue\else\rnw@doknitfalse\fi + \fi% + \fi + \fi +\ifrnw@doknit +} +\def\rnw@purge@outdir{ \immediate\write18{rm -rf \rnw@dir@output} + \immediate\write18{mkdir \rnw@dir@output} +} +\def\rnw@preKnit{\newtoks\mytoks +\mytoks{\\} +\def\bs{\@backslashchar} +\def\doublebs{\bs\bs\bs\bs\bs} +\def\fourbs{\doublebs\doublebs\doublebs} +} +\providecommand\rnw@execute@knitr[2][]{% + \def\givenopt{#1} + \rnw@filename@parse{#2} + \xdef\knitOutfile{\rnw@dir@output/\filename@base\rnw@suffix.tex} + \ifrnw@should@knitr + \@dlog[0]{Decided to build \filename@base.Rnw} + \IfFileExists{\rnw@infile@fullpath}{ \@dlog[2]{Building \rnw@infile@fullpath\space to \rnw@dir@output/\filename@base\rnw@suffix.tex} + \rnw@preKnit + \immediate\write18{\rnw@knitCommand} +}{\@latex@error{includeRnw: Could not find file that I was asked to knit: \rnw@infile@fullpath!}{}\stop} + \else \@dlog[0]{- Skipping knit of \rnw@infile@fullpath} + \fi + \IfFileExists{\knitOutfile}{% + \@dlog[2]{Found \knitOutfile. Including it.} + \incl{\knitOutfile} +}{% + \PackageError{includeRnw}{Couldn't find knitted file: \knitOutfile}{} +} +} +\newcommand\rnw@settable[3][]{% +\edef\reserved@R{\expandafter\@gobble\string #2}% +\@ifundefined\reserved@R% + {% + \gdef#2##1{\gdef#3{##1}#1} +}% + {% + \@ifundefined{no\reserved@R}{ \@latex@error{includeRnw: Tried to define \@backslashchar \reserved@R \space, but it's already defined. \MessageBreak If you don't need the command \@backslashchar \reserved@R \space, then just define \string\no\reserved@R\space before you include the includeRnw package: \string\def\string\no\reserved@R{}}{}\stop +}{ \@latex@warning{\@backslashchar\reserved@R is not defined by includeRnw since it was already defined someewhere else. Continuing since \string\no\reserved@R is defined.} +} +}% +} +\rnw@settable\rnwInputDirectory\rnw@dir@input +\rnw@settable\rnwKnittedSuffix\rnw@suffix +\rnw@settable\rnwKnitlogFile\rnw@file@knitlog +\rnw@settable\rnwKnitheadName\rnw@filebase@knithead +\let\includeRnw\rnw@execute@knitr +\let\purgeOutDir\rnw@purge@outdir +\check@shell@escape +\check@output@dir +\rnw@clear@knitlog +\ifrnw@opt@knithead% +\rnw@include@knithead +\fi |