3

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, commentstyle=\color{purple}, }, 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
Anna-Kat
  • 267
  • 1
    with pdflatex you can use literate see e.g. https://tex.stackexchange.com/questions/24528/having-problems-with-listings-and-utf-8-can-it-be-fixed – Ulrike Fischer Dec 01 '21 at 15:29

1 Answers1

5

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,% commentstyle=\color{purple},% Not working :( 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.

1

Niranjan
  • 3,435