graph2texfile: Modifies the output of the tikz command and copies it to a...

View source: R/graphtikzcode.R

graph2texfileR Documentation

Modifies the output of the tikz command and copies it to a tex file.

Description

Based on tikzDevice::tikz.

Usage

graph2texfile(
  texte,
  output = tempfile(fileext = ".tex"),
  modify = NULL,
  widthe = 7,
  heighte = 7,
  caption = NULL,
  label = NULL,
  addfigureenv = FALSE,
  sanitize = FALSE,
  standalone = FALSE,
  addtopreamble = NULL,
  ...
)

Arguments

texte

file containing tikz code

modify

a function that takes a character string as a parameter and returns a character string

widthe

a numeric

heighte

a numeric

caption

a character string.

label

a character string.

addfigureenv

a boolean

sanitize

a booleaan

standalone

a booleaan

...

additional parameters to pass to tikzDevice::tikz

scale=c(1, 1)

a two parameters scale to apply to the graph

yxratio=c(1, 1),
usepackages

a character string

Examples

## First example: we generate the tikz code for a graph. 

outputtexfile<-tempfile(fileext = ".tex")
graph2texfile(
"print(ggplot2::ggplot(data=cars,ggplot2::aes(x=speed,y=dist))+
       ggplot2::geom_point())",
  output=outputtexfile)
readLines(outputtexfile)
graph2texfile(
"print(ggplot2::ggplot(data=cars,ggplot2::aes(x=speed,y=dist))+
       ggplot2::geom_point())",
  standalone=TRUE,
  output=outputtexfile,
  modify=function(y){
gsub("dist","$\\\\\\\\left(1-\\\\\\\\exp\\\\\\\\left(-\\\\\\\\mathrm(x)^2\\\\\\\\right)\left(\\\\\\\\sin(\\\\\\\\mathrm{x})+\\\\\\\\mathds{1}_{\\\\\\\\{0\\\\\\\\}}(\\\\\\\\mathrm{x})\\\\\\\\right)$",y)})
readLines(outputtexfile)
system(paste0("cd ",dirname(outputtexfile),"; lualatex '",basename(outputtexfile),"';"))
fs::file_show(gsub(".tex",".pdf",outputtexfile))

DanielBonnery/SweaveLst documentation built on May 4, 2022, 11:45 p.m.