0

I am trying to put a Verilog code listing in my document, but it returns a Latex error when processing the comment lines, here is the MWE:

\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[spanish]{babel}
\usepackage{listings}
\renewcommand{\lstlistingname}{Listado}

\begin{lstlisting}[language=Verilog]
/*Descripción estructural de un multiplexor 2 a 1*/

//interfaz I/O del módulo
module mux(f,a,b,sel);

\end{lstlisting}

These are the compiling errors I get:

! LaTeX Error Invalid UTF-8 byte "B3. ! LaTeX Error

! LaTeX Error Invalid UTF-8 byte sequence (�\expandafter)

If I erase the lines of comments the document compiles fine. After some research, I have used \UseRawInputEncoding command as suggested here: Package inputenc Error: Invalid UTF-8 byte 147 but when I do it my environment does not process the accented letters, so I need to put the literal command \'{a}. Given that I have 50+ pages in the document, seems like a chore to hunt down every accent in it, is there a more efficient way to do this? (addendum: the encoding command \usepackage[utf8]{inputenc} doesn't work either)

2 Answers 2

3

Use the literate option to make the non-ascii-chars safe inside listings:

\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[spanish]{babel}
\usepackage{listings}
\renewcommand{\lstlistingname}{Listado}
\begin{document}
\begin{lstlisting}[language=Verilog,literate={ó}{{\'{o}}}1]
/*Descripción estructural de un multiplexor 2 a 1*/

//interfaz I/O del módulo
module mux(f,a,b,sel);

\end{lstlisting}
\end{document}
0

I ran into the same problem and was able to bypass it by using luatex instead of xetex.

1
  • The answer may be short, but that's really all to say here.
    – MS-SPO
    Commented Jun 9, 2023 at 17:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .