我的代码无法编译,我该怎么办?问题出在符号$
和%
!
错误日志:关联
\documentclass{report}
\usepackage[brazil]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{listings}
\lstset{%
inputencoding=utf8,
extendedchars=true,
literate=%
{é}{{\'{e}}}1
{è}{{\`{e}}}1
{ê}{{\^{e}}}1
{ë}{{\¨{e}}}1
{É}{{\'{E}}}1
{Ê}{{\^{E}}}1
{û}{{\^{u}}}1
{ù}{{\`{u}}}1
{ú}{{\'{u}}}1
{â}{{\^{a}}}1
{à}{{\`{a}}}1
{á}{{\'{a}}}1
{ã}{{\~{a}}}1
{Á}{{\'{A}}}1
{Â}{{\^{A}}}1
{Ã}{{\~{A}}}1
{ç}{{\c{c}}}1
{Ç}{{\c{C}}}1
{õ}{{\~{o}}}1
{ó}{{\'{o}}}1
{ô}{{\^{o}}}1
{Õ}{{\~{O}}}1
{Ó}{{\'{O}}}1
{Ô}{{\^{O}}}1
{î}{{\^{i}}}1
{Î}{{\^{I}}}1
{í}{{\'{i}}}1
{Í}{{\~{Í}}}1
}
\begin{document}
\chapter{Códigos}
\lipsum[1]
\begin{lstlisting}
#Limpa todos os objetos na memória
rm(list=ls())
#Limpa o console
cat("\014")
set.seed(03052017)
mu1 <- exp(as.numeric(model.matrix(~X) %*% b))
#Vetor de médias 2
mu2 <- exp(as.numeric(model.matrix(~W) %*% g))
########################################################
IMR <- dnorm(fit1$linear.predictors)/pnorm(fit1$linear.predictors)
#Acrescimo de IMR ao dataframe
dt <- data.frame(dt,IMR)
#Modelo lm(regressao multipla)
fit2 <- lm(formula = YO~XO1+XO2+IMR, data = dt[dt$YS==1, ])
#Geração de valores da nova covariável delta
delta <- (dt$IMR)*(dt$IMR+fit1$fitted.values)
#Acrescimo de delta ao dataframe
dt <- data.frame(dt,delta)
#Quantidade de valores u==1
q <- sum(u)
#Calculo da variância
\end{lstlisting}
\end{document}
答案1
如果你仔细查看日志文件,你会发现日志会告诉你每个已加载包的位置。在你的情况下,有两个包与以下内容相关listings
:
("C:\Program Files\MiKTeX 2.9\tex\latex\listings\lstmisc.sty"
File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz)
加载此文件会产生以下明显的错误:
***
*** This file requires `listings.sty' version 1.6.
*** You have a serious problem, so I'm exiting ...
***
如果您回顾listings
日志文件中的加载位置,您将看到:
(listings.sty
Package: listings 2002/04/01 1.0 (Carsten Heinz)
请注意,它没有 MikTeX 发行版的完整文件路径(即缺少"C:\Program Files\MiKTeX 2.9\tex\latex\listings
)。这表明listings
正在加载的本地副本,而且是非常旧的副本。从文档文件夹中删除该副本(以及发行版中应包含的任何其他本地样式文件),文档应该可以正确编译。