I have an external JSON-File that contains the character Δ. A document can be built but I get the error: LaTeX Error: Invalid UTF-8 byte sequence (�\lst@FillFixed@).
As it's external I am using:
\lstinputlisting[language=json,firstnumber=1]{content/future/json/Vertices.json}
It is shown and formatted. However the Deltas are not there. Just shown as empty brackets.
As suggested here I tried adding \UseRawInputEncoding - the brackets are not empty any more, now they are filled with: "ΡT"
Here it's recommended to add
\usepackage[utf8]{inputenc}
\usepackage{listingsutf8}
Brackets are empty again. Using \usepackage[greek]{babel} doesn't do anything either.
There are some posts dealing specifically with the listing like this. Of course I replaced the entire line of Umlaute with: literate={Δ}{{\"Delta}}. However, this just results in no document being built and the error: LaTeX Error: Invalid UTF-8 byte sequence (�\lst@FillFixed@). This here (doing the same, just also replacing portuguese with greek) modified the font a bit but still, the character can't be displayed.
I managed to display a Δ inside regular text using (not math mode):
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\DeclareUnicodeCharacter{0394}{\ensuremath{\Delta}}
However, this doesn't affect the box of code.
The full code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{bera}% optional: just to have a nice mono-spaced font
\usepackage{listings}
\usepackage{xcolor}
\colorlet{punct}{red!60!black}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{delim}{RGB}{20,105,176}
\colorlet{numb}{magenta!60!black}
\lstdefinelanguage{json}{
basicstyle=\normalfont\ttfamily,
numbers=left,
numberstyle=\scriptsize,
stepnumber=1,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frame=lines,
backgroundcolor=\color{background},
literate=
*{0}{{{\color{numb}0}}}{1}
{1}{{{\color{numb}1}}}{1}
{2}{{{\color{numb}2}}}{1}
{3}{{{\color{numb}3}}}{1}
{4}{{{\color{numb}4}}}{1}
{5}{{{\color{numb}5}}}{1}
{6}{{{\color{numb}6}}}{1}
{7}{{{\color{numb}7}}}{1}
{8}{{{\color{numb}8}}}{1}
{9}{{{\color{numb}9}}}{1}
{:}{{{\color{punct}{:}}}}{1}
{,}{{{\color{punct}{,}}}}{1}
{{}{{{\color{delim}{{}}}}{1}
{}}{{{\color{delim}{}}}}}{1}
{[}{{{\color{delim}{[}}}}{1}
{]}{{{\color{delim}{]}}}}{1},
}
\begin{document}
\lstinputlisting[language=json,firstnumber=1]{Vertices.json}
\end{document}
The JSON in Vertices.json (Which is an external file):
{
"_key":"9374773",
"_id":"V1/9374773",
"_rev":"_fEczBK----",
"Description":"2018 maximum braking distance",
"xpl_isGroupNode":"Δ",
"xpl_isGeneric":"Δ"
}
And here to view: https://www.overleaf.com/read/fkkcsyfppppj
literatelist). – Ulrike Fischer Jan 19 '23 at 11:14\documentclassand ends with\end{document}, and that when compiled returns exactly the error that you are asking about. In this case you of course also need the contents of the JSON file but you already provided that at the end of the question, that code block should stay in as well. – Marijn Jan 19 '23 at 12:03! LaTeX Error: File 'JsonEnv.tex' not found.. The goal is to provide code, in one code block, that can be compiled without doing anything else. This helps to minimize the effort for people on the site that want to help you. So please edit again, and integrate all the code blocks into two (one for the complete LaTeX code and one for the json data example). – Marijn Jan 19 '23 at 14:42\usepackage{bera} ......). I prefer to separate any kind of logic from the text. It doesn't matter if it's done by input or just written directly. (https://www.overleaf.com/read/fkkcsyfppppj) – Qohelet Jan 19 '23 at 14:55lstlistingenvironment instead of an external file to make a nice minimal working example. – samcarter_is_at_topanswers.xyz Jan 19 '23 at 15:25\begin{filecontents}{<your file name here>}...\end{filecontents}(see e.g. https://tex.meta.stackexchange.com/q/228/35864), but in this case it appears to me that same effect can be reproduced with\begin{lstlisting}[language=json,firstnumber=1]...\end{lstlisting}instead of\lstinputlisting. – moewe Jan 19 '23 at 15:25literate={Δ}{{\ensuremath{\Delta}}}{1},appears to work for me.\Deltaalone is not enough, because we need to go into math mode.{\ensuremath{\Delta}}does not appear to work, because thelistingsdocumentation says "Each ‘printing unit’ in<replacement text>must be in braces unless it’s a single character." So we end up with{\ensuremath{\Delta}}as the contents of the replacement text braces. – moewe Jan 19 '23 at 15:27