为什么 LaTeX 在 RMarkdown 中编译失败

问题描述 投票:0回答:2

我的代码应该很容易编写成 pdf,但它无法编译,我在 R Markdown 中收到此消息:

! LaTeX 错误:Unicode 字符 ₁ (U+2081) 未设置与 LaTeX 一起使用。

错误:LaTeX 无法编译 L-work-5.tex。请参阅 https://yihui.org/tinytex/r/#debugging 了解调试技巧。有关详细信息,请参阅 L-work-5.log。 执行停止

这是代码:


---
title: "work 5"
author: "PLars"
date: "4/2/2022"
output: pdf_document

fonttheme: professionalfonts
fontsize: 12pt
editor_options:
  markdown:
    wrap: 72
---

```{r, echo = FALSE, results = "hide", message = FALSE, purl = FALSE}
library(knitr)


opts_chunk$set(tidy = FALSE,
               fig.align = "left",
               background = '#a6a6a6',
               fig.width = 10,
               fig.height = 10,
               out.width ="\\linewidth",
               out.height = "\\linewidth",
               message = FALSE,
               warning = FALSE,
               fig.align = "left"
               )

options(width = 55, digits = 3)
library(scales)
percent <- function(x, digits = 2, format = "f", ...) {
  paste0(formatC(100 * x, format = format, digits = digits, ...), "%")
}
library(haven)
library(tinytex)
library(stargazer)
library(tidyverse)
library(texreg)
library(dplyr)
library(texreg)
library(AER)
library(tidyverse)
```

**Part I - Categorical Models (5 points)**

Say that you estimate an ordered logit model with a three category
dependent variable and two independent variables, X~₁i~ and X~₂i~, and
obtain the following results:

```{=tex}
\begin{center}
\begin{tabular}{c|rc}
\hline \hline
& $\hat{\beta}$ & SE \\
\hline
$X_{1}$ & $-0.68$  & $(0.23)$    \\
$X_{2}$ &  $-0.47$  & $(0.13)$  \\
\hline
$\tau_1$    & $-1.02$ & $(0.46)$ \\
$\tau_2$    & $.85$  & $(0.21)$ \\
\hline
\end{tabular}
\end{center}
```
```{=tex}
\begin{enumerate}

\item  Calculate $\Pr(Y_i=1 | X_{1i}=1, X_{2i}=0)$.

\item  Calculate $\Pr(Y_i=2 | X_{1i}=1, X_{2i}=0)$.

\item  Calculate $\Pr(Y_i=3 | X_{1i}=1, X_{2i}=0)$.

\item Calculate the first difference (difference in probability in category) that result from changing X_{2i} from -2 to 2, holding X_{1i} fixed at 0. Do calculations for each possible value of Y_i.

\item Explain how we might assess whether the parallel regression assumption holds for this model? If it does not, what alternative might you pursue if this were your model?

\end{enumerate}
```
# 

First, we calculate $X_i \beta$

```{r}
(xiB <- (-.068*1) + (-0.47*0)) 
```

Then, plug into the following equations:

```{r}
(prob1 <- 1/(1 + exp(-(-1.02-xiB))))

(prob2 <- 1/(1 + exp(-(.85-xiB))) - prob1)

(prob3 <- 1 - (1/(1 + exp(-(.85-xiB)))))

prob1 + prob2 + prob3
```
r latex r-markdown
2个回答
4
投票

首先,尝试删除行中的特殊字符

两个自变量,X~₁i~ 和 X~2i~

这将让你编译。

可能可以通过包含类似的内容来使其发挥作用

\newunicodechar{₁}{\ensuremath{{}_1}}

同样对于 subscript-2 字符,位于文件顶部(来自 这个 TeX Stack Exchange 问题),但我还没有测试过它,现在不想进入那个兔子洞......

或者只是将相关文字更改为

two independent variables, $X_{1i}$ and $X_{2i}$

这可能会按照最初的预期排版!


0
投票

这看起来很像我在使用库(tidyverse)时遇到的错误。它是否可以通过删除library(tidyverse)并定义tidyverse中使用的包来工作,例如library(tidyr)、library(dplyr)等?

© www.soinside.com 2019 - 2024. All rights reserved.