[Tikzdevice-bugs] Single file with tikzDevice
Cameron Bracken
cameron.bracken at gmail.com
Sun Dec 6 21:04:41 CET 2009
I liked this idea so much that I implemented it right away. You can
get it from the master branch of my github fork until the next release
http://github.com/cameronbracken/rtikzdevice/network
Instead of "append" i called it "console." It works nearly as you envisioned:
cat("\\documentclass{article}
\\usepackage{tikz}
\\begin{document}
\\begin{figure}[ht]
\\centering
", file = "myfile.tex")
sink("myfile.tex",append=T)
tikz(console=T, width=5, height=5)
x <- rnorm(100)
plot(x)
quiet <- dev.off()
sink()
cat("\\caption{caption}
\\label{fig:inline}
\\end{figure}
\\end{document}
", file = "myfile.tex", append = TRUE)
The following will now produce a self contained tex file:
\documentclass{article}
\usepackage{tikz}
\usepackage[nogin]{Sweave}
\begin{document}
\begin{figure}[ht]
\centering
<<inline,echo=F,results=tex>>=
require(tikzDevice)
tikz(console=T,width=5,height=5)
x <- rnorm(100)
plot(x)
dummy <- dev.off()
@
\caption{caption}
\label{fig:inline}
\end{figure}
\end{document}
-Cameron
On Sun, Dec 6, 2009 at 9:46 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> If you able to provide this feature (i.e. incorporate the tikz tex directly
> into the current file rather than writing out a temporary file and reading
> it back in) then that would be useful since one of the key potential
> advantages of tikz and pgf are the ability to have a single file rather than
> multiple files. Perhaps an append=TRUE argument like this:
>
> cat("\\documentclass{article}
> \\usepackage{tikz}
> \begin{document}
> \\begin{figure}[ht]
> \\centering
> ", file = "myfile.tex")
> tikz("myfile.tex", width=5, height=5, append = TRUE)
> x <- rnorm(100)
> plot(x)
> dev.off()
> cat("\\caption{caption}
> \\label{fig:inline}
> \\end{figure}
> \\end{document}
> ", file = "myfile.tex", append = TRUE)
>
> On Sun, Dec 6, 2009 at 11:34 AM, Cameron Bracken <cameron.bracken at gmail.com>
> wrote:
>>
>> Interesting Idea. This should work with plain Sweave. It is not very
>> efficient and would be very slow for large files since it must write
>> out then read in then write out.
>>
>> \documentclass{article}
>> \usepackage{tikz}
>> \usepackage[nogin]{Sweave}
>> \begin{document}
>> \begin{figure}[ht]
>> \centering
>> <<inline,echo=F,results=tex>>=
>>
>> require(tikzDevice)
>> tf <- tempfile()
>> tikz(tf,width=5,height=5)
>> x <- rnorm(100)
>> plot(x)
>> #Suppress "null device 1" from being printed
>> dummy <- dev.off()
>> cat(readLines(tf),sep='\n')
>>
>> @
>> \caption{caption}
>> \label{fig:inline}
>> \end{figure}
>> \end{document}
>>
>>
>> -Cameron
>>
>>
>>
>> On Sun, Dec 6, 2009 at 9:02 AM, Gabor Grothendieck
>> <ggrothendieck at gmail.com> wrote:
>> > I would like to create a single file that has my latex and tikzDevice
>> > output
>> > as opposed to outputting the tikZ output into a separate file and using
>> > \input . The latex would be generated using cat statements in R.
>> >
>> > Can that be done? If so, can you provide a small example.
>> >
>> >
>
>
More information about the Tikzdevice-bugs
mailing list