- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将包含地理绘图的 rmarkdown
文档编译成 PDF 文件。这是一个 MWE:
---
title: "Problems with maps in tikz"
output: pdf_document
---
```{r setup, include=FALSE}
library(ggplot2)
library(sf)
```
## sf:png
Builds find when `nctikz` chunk is excluded.
```{r nc}
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) +
geom_sf(aes(fill = AREA))
```
## sf:tikz
This graphic fails to build.
```{r nctikz, dev = 'tikz'}
ggplot(nc) +
geom_sf(aes(fill = AREA))
```
我正在使用 RStudio 中的“Knit”按钮编译此文档。我将讨论我在编译文档时收到的每个错误/警告,以防一个导致另一个。
每次我尝试运行包含 dev = 'tikz'
的 block 时,tinytex
都会尝试重新安装 pgf
TeX 包,然后发现它已经存在,然后放弃尝试链接它。但是,我能够使用非地理 tikz
输出构建文档,所以我基本上只是接受了这个事实。
tlmgr search --file --global '/tikzlibrarytopaths.code.tex'
Trying to automatically install missing LaTeX packages...
tlmgr install pgf
tlmgr: package repository http://mirror.utexas.edu/ctan/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr install: package already present: pgf
tlmgr path add
add_link_dir_dir: /usr/local/share/info/dir exists; not making symlink.
Tikz(在 knitr 中)似乎无法将度数符号作为 tex 文件的一部分进行处理。请注意,nctikz-1.tex
对象可以由 pdflatex
毫无问题地构建。
! Package inputenc Error: Invalid UTF-8 byte "B0.
Quitting from lines 24-27 (test.Rmd)
Error: Failed to compile test_files/figure-latex/nctikz-1.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See nctikz-1.log for more info.
我可以通过在我的绘图上抑制轴标题 theme(axis.text = element_blank())
来解决无效字符错误,但这会引入另一个处理引入文件的错误。
! Missing $ inserted.
<inserted text>
$
l.3975 ...72.27pt,interpolate=true]{nctikz-1_ras1}
};
Quitting from lines 24-27 (test.Rmd)
产生这个错误的完整行是
\node[inner sep=0pt,outer sep=0pt,anchor=south west,rotate= 0.00] at (423.16, 120.24) {
\pgfimage[width= 14.45pt,height= 72.27pt,interpolate=true]{nctikz-1_ras1}};
它试图引用的图像几乎不是图像(我认为它是为了图例)。
我在 MacOS 上用一大堆库构建这个文档。为了隔离问题,我还尝试在一个全新的项目中在 Rstudio.cloud (Ubuntu) 上构建文档。在此环境中,只会出现数学环境/下划线的问题。
! Missing $ inserted.
<inserted text>
$
l.4049 ...72.27pt,interpolate=true]{nctikz-1_ras1}
};
Quitting from lines 26-28 (test.Rmd)
Error: Failed to compile test_files/figure-latex/nctikz-1.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See nctikz-1.log for more info.
最佳答案
不是一个完整的答案,但我想记录下我目前的状态:
通过添加启用调试是有意义的
```{r, include=FALSE}
options(tinytex.verbose = TRUE)
```
到 Rmd
文件 as suggested .
pgf 问题有点像转移注意力。通过调试,我们看到它是在发生其他错误(文件路径中的非法字符或下划线)之后发生的。对应的正则表达式为recently introduced并且可能应该被扩展以检查来自 Tikz/pgf 的实际错误消息。
我可以在 Debian Linux 上重现非法字符。 °
以某种方式写为 0xB0
,即 Latin-1 编码而不是 UTF-8。我不确定为什么/在哪里发生这种情况。顺便说一句,我可以直接使用来自 RStudio 的 pdflatex
处理生成的 tex
文件,因为它重新编码了 0xB0
作为问号。如果我通过 Emacs 或直接在命令行上使用 pdflatex
,我会收到相同的错误消息。
通过以下方式从输出中删除度数符号
```{r nctikz, dev = 'tikz'}
ggplot(nc) +
theme(axis.text = element_blank()) +
geom_sf(aes(fill = AREA))
```
我可以重现“文件路径中的下划线”问题。打开调试后,可以看到问题又出在其他地方:
Package pgf Warning: File "nctikz-1_ras1" not found when defining image "pgflas
timage". Tried all extensions in ".pdf:.jpg:.jpeg:.png:" on input line 3975.
! Missing $ inserted.
<inserted text>
$
l.3975 ...72.27pt,interpolate=true]{nctikz-1_ras1}
};
! ==> Fatal error occurred, no output PDF file produced!
未找到与 nctikz-1.tex
位于同一目录中的文件 nctikz-1_ras1.png
。可以直接使用重现此问题
tinytex::latexmk("<path>/nctikz-1.tex", install_packages = FALSE, clean = FALSE)
但是,如果先更改目录,则不会出现这样的错误:
setwd("<path>")
tinytex::latexmk("./nctikz-1.tex", install_packages = FALSE, clean = FALSE)
关于r-markdown - 如何解决涉及 tikz 设备的 rmarkdown to latex 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58401825/
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我有一个在 ab 时间内运行的算法,其中 a 和 b 都是单独的输入。 我的算法还是多项式时间复杂度算法还是nn?我认为 nn 不是多项式,但我仍然不确定。 我看到 n 算法的阶乘仍然评估为 nn 复
这个问题在这里已经有了答案: Logical operators (AND, OR) with NA, TRUE and FALSE (2 个回答) 1年前关闭。 由于“is.na(NA)”返回真,“
假设我有一个具有以下结构的 Pandas 数据框: df = pd.DataFrame(dict(a=["x", "x", "y"], b=[0, 1, 1], c=[1, 2, 2])) 我想按 a
谁能帮我处理一些相当复杂的 Django 查询? 这些是我的模型: class County(models.Model): name = models.CharField(max_length
我想从某个表中选择一行并根据另一个表对结果进行排序。 这是我的表: lang1_words: word_id - word statuses: word_id - status 在每个表中 word_
我是单元测试的新手,所以请对我宽容一些。我有一些查询 RESTful API 的模块。我发现在每个测试套件中,我都使用几行代码来启动一个简单的 ExpressJS Web 服务器,以模拟一些我可以从测
假设我有以下代码: var blinker = function(element){ if(stopped){ return; } else { var sampleMappi
我正在用 JavaScript 制作一个选择你自己的冒险风格的游戏,在本节中: evade = prompt("Go out of your way to avoid them, just in ca
我的代码: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Events1 extends
我正在使用 scipy ode 来解决钟摆问题。 from scipy import * import matplotlib.pyplot as plt from scipy.integrate im
我有一个 Google 表格,用于收集客户的注册数据。收集的数据包括学生的姓名、学生选择参加的类(class)以及信用卡号。提交后,我会收到通知。收到通知后,我会转到我的 Google 表格并从信用卡
我需要定义一个操作的两个版本,定义略有不同。它是一系列包含Nat指数的成分。 open import Data.Nat data Hom : ℕ → ℕ → Set where id : (
我正在研究游戏引擎 http://ducttape-dev.org使用 boost 作为依赖项之一。有一天,当我正在编写一个链接到我的游戏引擎的测试应用程序时,OgreProcedural 的 Ext
我正在 Android 中制作一个表达式计算器,所以我想在实际计算答案之前检查字符串是否符合有效表达式的条件。 我在 Java 中试过这个正则表达式: ^\s*([-+]?)(\d+)(?:\s*([
我有以下 postgresql 查询(为便于阅读而简化): select * from a_view where a in (select * from a_function(a_input))
我开始更好地掌握 PostgreSQL 索引,但我遇到了 OR 条件的问题,我不知道如何优化我的索引以加快查询速度。 我有 6 个条件,当单独运行时,它们的成本似乎很小。下面是修剪查询的示例,包括查询
有谁知道为什么下面的代码接受诸如123-123-1234这样的答案: [1-9]\\d{2}-[1-9]\\d{2}-\\d{4} 我想到了代码,它只接受先接受 2 个数字,再接受 2 个数字,然后再
在使用 Java 1.8u40 打开带有提示类型和附加的 StringConverter 的组合框时,我遇到了以下错误。这可以追溯到执行 FXML 的团队留下的示例字符串,与 Controller 中
在 MySQL 中,我有三个不同的数据库 - 我们将它们称为 A、B 和 C。 是否可以执行涉及所有三个数据库(A、B、C)中的表的事务? (所有数据库都在同一服务器上) 最佳答案 是的,你可以。这是
我是一名优秀的程序员,十分优秀!