Closed jmarca closed 9 years ago
Sorry, I did not see this before.
Define a vimtyping
environment, say Rtyping
and then set readcommand=\typeRtypingfile
.
Ah cool. I will try that today.
@jmarca Could you confirm whether my suggestion works? If so, I will like to close this issue.
I'll check. I honestly don't remember how I solved it, but I will dig up the report and check.
Yes it works. Details:
My test.tex
file reads:
\usetypescript[termes]
\setupbodyfont[termes,14pt]
\usecolors[xwi]
\defineframedtext
[framedcode]
[strut=yes,
offset=2mm,
leftframe=on,
foreground=color,
foregroundcolor=blue,
width=\textwidth,
align=right,
background=color,
backgroundcolor=yellow,
frame=off]
\usemodule[vim]
\definevimtyping [R][syntax=r,
before={\startframedcode},
after={\stopframedcode},
margin=0.5cm,
directory=output/]
\definevimtyping [RBLOCKOUTPUT][syntax=r,
before={\startframedcode[backgroundcolor=beige]},
after={\stopframedcode},
margin=0.5cm,
directory=output/]
\defineexternalfilter
[markdown]
[filtercommand={ \space
echo 'SECFILTER s/^\externalfilterparameter{markdownbasenest}/\externalfilterparameter{markdownsectionnest}\externalfilterparameter{markdownbasenest}/g'; \space
sed 's/^\externalfilterparameter{markdownbasenest}/\externalfilterparameter{markdownsectionnest}\externalfilterparameter{markdownbasenest}/g' \space
\externalfilterinputfile\space > \externalfilterinputfile.tmp.md; \space
pandoc -t context --filter=filters/context-float-refs.js \space
\externalfilterinputfile.tmp.md -o \externalfilteroutputfile; \space
rm tmp.md
},
directory=output]
\defineexternalfilter
[Rcode]
[
filtercommand={R CMD BATCH -q --restore --slave --save --no-timing \externalfilterinputfile\space \externalfilteroutputfile},
output=\externalfilterbasefile.out,
readcommand=\typefile,
cache=yes,
directory=output,
continue=yes]
%% this one defaults to readfile, not typefile
\defineexternalfilter
[Recho]
[
filtercommand={Rscript --restore \externalfilterinputfile\space |\space pandoc -t context\space --filter=filters/context-float-refs.js\space -o \externalfilteroutputfile},
%%output=\externalfilterbasefile.out,
%%cache=yes,
directory=output,
continue=yes]
%% this one hides output
\defineexternalfilter
[Rhidden]
[
filtercommand={R CMD BATCH -q --save --restore --no-timing
\externalfilterinputfile\space \externalfilteroutputfile},
output=\externalfilterbasefile.out,
read=no,
cache=yes,
directory=output,
continue=yes]
\defineexternalfilter
[RcodeFormatted]
[
filtercommand={R CMD BATCH -q --restore --slave --save --no-timing \externalfilterinputfile\space \externalfilteroutputfile},
output=\externalfilterbasefile.out,
readcommand=\typeRBLOCKOUTPUTfile,
cache=yes,
directory=output,
continue=yes]
\starttext
\startbodymatter
\processmarkdownfile{simpleR.md}
\stopbodymatter
\stoptext
Then in my markdown file, I have:
# testing
This is a test. First execute R hidden from output.
\startRhidden
a <- 2
b <- 3
\stopRhidden
Execute R code, but it is not piped through vim module:
\startRcode
print(paste(a,'and',b))
result <- print(paste(a,'and',b))
cat (result)
\stopRcode
Can format but not execute R using the vimtyping `R` environment.
\startR
print(paste(a,'and',b))
result <- print(paste(a,'and',b))
cat (result)
\stopR
And can get executed R plus inline echo: \inlineRecho{cat(paste(a,'and',b))} using
`Recho` environment.
And finally, can execute R and format the output through the vim
typing module by using `RCodeFormatted`. Note the beige background.
\startRcodeFormatted
print(paste(a,'and',b))
result <- print(paste(a,'and',b))
cat(result)
\stopRcodeFormatted
The end
Output looks like:
This is a question, not a bug or issue.
I want to process R, and then have the commands piped to the vimtyping filter.
So, how to I "wrap" the output from the filter module in another set of \startR \stopR commands that will trigger the vimtyping filter module?
Here is what I tried, without success:
First, the base case (largely based on your test case for R)
The R code is executed and formatted as plain text. The "ls()" command is not executed, but is syntax colored. What I want to do is to put
\startR
and\stopR
in the filter as follows:However, that dies, with context hanging up on the stopR of the next bit of code:
I don't really understand tex/context macros, but it just seems like there should be some way to "protect" the macro so that it is not executed, but rather is written out as a command first and then interpreted in a second pass?
Any help would be appreciated, or redirection to a more appropriate channel.