2

I need to include code in the appendix of my thesis. The code contains comments and the compilation instantly breaks returning:

Unicode char �\lst@FillFixed@ (U+5A8)
(inputenc)                not set up for use with LaTeX.
l.160       if (lastArg < 0, lastArg = 360° 
                                             + lastArg);

This is only one of many characters which produce problems. I cannot change my entire code just because this won't compile. Is there any way to include code with arbitrary unicode characters? Thank you.

Edit: complete sample code, as requested.

\RequirePackage[l2tabu,orthodox]{nag}


\documentclass[headsepline,footsepline,footinclude=false,oneside,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc]{scrbook} % one-sided


\usepackage[toc,page]{appendix}
\usepackage{listings}
\usepackage[utf8]{inputenc}

\lstset{
    inputencoding=utf8,
  extendedchars=true,
  basicstyle=\footnotesize\ttfamily,
  showstringspaces=false,
  showspaces=false,
  numbers=left,
  numberstyle=\footnotesize,
  numbersep=9pt,
  tabsize=2,
  breaklines=true,
  showtabs=false,
  captionpos=b,
    literate={ö}{{\"o}}1 {ä}{{\"a}}1 {ü}{{\"u}}1 
}

\begin{document}

\begin{appendices}
\lstinputlisting{code/power_series.html}
\end{appendices}

\end{document}

Relevant content of power_series.html:

if (lastArg < 0, lastArg = 360° + lastArg);

There really is not much to say about this problem. I only want to be able to use all unicode characters inside a listing. Thank you.

  • 1
    Can you please add a minimal example of code? – egreg Jul 7 '17 at 8:58
  • 1
    Your sample code can not be compiled. Add a full example or do you expect that we complete your snippets to test your problem? – Ulrike Fischer Jul 7 '17 at 9:17
3

Define the Unicode character in the proper way.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listingsutf8}

\protected\def\dg{\ensuremath{^\circ}}
\DeclareUnicodeCharacter{05A8}{\dg}

\lstset{
    inputencoding=utf8,
  extendedchars=true,
  basicstyle=\footnotesize\ttfamily,
  showstringspaces=false,
  showspaces=false,
  numbers=left,
  numberstyle=\footnotesize,
  numbersep=9pt,
  tabsize=2,
  breaklines=true,
  showtabs=false,
  captionpos=b,
  literate={ö}{{\"o}}1 {ä}{{\"a}}1 {ü}{{\"u}}1 {°}{\dg}1
}

\begin{document}

\lstinputlisting{\jobname.html}

\end{document}

The \jobname.html file contains

if (lastArg < 0, lastArg = 360° + lastArg);

Here is the output.

enter image description here

  • thank you for your help. declaring unicode characters this way solves my problem. – Gerry Jul 7 '17 at 9:29

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.