4

If I compile the next code the following error appear.

! Package inputenc Error: Unicode char \u8:�\expandafter\lst@FillFixed@\fi not set up for use with LaTeX.

See the inputenc package documentation for explanation. Type H for immediate help. ...

l.6 ...%% sI A tiene inversa esta es la soluci�n( Vector Nulo) ?

Then when I comment "\usepackage[utf8]{inputenc}" the code compile, but I need the utf8 package. How could I fix it?

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pgf,tikz}

\usetikzlibrary{arrows}
\usepackage{float}
\usepackage{verbatim}




\usepackage{listings}



\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}

\usepackage{hyperref}
\usepackage{txfonts,pxfonts}


\begin{document}    



\section*{Matlab Code}
\begin{lstlisting}
clc, clear
syms k1 k2 y m
A= [0 1 0 1;-1*(k1+k2)/m 0 k2/m 0; 0 0 0 1; k2/m 0 0 -(k1+k2)/m];
cero=zeros(4);  
determinante=det(A); %% Determinante de A
Sol=A\cero;%% sI A tiene inversa  esta es la solución(Vector Nulo)
% El unico punto de equilibrio es el punto 0
detervalprop= det(A-y*eye(4))
[V,D]=eig(A)
f=subs(D(1),m,1)
%figure
%ezsurf(f)
%figure
%subplot(2,1,2)
h=ezplot(f)
set(h, 'Color', 'r')
\end{lstlisting}



\end{document}
  • Did you read the manual for listingsutf8? It can only help in a very certain case. I generally recommend our users to document in English to avoid this. You can get by by using the literal trick this is documented elsewhere on the site (there should be enough questions about listings vs uft8) – daleif May 31 '16 at 17:43
  • If you had read the manual you would know that listingsutf8 only helps on \lstinputlisting it cannot help on the use of the lstlisting env like you use here. – daleif May 31 '16 at 17:58
  • @daleif I havent found the "enough" questions that you are talking about, I have just find one, and is this one "tex.stackexchange.com/questions/110020/utf8-for-listings";, but this have'nt answer my specific problem. If I get well your message, are you saing that my answer is in the manual of "listingsutf8"? – JuanMuñoz May 31 '16 at 17:58
  • Here is one: tex.stackexchange.com/a/24532/3929, the option is literate, there are many more questions and answers if you google "listings utf8" – daleif May 31 '16 at 18:01
  • Yes @daleif you are right , I haven't found an answer reading all this documentation that is why Im posting, could you send me a code please, where I can see what I have to modify?. – JuanMuñoz May 31 '16 at 18:06
1

If you can accept to escape to LaTeX for accented characters.

From page 15 in listings manual:

Similarly, if you are using UTF-8 extended characters in a listing, they must be placed within an escape to LaTeX.

Note: I've commented mcode because MikTeX didn't find it.

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usepackage{float}
\usepackage{verbatim}

\usepackage{listings}

%\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}

\usepackage{hyperref}
\usepackage{txfonts,pxfonts}


\begin{document}    

\section*{Matlab Code}

\begin{lstlisting}[escapechar=&]
clc, clear
syms k1 k2 y m
A= [0 1 0 1;-1*(k1+k2)/m 0 k2/m 0; 0 0 0 1; k2/m 0 0 -(k1+k2)/m];
cero=zeros(4);  
determinante=det(A); %% Determinante de A
Sol=A\cero;%% si A tiene inversa  esta es la soluci&ó&n (Vector Nulo)
% El &ú&nico punto de equilibrio es el punto 0
detervalprop= det(A-y*eye(4))
[V,D]=eig(A)
f=subs(D(1),m,1)
%figure
%ezsurf(f)
%figure
%subplot(2,1,2)
h=ezplot(f)
set(h, 'Color', 'r')
\end{lstlisting}

\end{document}

enter image description here

2

What I usually have in my lstlisting setup is:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{listings}

\lstset{
    inputencoding = utf8,  % Input encoding
    extendedchars = true,  % Extended ASCII
    texcl         = true,  % Activate LaTeX commands in comments
    mathescape    = true   % Mathematical expressions between $
    captionpos    = b,     % Caption position
    literate      =        % Support additional characters
      {á}{{\'a}}1  {é}{{\'e}}1  {í}{{\'i}}1 {ó}{{\'o}}1  {ú}{{\'u}}1
      {Á}{{\'A}}1  {É}{{\'E}}1  {Í}{{\'I}}1 {Ó}{{\'O}}1  {Ú}{{\'U}}1
      {à}{{\`a}}1  {è}{{\`e}}1  {ì}{{\`i}}1 {ò}{{\`o}}1  {ù}{{\`u}}1
      {À}{{\`A}}1  {È}{{\'E}}1  {Ì}{{\`I}}1 {Ò}{{\`O}}1  {Ù}{{\`U}}1
      {ä}{{\"a}}1  {ë}{{\"e}}1  {ï}{{\"i}}1 {ö}{{\"o}}1  {ü}{{\"u}}1
      {Ä}{{\"A}}1  {Ë}{{\"E}}1  {Ï}{{\"I}}1 {Ö}{{\"O}}1  {Ü}{{\"U}}1
      {â}{{\^a}}1  {ê}{{\^e}}1  {î}{{\^i}}1 {ô}{{\^o}}1  {û}{{\^u}}1
      {Â}{{\^A}}1  {Ê}{{\^E}}1  {Î}{{\^I}}1 {Ô}{{\^O}}1  {Û}{{\^U}}1
      {œ}{{\oe}}1  {Œ}{{\OE}}1  {æ}{{\ae}}1 {Æ}{{\AE}}1  {ß}{{\ss}}1
      {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1  {å}{{\r a}}1 {Å}{{\r A}}1
      {ñ}{{\~n}}1  {Ñ}{{\~N}}1  {¿}{{?`}}1  {¡}{{!`}}1
      % ¿ and ¡ are not correctly displayed if inconsolata font is used
      % together with the lstlisting environment. Consider typing code in
      % external files and using \lstinputlisting to display them instead.      
  }

\begin{document}

\begin{lstlisting}[language=C]
/* 
    comentarios en español
    código base
*/
a = a + 1
\end{lstlisting}


\end{document}

...and it works quite well for Spanish and Italian and a handful of other latin scripts.

enter image description here

  • The thing is that if I eliminate de package UTF8, all my code compile find, and even the listing appear how i wanted, it is in the elegant format that Matlab have. Your answer looks finds, but it is not weird to write all those symbols in a Tex? – JuanMuñoz Jun 13 '16 at 5:29
  • I really do not understand the comment, sorry. You can copy that lstset and put it in a style file --- the matter is that lstlisting, by default, is not set-up to work with characters that are not ASCII in the inline environment. This snippet will solve this. Using \lstinputlisting should work out of the box... – Rmano Jun 13 '16 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.