3

I have the following code:

\documentclass{article}

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

\title{DuvidaLatex}
\author{Ricardo Ramos}
\date{October 2017}

\begin{document}

 \begin{lstlisting}[caption={Testes de CRUD - Abordagem},label=testesgrupoA, language=Java]

    public class UniversidadesSystemTest{

        @Test
        @Carga(classe = UniversidadeCarga.class)
        public void adicionarUmaUniversidade() {
            UsuarioEm(AplicacaoPage.class).deve().acessarMenu("Universidades>Nova Universidade");
            UsuarioEm(IncluirUniversidadePage.class).deve().informarNome("Universidade Paulista").informarCidade("Sao Paulo - SP").informarEndereco("Rua Jardim Cris, nº 40, Santo Amaro")
                    .informarCEP("13572-000").salvar();
            UsuarioEm(ListarUniversidadesPage.class).deve().verificarQueUniversidadeComNomeECidade("Universidade Paulista", "Sao Paulo - SP").existe();
        }   

    }
    \end{lstlisting}

\end{document}

But when I compile my code the following message appears in the nº40 character:

Package inputenc error: Unicode char \expandafter
Package inputenc Error: Keyboard character used is undefined
2

Degree symbol

This example shows the use of the degree symbol in the text and also in the lstlisting environment.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\RequirePackage[top=2.5cm,bottom=2.5cm,left=0.5cm,right=0.5cm,headsep=15pt,footskip=27pt,a4paper]{geometry}
\usepackage{listings}
%----------------------------------------
\usepackage{listingsutf8}
\usepackage{textcomp}
\usepackage{inconsolata}
%-----
\usepackage{gensymb}
\DeclareUnicodeCharacter{00B0}{\degree}
%-----
\usepackage{color}
\definecolor{azzul}{RGB}{6,96,167}
\definecolor{grverd}{rgb}{.133,.545,.133}
\definecolor{ruddy}{rgb}{1.0, 0.0,0.16}
\definecolor{gray(x11gray)}{rgb}{0.75,0.75, 0.75}
%-----
\lstdefinestyle{sycodjava}{%
    language=Java,
    showspaces=false,
    showtabs=false,
    breaklines=true,
    showstringspaces=false,
    breakatwhitespace=true,
    commentstyle=\color{grverd},
    keywordstyle=\color{azzul},
    stringstyle=\color{ruddy},
    basicstyle=\ttfamily,
    inputencoding=utf8/latin1,
    inputencoding=utf8,
    extendedchars=true,
    literate={á}{{\'a}}1 {ã}{{\~a}}1 {é}{{\'e}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1
    {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1%
    {°}{\textdegree}1,
    moredelim=[il][\textcolor{gray(x11gray)}]{$$},
    moredelim=[is][\textcolor{gray(x11gray)}]{\%\%}{\%\%}
    framexleftmargin=1mm,
    xleftmargin=2mm,
    numbers=none,
    columns=fullflexible,
    }
%----------------------------------------
\title{DuvidaLatex}
\author{Ricardo Ramos}
\date{October 2017}

\begin{document}
\section{Degree symbol}
Degree symbol in plain text still works: 90° is a right angle.

\begin{lstlisting}[style=sycodjava,caption={Testes de CRUD - Abordagem},label=testesgrupoA]
public class UniversidadesSystemTest{

    @Test
    @Carga(classe = UniversidadeCarga.class)
    public void adicionarUmaUniversidade() {
        UsuarioEm(AplicacaoPage.class).deve().acessarMenu("Universidades>Nova Universidade");
        UsuarioEm(IncluirUniversidadePage.class).deve().informarNome("Universidade Paulista").informarCidade("Sao Paulo - SP").informarEndereco("Rua Jardim Cris, n° 40, Santo Amaro")
                .informarCEP("13572-000").salvar();
        UsuarioEm(ListarUniversidadesPage.class).deve().verificarQueUniversidadeComNomeECidade("Universidade Paulista", "Sao Paulo - SP").existe();
    }
}
\end{lstlisting}

\end{document}

Result: Degree symbol in java code

3

If you are using UTF-8 extended characters in a listing, you must place within an escape to LaTeX.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{listingsutf8}

\title{DuvidaLatex}
\author{Ricardo Ramos}
\date{October 2017}

\lstset{language=Java,
    label=testesgrupoA,
    caption={Testes de CRUD - Abordagem},
    escapeinside={\%*}{*)},
    breaklines=true,
    inputencoding=utf8,
    extendedchars=true
}

\begin{document}
\begin{lstlisting}
public class UniversidadesSystemTest{
    @Test
    @Carga(classe = UniversidadeCarga.class)
    public void adicionarUmaUniversidade() {
        UsuarioEm(AplicacaoPage.class).deve().acessarMenu("Universidades>Nova Universidade");
        UsuarioEm(IncluirUniversidadePage.class).deve().informarNome("Universidade Paulista").informarCidade("Sao Paulo - SP").informarEndereco("Rua Jardim Cris, %*nº*) 40, Santo Amaro")
                .informarCEP("13572-000").salvar();
        UsuarioEm(ListarUniversidadesPage.class).deve().verificarQueUniversidadeComNomeECidade("Universidade Paulista", "Sao Paulo - SP").existe();
    }   

}
\end{lstlisting}
\end{document}
2

Write the next code into the preamble:

\usepackage{textcomp}
\lstset{breaklines,literate={º}{{\hspace{-.2em}\scriptsize\textordmasculine}}1}

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.