包 inputenc 错误:无效的 UTF-8 字节序列

包 inputenc 错误:无效的 UTF-8 字节序列

我正在编写一份包含多个导入代码的报告(我正在使用listing包),当编译器开始解析其中一个导入的代码文本时,我发现标题中的错误。查看日志文件,我发现了以下几行:

The document does not appear to be in UTF-8 encoding.
Try adding \UseRawInputEncoding as the first line of the file
or specify an encoding such as \usepackage [latin1]{inputenc}
in the document preamble.
Alternatively, save the file in UTF-8 using your editor or another tool

\UseRawInputEncoding按照我在 latex 文件开头添加的这些说明。然后我检查了导入文件的编码类型,因为其他文件都是 UTF-8,但没有任何效果。任何建议都将不胜感激:)

我的乳胶序言:

\UseRawInputEncoding
%PREAMBOLO
\documentclass[a4paper,11pt]{report}

\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}

\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{textcomp}
\usepackage{enumerate}
\usepackage{xcolor}
\usepackage{listingsutf8}

\definecolor{codegreen}{RGB}{42, 184, 42}
\definecolor{codeblue}{RGB}{48, 48, 255}
\definecolor{codered}{RGB}{223, 15, 15}
\definecolor{codeyellownum}{RGB}{183, 183, 38}
\definecolor{codeyellowstring}{RGB}{251, 191, 71}
\definecolor{backcolour}{RGB}{236, 239, 244}

\lstdefinestyle{global}{
    language=Octave,
    inputencoding=utf8,
    extendedchars=true,
    backgroundcolor={\color{backcolour}},
    commentstyle={\color{codegreen}},
    keywordstyle={\color{codeblue}},
    keywordstyle=[2]{\color{codered}},
    otherkeywords={;,+,-,*,/,.,=,++,(,),[,],=+,=-},
    morekeywords=[2]{;,+,-,*,/,.,=,++,(,),[,],=+,=-},
    numberstyle=\tiny\color{black},
    stringstyle=\color{codeyellowstring},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    numbers=left,
    numbersep=5pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2,
    literate={à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1,
}

\lstset{style=global}

\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{subfig}
\usepackage{float}
\usepackage{geometry}
\geometry{
a4paper,
left=25mm,
right=15mm,
top=25mm,
bottom=25mm
}

\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{xfrac}
\usepackage{stmaryrd}
\usepackage{enumitem}
\usepackage[all]{xy}

% Cambiare impostazioni di pagina
\setlength{\parindent}{0cm} % Lunghezza indentazione

% Dichiarazione nuovi comandi
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\restr}[2]{\left.#1\right|_{#2}}
\newcommand{\ds}{\displaystyle}
% ALGEBRA
\newcommand{\acts}{\rotatebox[origin=c]{-170}{$\circlearrowright$}}
%
%

% Dichiarazioni nuovi ambienti
\newtheorem*{deff}{\normalfont\scshape Definizione}
\newtheorem*{thm}{\normalfont\scshape Teorema}
\newtheorem*{prop}{\normalfont\scshape Proposizione}
\newtheorem*{lemma}{\normalfont\scshape Lemma}
\newtheorem*{cor}{\normalfont\scshape Corollario}
\newtheorem*{oss}{\normalfont\scshape Osservazione}
\newtheorem*{example}{\normalfont\scshape Esempio}
\newtheorem*{exe}{\normalfont\scshape Esercizio}

答案1

我发现当我将操作系统更新到 Monterey 时也遇到了同样的问题。(我的 MacBook 实际上已经更新了大约 7 代……其中包括新的操作系统) 我发现问题在于我的文件中有许多“-”和“-”以及类似的非标准字符。 (长破折号与仅一条破折号...我正在将草稿书从 MS Word 移至 LaTex。Word 会自动添加长破折号。)当我删除它们时,问题就解决了。

相关内容