我正在使用tcolorbox
越南语的练习和解决方案,但无法编译此代码。我做错了什么?
\documentclass[12pt,a4paper]{article}
\usepackage{fouriernc}
\usepackage[utf8]{vietnam}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\tcbset{texercisestyle/.style={arc=0.5mm, colframe=blue!25!yellow!90!white,
colback=blue!25!yellow!5!white, coltitle=blue!25!yellow!40!black,
fonttitle=\small\sffamily\bfseries, fontupper=\small, fontlower=\small,
listing options={style=tcblatex,texcsstyle=*\color{red!40!black}},
}}
\newtcolorbox[auto counter,number within=section,list inside=exam]{baitap}[2][]{%
texercisestyle,
listing file={solutions/texercise\thetcbcounter.tex},
label={exe:#2},
record={\string\processsol{solutions/texercise\thetcbcounter.tex}{#2}},
title={Bài tập \thetcbcounter\hfill\textbf{Lời giải ở trang} \pageref{sol:#2}},
list text={Exercise with solution on page \pageref{sol:#2}},#1}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\begin{document}
\section{Thử máy}
Thử máy
\tcbset{texercisestyle/.style={arc=0.5mm, colframe=blue!25!yellow!90!white,
colback=blue!25!yellow!5!white, coltitle=blue!25!yellow!40!black,
fonttitle=\small\sffamily\bfseries, fontupper=\small, fontlower=\small,
listing options={style=tcblatex,texcsstyle=*\color{red!40!black}},
}}
\tcbstartrecording
\begin{baitap}{tabular_example}
Giải phương trình
\[(x^2 + 2x + 3) \cdot \sqrt{4x +5} + (6x^2 + 7x + 8) \cdot \sqrt{9x +10} = 9.\]
\begin{tcboutputlisting}
\begin{tcbwritetemp}
This is a solution.
\end{tcbwritetemp}
\end{tcboutputlisting}
\tcbuselistingtext%
\end{baitap}
\begin{baitap}{macro_twoparam}
\begin{tcboutputlisting}
Tôi không thể viết được tiếng Việt Nam (I can't write Vietnamese).
\end{tcboutputlisting}
\tcbuselistingtext%
This is a problem. \par\smallskip
\begin{tcbwritetemp}
\end{tcbwritetemp}
\tcbusetemplisting\par\smallskip\tcbusetemp%
\end{baitap}
\tcbstoprecording
\tcblistof[\subsection]{exam}{List of Exercises%
\label{listofexercises}}
\newtcbinputlisting{\processsol}[2]{%
texercisestyle,
listing only,
listing file={#1},
phantomlabel={sol:#2},%
title={Lời giải cho Bài tập \ref{exe:#2} ở trang \pageref{exe:#2}},
}
\tcbinputrecords
\end{document}
答案1
这是底层包的问题,在使用字符listings
时会出现问题。您可以使用来稍微放松一下这个问题,因为这会将字符映射到可选的 8 位编码(这是默认值)。我不知道您是否可以在 中表示所有越南语字符,但我不这么认为(它可以编译,但结果并不好)。utf8
\tcbuselibrary{listingsutf8}
latin1
latin1
另一个选择是用 替换listings
。minted
这样就可以使用utf8
字符。请注意,你可能需要安装其他软件才能使用 minted。
这是由以下人员制作的:
% !TeX encoding=UTF-8
\documentclass[12pt,a4paper]{article}
\usepackage{fouriernc}
\usepackage[utf8]{vietnam}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{tcolorbox}
\tcbuselibrary{minted}
\tcbset{texercisestyle/.style={arc=0.5mm, colframe=blue!25!yellow!90!white,
colback=blue!25!yellow!5!white, coltitle=blue!25!yellow!40!black,
fonttitle=\small\sffamily\bfseries, fontupper=\small, fontlower=\small,
%listing options={style=tcblatex,texcsstyle=*\color{red!40!black}},
minted options={fontsize=\small},
}}
\newtcolorbox[auto counter,number within=section,list inside=exam]{baitap}[2][]{%
texercisestyle,
listing file={solutions/texercise\thetcbcounter.tex},
label={exe:#2},
record={\string\processsol{solutions/texercise\thetcbcounter.tex}{#2}},
title={Bài tập \thetcbcounter\hfill\textbf{Lời giải ở trang} \pageref{sol:#2}},
list text={Exercise with solution on page \pageref{sol:#2}},#1}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\begin{document}
\section{Thử máy}
Thử máy
\tcbset{texercisestyle/.style={arc=0.5mm, colframe=blue!25!yellow!90!white,
colback=blue!25!yellow!5!white, coltitle=blue!25!yellow!40!black,
fonttitle=\small\sffamily\bfseries, fontupper=\small, fontlower=\small,
%listing options={style=tcblatex,texcsstyle=*\color{red!40!black}},
minted options={fontsize=\small},
}}
\tcbstartrecording
\begin{baitap}{tabular_example}
Giải phương trình
\[(x^2 + 2x + 3) \cdot \sqrt{4x +5} + (6x^2 + 7x + 8) \cdot \sqrt{9x +10} = 9.\]
\begin{tcboutputlisting}
\begin{tcbwritetemp}
This is a solution.
\end{tcbwritetemp}
\end{tcboutputlisting}
\tcbuselistingtext%
\end{baitap}
\begin{baitap}{macro_twoparam}
\begin{tcboutputlisting}
Tôi không thể viết được tiếng Việt Nam (I can't write Vietnamese).
\end{tcboutputlisting}
\tcbuselistingtext%
This is a problem. \par\smallskip
\begin{tcbwritetemp}
\end{tcbwritetemp}
\tcbusetemplisting\par\smallskip\tcbusetemp%
\end{baitap}
\tcbstoprecording
\tcblistof[\subsection]{exam}{List of Exercises%
\label{listofexercises}}
\newtcbinputlisting{\processsol}[2]{%
texercisestyle,
listing only,
listing file={#1},
phantomlabel={sol:#2},%
title={Lời giải cho Bài tập \ref{exe:#2} ở trang \pageref{exe:#2}},
}
\tcbinputrecords
\end{document}
listings
毕竟可能还有其他使用方法。对于德语变音符号,可以使用
\lstset{literate=%
{Ä}{{\"A}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
{ä}{{\"a}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
{ß}{{\ss}}1
}
类似的技巧可能也适用于越南字符(?)。
答案2
由于 VnTeXvnr
默认使用字体,如果您希望列表使用相同的字体,您可以添加fontfamily=vnr
到minted options
。这对我来说很有效。
% !TeX encoding=UTF-8
\documentclass[12pt,a4paper]{article}
\usepackage{fouriernc}
\usepackage[utf8]{vietnam}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{tcolorbox}
\tcbuselibrary{minted}
\tcbset{texercisestyle/.style={arc=0.5mm, colframe=blue!25!yellow!90!white,
colback=blue!25!yellow!5!white, coltitle=blue!25!yellow!40!black,
fonttitle=\small\sffamily\bfseries, fontupper=\small, fontlower=\small,
%listing options={style=tcblatex,texcsstyle=*\color{red!40!black}},
minted options={fontfamily=vnr,fontsize=\small},
}}
\newtcolorbox[auto counter,number within=section,list inside=exam]{baitap}[2][]{%
texercisestyle,
listing file={solutions/texercise\thetcbcounter.tex},
label={exe:#2},
record={\string\processsol{solutions/texercise\thetcbcounter.tex}{#2}},
title={Bài tập \thetcbcounter\hfill\textbf{Lời giải ở trang} \pageref{sol:#2}},
list text={Exercise with solution on page \pageref{sol:#2}},#1}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\begin{document}
\section{Thử máy}
Thử máy
\tcbstartrecording
\begin{baitap}{tabular_example}
Giải phương trình
\[(x^2 + 2x + 3) \cdot \sqrt{4x +5} + (6x^2 + 7x + 8) \cdot \sqrt{9x +10} = 9.\]
\begin{tcboutputlisting}
\begin{tcbwritetemp}
This is a solution.
\end{tcbwritetemp}
\end{tcboutputlisting}
\tcbuselistingtext%
\end{baitap}
\begin{baitap}{macro_twoparam}
\begin{tcboutputlisting}
Bây giờ tôi có thể viết được tiếng Việt Nam (Now, I can write Vietnamese).
\end{tcboutputlisting}
\tcbuselistingtext%
My previous problem is solved. \par\smallskip
\begin{tcbwritetemp}
\end{tcbwritetemp}
\tcbusetemplisting\par\smallskip\tcbusetemp%
\end{baitap}
\tcbstoprecording
\tcblistof[\subsection]{exam}{List of Exercises%
\label{listofexercises}}
\newtcbinputlisting{\processsol}[2]{%
texercisestyle,
listing only,
listing file={#1},
phantomlabel={sol:#2},%
title={Lời giải cho Bài tập \ref{exe:#2} ở trang \pageref{exe:#2}},
}
\tcbinputrecords
\end{document}