如何解决重音字母的问题?

如何解决重音字母的问题?

我已经使用环境将 MATLAB 代码导入到我的文档中\lstinputlisting,但是出现以下有关重音字母的错误:

package inputenc error: invalid utf-8 byte sequence;
package inputenc error: invalid utf-8 byte "A0;
package inputenc error: invalid utf-8 byte "A8;
package inputenc error: invalid utf-8 byte "A9;

等等...我该如何修复这些错误?

这是main.tex

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\usepackage[hyper]{listings}

\renewcommand{\lstlistingname}{Listato}
\newcommand{\lstInCaption}[1]{\lstinline[basicstyle=\ttfamily\footnotesize]|#1|}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{mydarkgreen}{rgb}{0.03,0.47,0.03}
\definecolor{mydarkblue}{rgb}{0.07,0.08,0.4}
\definecolor{mylightblue}{rgb}{.8, .8, 1}
\definecolor{mylightgray}{rgb}{0.96,0.96,0.96} %original: 0.95,0.95,0.95
\definecolor{mydarkgray}{rgb}{0.35,0.35,0.35}
\definecolor{mylightyellow}{rgb}{0.97,0.91,0.81}
\definecolor{myblue}{rgb}{.4,.4,1}
\definecolor{colKeys}{RGB}{0,0,255}
\definecolor{colIdentifier}{rgb}{0,0,0}
\definecolor{colComments}{RGB}{28,172,0}
\definecolor{colString}{RGB}{170,55,241}

%%%% colori inseriti da G.Donnarumma %%%%%%%%%%%%%%%%%%%
\definecolor{colTitle}{rgb}{0.83529 0.31373 0}
\definecolor{boxgray}{rgb}{0.71,0.71,0.71}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5

%%%% pacchetto per centrare didascalie inserito da G.Donnarumma%
\usepackage[justification=centering]{caption}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% pacchetto per stile e grafica Matlab inserito da G.Donnarumma%
\usepackage[numbered,framed]{matlab-prettifier}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MATLAB as default 
\lstset{%
    float=hbp,%
    language=Matlab,%
    style=Matlab-editor,   %richiede il pacchetto matlab-prettifier (inserito da G.Donnarumma)
    basicstyle=\ttfamily\small, %font size/family/etc.for source \small
    identifierstyle=\color{colIdentifier}, %
    keywordstyle=\color{colKeys},%
    stringstyle=\color{colString},%
    commentstyle=\color{colComments},%
    columns=[l]fixed,% flexible,%
    keepspaces=false,%        sposta la linea di separazione delle sezioni 
    %tabsize=2,%
    frame=single,% single,lines, none
    rulecolor= \color{boxgray},%specify the color of  the frame-box 
    extendedchars=true,%
    showspaces=false,%
    showstringspaces=false,%
    escapechar         = ",      %inserito da G.Donnarumma
    mlshowsectionrules = true,   %inserito da G.Donnarumma
    numbers=left,% left, none    %visualizza num. identificat. linea codice
    numberstyle=\tiny,%
    breaklines=true,     %automatic line-breaking
    lineskip=-2pt,       %
    backgroundcolor=\color{mylightgray}, %
    breakautoindent=true,       %
    numberbychapter=true,       %
    captionpos=false,    %position of caption (t/b)
    belowcaptionskip=0.2\baselineskip%\medskipamount%
}
\lstset{%
   morekeywords={cell,interp3,interpn,fnplt,fneval%
      ,odeset,ode113,ode15s,ode23s,ode23t,ode23tb,cell2mat,%
      convvel,convang,convforce,convlength,deg2rad,atmoscoesa,atmosisa,atmosnonstd,%
      datcomimport,importdata,fieldnames,assignin%
      ,fnval,csaps,fmincon%
      ,classdef,properties,methods%
   }
}
\lstset{%
   emph={myfun,myfunction2x1,f_prandtl_a_b,%
      DSVAircraft,myAC,costLongEquilibriumStaticStickFixed,myNonLinearConstraint,dummyNonLinearConstraint,%
      eqLongDynamicStickFixed,calc_CD0_k_Tmax,MassStickFree,cla,eps,},%
   emphstyle={%
      \color{red!80!black}%
         \ttfamily\bfseries%
   }
}

\lstset{%
    emph=[1]{interp1,pi,norm,sin,cos,disp,ode45,cd,set,get,gca,gradient,length,tan,gamma,sqrt,diag,acos,atan,asin,imag,real,subplot,sound,zeros,interp2,meshgrid,input,sprintf,xlabel,ylabel,plot,print, legend,grid,figure,hold},emphstyle=[1]\color{black}, %some words to emphasise
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

Test

\vskip 0.3cm
\lstinputlisting[caption=Es.1-2 - cinematica manovra looping perfetto,label=lst:es-1-2,firstline=2,lastline=180]{code.m} 

\end{document}

这是文件code.m

%% *DSV_Quaderno 3: Quaternione dell'orientamento di un velivolo*
%% Esercizi 3.1 e 3.2: cinematica e traiettoria dell'evoluzione di _looping perfetto_

clc; clear all; close all;
% Condizioni iniziali

%sull'orientamento
% angoli di Eulero in rad
psi0   = convang(0,'deg','rad'); 
theta0 = convang(0,'deg','rad'); 
phi0   = convang(0,'deg','rad'); 

% in termini di quaternione
Q0 = angle2quat(psi0, theta0, phi0);

% sulla posizione
x0 = 0; y0 = 0; z0 = 0;
Pos0 = [x0; y0; z0];

% Tempi di manovra
% siccome si assegna una q di 1 rad/s per fare 
% un giro completo occorre un tempo pari a 2*pi
ti = 0; tf = 2*pi;

%Componenti della velocità inziale del baricentro in m/s
u0 = convvel(350,'km/h','m/s'); 
v0 = convvel(0,'km/h','m/s'); 
w0 = convvel(0,'km/h','m/s'); 
% Storie temporali delle velocità (funzioni anonime)

%Velocità angolari massime in rad/s
pmax = 0;
qmax = 1.00;
rmax = 0;


test: à, è, é, ù, ò

这些文件已加载到我的 Overleaf 项目中,以下是我使用的某些包:

% packages and related macros

\usepackage[final]{optional}% draft, etc

% Language and encoding
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}

% from guit forum: http://www.guit.sssup.it/phpBB2/viewtopic.php?t=3287
\makeatletter
\addto\extrasitalian{\babel@savevariable\@clubpenalty
  \@clubpenalty3000 }
\makeatother

% Mathematics and related stuff

\usepackage[intlimits]{amsmath}
\usepackage{amsfonts}
\usepackage{amsbsy}
\usepackage{fixmath}
\usepackage{mathtools}

% Fonts and related stuff

\usepackage{relsize}

\usepackage[T1]{fontenc}
\usepackage{pifont} % for dingbats
\usepackage{marvosym} % for \Keyboard etc

%\usepackage{lmodern}
\usepackage{newtxtext}
%\usepackage[osf]{erewhon}% extension of Utopia, osf=old-style-figures
\usepackage[varqu,varl]{inconsolata}% sans typewriter
\usepackage[scaled=.95]{cabin}% sans serif
\usepackage[utopia,vvarbb]{newtxmath}
\usepackage{newtxmath}

\usepackage{textcomp}% AFTER newtxtext to avoid clashes
\usepackage{wasysym}
% font for Aspect Ratio by Claudio Beccari and Agostino De Marco
% the default variant is compatible with lmodern font
\usepackage[TM]{ar}

% Floating objects and related stuff
\usepackage{float}
% I got this somewhere on the net:
\renewcommand{\textfraction}{0.15}
\renewcommand{\topfraction}{0.85}
\renewcommand{\bottomfraction}{0.65}
\renewcommand{\floatpagefraction}{0.60}

\usepackage[above]{placeins}

答案1

我通过包解决了这个问题listingsutf8,然后通过使用设置编码\lstset{inputencoding=utf8/latin1}

相关内容