summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/includernw
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-04-29 21:47:49 +0000
committerKarl Berry <karl@freefriends.org>2018-04-29 21:47:49 +0000
commitd66a575324f780018fe771d8f391d1cb011bdc9c (patch)
tree5f0a928a3d87ab0e7765494ccdaed1a6200fc031 /Master/texmf-dist/tex/latex/includernw
parent0c9f0e3c20d7b39baa0fdbdc1563c13349ad108a (diff)
includernw (29apr18)
git-svn-id: svn://tug.org/texlive/trunk@47484 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/includernw')
-rw-r--r--Master/texmf-dist/tex/latex/includernw/includeRnw.sty139
1 files changed, 139 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/includernw/includeRnw.sty b/Master/texmf-dist/tex/latex/includernw/includeRnw.sty
new file mode 100644
index 00000000000..14cecb5b9c1
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/includernw/includeRnw.sty
@@ -0,0 +1,139 @@
+% Source (with comments) can be found at https://github.com/Strauman/includeRnw/
+%% The LaTeX package includeRnw - version v0.0.2 (2018/04/29) - build 10
+%% 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/04/29 v0.0.2 Makes commands for including external .Rnw files.]
+\providecommand\rnw@loglevel{0}
+\RequirePackage{pdftexcmds}
+\RequirePackage{kvoptions}
+\let\incl\input
+\RequirePackage{kvoptions}
+\SetupKeyvalOptions{ family=includeRnw,
+ prefix=rnw@opt@
+}
+\DeclareBoolOption[true]{build}
+\DeclareComplementaryOption{halt}{build}
+\DeclareBoolOption[false]{new}
+\DeclareBoolOption[true]{knithead}
+\DeclareComplementaryOption{noknithead}{knithead}
+\ProcessKeyvalOptions*\relax
+\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\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\@latex@warning{#2}\fi}
+\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[0]{Deciding whether to do knitting}
+ \let\ifrnw@local@build\ifrnw@opt@build
+ \newif\ifrnw@doknit
+ \rnw@doknittrue
+ \@dlog[2]{Decision is given option: \givenopt}
+ \ifnum\pdfstrcmp{\rnw@gopt@force}{\givenopt\relax}=\z@\relax\rnw@doknittrue\@dlog[2]{Focing build}\else%
+ \ifnum\pdfstrcmp{\rnw@gopt@halt}{\givenopt\relax}=\z@\rnw@doknitfalse\relax\else%
+ \ifrnw@opt@new%
+ \else%
+ \let\ifrnw@doknit\ifrnw@opt@build\relax%
+ \fi%
+ \fi
+ \fi
+\ifrnw@doknit
+\@dlog[1]{Decided to build}
+}
+\def\rnw@purge@outdir{ \immediate\write18{rm -rf \rnw@dir@output}
+ \immediate\write18{mkdir \rnw@dir@output}
+}
+\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
+ \IfFileExists{\rnw@infile@fullpath}{ \@dlog[2]{Building \rnw@infile@fullpath\space to \rnw@dir@output/\filename@base\rnw@suffix.tex}
+ \immediate\write18{R -e 'library("knitr");knit("\rnw@dir@input/\rnw@infile@fullpath", "\rnw@dir@output/\filename@base\rnw@suffix.tex")' &> \rnw@file@knitlog}
+}{\@latex@error{includeRnw: Could not find file that I was asked to knit: \rnw@infile@fullpath!}{}\stop}
+ \else \@dlog[2]{- 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