# How can I write letters like ř, í, á to listings?

How can I write letters like ř, í, á to listings?

Why is zero in the name of the section?

\documentclass[12pt,a4paper]{report}
\usepackage[total={7in, 9in}]{geometry}
\usepackage{enumitem}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[czech]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{framed}
\usepackage{xcolor}

\usepackage{listings}

\usepackage{xcolor,colortbl}
\usepackage[most]{tcolorbox}
\newtcbinputlisting[auto counter,list inside=lol,list type={lstlisting}]{\mylisting}[3][]{%
listing file={#3},
title=Listing,
colback=white,
colframe=gray!75!black,
fonttitle=\bfseries,
listing only,
breakable,
listing options={basicstyle=\scriptsize\ttfamily,
},
title={Script \thetcbcounter: #2},
#1
}
\newcommand{\listingsfont}{basicstyle=\ttfamily}

\begin{document}

\section{Why is here 0}
\lstset{morecomment=[l]{\#}}
\mylisting{Code}{script.txt}

\end{document}


The file with the script:

script.txt
#hello
í ů ř á
hello


You are using report class. First sectioning level of report (and book) class is chapter and not section. Therefore you are getting a zero in your section number. Use article class or try this.

Using listing options was for some reasons producing weird results, but if you instead use \lstset; you will get the desired output.

Also the argument structure can be simplified as in the following:

\documentclass[12pt,a4paper]{article}
\begin{filecontents*}[overwrite]{myscript.txt}
script.txt
# hello
í ů ř á
hello
\end{filecontents*}
\usepackage{listings}
\usepackage{xcolor,colortbl}
\usepackage[most]{tcolorbox}
\newtcbinputlisting[%
auto counter,%
list inside=lol,%
list type={lstlisting}%
]%
{\mylisting}%
[2]{%
listing file={#1},%
title=Listing,%
colback=white,%
colframe=gray!75!black,%
fonttitle=\bfseries,%
listing only,%
breakable,%
title={Script \thetcbcounter: #2},%
}

\begin{document}
\lstset{%
basicstyle=\scriptsize\ttfamily,%
morecomment=[l]{\#}%
}
\section{There is no zero here}
\mylisting{myscript.txt}{My script}
\end{document}


Note: pdflatex will complain about UTF characters, you would need to use Xe/LuaLaTeX.

• Sorry I just realized that the comment isn't colored and I have no clue why. I pass on this. Dec 1 '21 at 9:41
• Thank you very much. Dec 1 '21 at 11:03
• My pleasure :-) Dec 1 '21 at 11:52
• Have you figured out the colour comment, please? Dec 1 '21 at 16:30
• It should ideally work, but maybe something is wrong with the combination of tcolorbox and listings. Try for example this pastebin.com/yA0kzuyw. It works as expected. It might be better to 1) ask a separate question so that experts can find a way to deal with the specific problem we are facing or 2) report a bug to the maintainer of package listings or tcolorbox. Dec 2 '21 at 3:48