1

所以我尝试使用 tikzDevice 来获取矢量图形,然后我想将其包含在我的 Overleaf 文件中。但是,当我使用此处的指令时,我遇到了问题。

另外,我使用 RStudio 版本 1.3.929 和最新的 MikTex。我还更新了所有软件包。

# Example by Ilyass

library(tikzDevice)
library(ggplot2)
    
options(tz="Europe/Berlin")

#Dummy data for the plot
y <- exp(seq(1,10,.1))
x <- 1:length(y)
data <- data.frame(x = x, y = y)

#Create a .tex file that will contain your plot as vectors
tikz(file = "plot_test.tex", width = 5, height = 5)

#Simple plot of the dummy data using LaTeX elements
    plot <- ggplot(data, aes(x = x, y = y)) + 
        geom_line() +
        ggtitle( paste("Fancy \\LaTeX ", "\\hspace{0.01cm} title")) +
        labs( x = "$x$ = Time", y = "$\\Phi$ = Innovation output") +
        theme_bw()

#This line is only necessary if you want to preview the plot right after compiling
print(plot)

#Necessary to close or the tikxDevice .tex file will not be written
dev.off()

如果我运行我的代码(见上文),我会收到错误消息:

TeX 无法计算以下指标:\char77

然后我运行它并收到此错误消息:

tikzTest("\\char77") 
 Active compiler:
    /usr/local/bin/pdflatex
    pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2021)
    kpathsea version 6.3.3

Measuring dimensions of: \char77
Running command: '/usr/local/bin/pdflatex' -interaction=batchmode -halt-on-error -output-directory '/var/folders/1r/rtb0lx8x5hdg48qw7bg3wh8c0000gn/T//RtmpIEsh0G/tikzDevice12365771d59f1' 'tikzStringWidthCalc.tex'
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode

TeX was unable to calculate metrics for:

    \char77

Contents of TeX file tikzStringWidthCalc.tex:

\documentclass[10pt]{article}

\usepackage{tikz}

\usepackage[active,tightpage,psfixbb]{preview}

\PreviewEnvironment{pgfpicture}

\setlength\PreviewBorder{0pt}

\usepackage[T1]{fontenc}

\usetikzlibrary{calc}

\batchmode
\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt, outer sep=0pt, scale=1] (TeX) {\char77};
\path let \p1 = ($(TeX.east) - (TeX.west)$),
    \n1 = {veclen(\x1,\y1)} in (TeX.east) -- (TeX.west)
    node{ \typeout{tikzTeXWidth=\n1} };
\end{tikzpicture}
\end{document}
Contents of log file tikzStringWidthCalc.log:

This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=pdflatex 2021.5.18)  18 JUN 2021 10:29
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**tikzStringWidthCalc.tex

(/var/folders/1r/rtb0lx8x5hdg48qw7bg3wh8c0000gn/T//RtmpIEsh0G/tikzDevice1236577
1d59f1/tikzStringWidthCalc.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-05-11> (/Users/sophiehensgen/Library/TinyTeX/texmf-d
ist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/Users/sophiehensgen/Library/TinyTeX/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2020/04/10 v1.4m Standard LaTeX file (size option)
)
\c@part=\count179
\c@section=\count180
\c@subsection=\count181
\c@subsubsection=\count182
\c@paragraph=\count183
\c@subparagraph=\count184
\c@figure=\count185
\c@table=\count186
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
)

! LaTeX Error: File `tikz.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name: 
! Emergency stop.
<read *> 
         
l.4 ^^M
        
Here is how much of TeX's memory you used:
 223 strings out of 480796
 3020 string characters out of 5903434
 284328 words of memory out of 5000000
 17703 multiletter control sequences out of 15000+600000
 403430 words of font info for 27 fonts, out of 8000000 for 9000
 14 hyphenation exceptions out of 8191
 34i,0n,38p,138b,36s stack positions out of 5000i,500n,10000p,200000b,80000s

!  ==> Fatal error occurred, no output PDF file produced!

我可以通过使用以下命令在正确的位置设置 pdflatex 来解决这个问题。

getOption("tikzLatex")
options("tikzLatex"='/usr/bin/pdflatex')

但是,不,我得到一个全新的错误,我找不到任何帮助。

Error in system(latexCmd, intern = TRUE, ignore.stderr = TRUE) : error in running command

有谁知道我该如何解决这个问题或 tikzDevice 的替代方案?

4

0 回答 0