ů ř 未出现在列表中

ů ř 未出现在列表中

请问如何将 ů 和 ř 添加到列表中?

\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]{\#}%
}

\mylisting{myscript.txt}{My script}
\end{document}

输出:

在此处输入图片描述

答案1

你需要literate

\begin{filecontents*}[overwrite]{\jobname.txt}
script.txt
# hello
í ů ř á
hello
\end{filecontents*}

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[czech]{babel}
\usepackage{listings}
\usepackage[table]{xcolor}
\usepackage[most]{tcolorbox}
\newtcbinputlisting[
  auto counter,
  list inside=lol,
  list type={lstlisting}
]{\mylisting}[2]{
  listing file={#1},
  colback=white,
  colframe=gray!75!black,
  fonttitle=\bfseries,
  listing only,
  breakable,
  title={Script \thetcbcounter: #2},
}

\lstset{
  basicstyle=\scriptsize\ttfamily,
  commentstyle=\color{purple},
  morecomment=[l]{\#},
  literate=
   {í}{{\'i}}1
   {ů}{{\r{u}}}1
   {ř}{{\v{r}}}1
   {á}{{\'a}}1
   % add the other needed characters along the same line
}

\begin{document}

\mylisting{\jobname.txt}{My script}

\end{document}

确保将字符作为单个 Unicode 点输入,而不是组合重音符号输入。

在此处输入图片描述

您可以尝试这样做:您的设置问题可能是您的编辑器使用了组合重音而没有进行规范化。

\lstset{
  basicstyle=\scriptsize\ttfamily,
  commentstyle=\color{purple},
  morecomment=[l]{\#},
  literate=
   {í}{{\'i}}1
   {ů}{{\r{u}}}1 % U+016F
   {u^^cc^^8a}{{\r{u}}}1
   {ř}{{\v{r}}}1 % U+0159
   {r^^cc^^8c}{{\v{r}}}1
   {á}{{\'a}}1
   % add the other needed characters along the same line
}

答案2

我可能会使用它lualatex,然后问题就消失了。

但是如果您必须坚持,pdflatex那么您可以使用该listingsutf8 tcolorbox库并指定适当的编码(latin2)。

listings options={}在您的选项中使用tcolorbox而不是\lstset似乎被忽略的选项。

\documentclass{article}
\begin{filecontents*}[overwrite]{myscript.txt}
script.txt
# hello
í ů ř á
hello
\end{filecontents*}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{listingsutf8}
\newtcbinputlisting{\mylisting}[1]{
  listing utf8=latin2,
  listing file={#1},
  listing only,
  listing options={
    style=tcblatex,
    basicstyle=\scriptsize\ttfamily,
    commentstyle=\color{purple},
    morecomment={[l]{\#}}
  }
}
\begin{document}
\mylisting{myscript.txt}
\end{document}

输出

相关内容