I'm using TeXstudio and pdfLaTeX. I'm trying to use the listings package to add some Matlab source code to my document. However, I'm having trouble with some portuguese letters used in the code (graphics captions, actually).
The common answer to this known encoding problem is shown here and here. However, even after adding the \lstset{literate=} with the correct list, the problem persists. I verified that the problematic letters and indeed in the list to be substituted, but no change.
The \lstset and the \lstinputlisting[language=Matlab]{estrutura/dados/algoritmos/main.m} I'm calling to add the code are in different files, but that was not a problem for any other package. I also verified that I can include code without any special characters.
What could be causing this problem and what would be a fix or an workaround?
Thanks for any help
EDIT for sample code: This part is the one being used to substitute letters in the listings.
\lstset{language=Matlab}
\lstset{
inputencoding=utf8,
extendedchars=true,
literate=
{á}{{\'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 {ű}{{\H{u}}}1
{Ű}{{\H{U}}}1 {ő}{{\H{o}}}1 {Ő}{{\H{O}}}1
{ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1
{å}{{\r a}}1 {Å}{{\r A}}1 {£}{{\pounds}}1
{«}{{\guillemotleft}}1 {»}{{\guillemotright}}1
{ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?`}}1
}
This is the line calling listing of the source code
\lstinputlisting[language=Matlab]{estrutura/dados/algoritmos/plot_bf_compare_in_out.m}
Specifically, the section of Matlab code throwing the error is
title("Comparação entre áudio antes e depois do beamformer");
EDIT 2: Since the complete text I am working is spread across multriple files and folders, I recreated the minimum document with everything that seems relevant to this problem and throws the same error. OneDrive download link here with the files.
EDIT 3: Compilable LaTeX code
\documentclass[%twoside, % Impressão em frente e verso
oneside, % Impressão apenas frente
]{utfpr-abntex2}
\usepackage{nicefrac}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{nicefrac}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{color, colortbl}
\usepackage{float}
\usepackage{graphicx}
\usepackage{icomma}
\usepackage{indentfirst}
\usepackage{microtype}
\usepackage{multirow, array}
\usepackage{subeqnarray}
\usepackage{lastpage}
\usepackage{pdfpages}
\usepackage{verbatim}
\usepackage{amsfonts, amssymb, amsmath}
\usepackage[algoruled, portuguese]{algorithm2e}
\usepackage{times}
\usepackage[bottom]{footmisc}
\usepackage{ae, aecompl}
\usepackage{latexsym}
\usepackage{lscape}
\usepackage{picinpar}
\usepackage{scalefnt}
\usepackage{upgreek}
\usepackage{listings}
% Parte utilizada para que códigos fonte possam conter caracteres em português
\lstset{language=Matlab}
\lstset{
inputencoding=utf8,
extendedchars=true,
literate=
{á}{{\'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 {ű}{{\H{u}}}1
{Ű}{{\H{U}}}1 {ő}{{\H{o}}}1 {Ő}{{\H{O}}}1
{ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1
{å}{{\r a}}1 {Å}{{\r A}}1 {£}{{\pounds}}1
{ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?`}}1
}
\begin{document}
\lstinputlisting[language=Matlab]{plot_bf_compare_in_out.m}
\end{document}
Sample of problematic source code file (.m):
figure;
title("Comparação entre áudio antes e depois do beamformer");
\documentclass{...}and ends with\end{document}. And we can't see your actual\lstinputlistingfile, so please include some of it directly in the document or add a small sample file to the question too. – Alan Munn Nov 24 '18 at 19:19\lstinputlisting[language=Matlab]{estrutura/dados/algoritmos/plot_bf_compare_in_out.m}that calls to source code file and the linetitle("Comparação entre áudio antes e depois do beamformer");in the source code itself, with the character that causes the error. – L. Farinha Nov 24 '18 at 21:32\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}twice (is this really a "template"?). These packages wouldn't be needed if you usexelatex. Besides, there are many reasons to use LaTeX and not using that template without any modifications. – Nov 30 '18 at 08:40