# lstinline has Invalid UTF-8 byte 167

Possible duplicate of this question

MWE:

\documentclass[%
parskip=full,% empty line after each paragraph.
twoside=false% not a 2-sided print for a book.
]{scrbook}

% \usepackage[utf8]{inputenc} % For non-English languages
\usepackage[latin1]{inputenc} % listings needs this encoding instead!

\usepackage{listings, tcolorbox}

\usepackage{tcolorbox}
\tcbuselibrary{listings,skins,theorems,xparse}
\NewTotalTCBox{\inlinebox}{ O{white} v}
{ tcbox raise base,
arc=2pt,
nobeforeafter,% makes the box inline
colback=#1!10!white,% pales given color for background
boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt,
boxrule=0pt}
{\lstinline[style=tcblatex,texcsstyle=*\color{blue}\bfseries]§#2§}
\newcommand\cil{\inlinebox[green]}

\begin{document}

\cil|\TeX| (\TeX) is a control word because it is made up of letters. Any non-letter will end the sequence.

\end{document}


This all works if I do \UseRawInputEncoding, as per this answer.

Should I do that? Or is there something more correct that I should do?

\usepackage[latin1]{inputenc} also works, by the way.

• How can it work? That's not a complete document anybody could compile, but just a fragment. Please complete it.
– cfr
Jun 7 '18 at 0:14
• No. You should declare the input encoding you're using, as David's answer says.
– cfr
Jun 7 '18 at 0:15

The problematic part is:

\lstinline[...]§#2§


The character § is not an ASCII character.

## 8-bit TeX engines (TeX, pdfTeX)

Since package listings does not support multi-byte encodings, the text encoding is limited to an 8-bit encoding as latin1. This encoding should then be declared by

\usepackage[latin1]{inputenc}


For greater portability, I recommend to use a different fence character from the ASCII range (|, &, ...). This avoids problems, when the input file encoding is changed to UTF-8.

## Unicode engines (LuaTeX, XeTeX)

Here, the character § is just one character (big char) and it can be used as fence character for \lstinline of package listings.

However, the best supported input encoding for LuaTeX or XeTeX is UTF-8. Therefore, the input file should be re-encoded from Latin-1 to UTF-8.

• Which UTF-8 fence character do you recommend? Should I use the minted package instead if I need UTF-8 support?
– user152148
Jun 10 '18 at 1:51
• @JonWong It depends on the characters used inside the verbatim text. If | is free, then it looks nice in the source code. Jun 10 '18 at 6:37