
為什麼pdflatex
(但不是)即使使用文檔編碼而不是普通的西里爾字母也會lualatex
寫入 toc-file -命令?如何預防呢?我對重新定義命令的解決方案感興趣。我重新定義了 但沒有結果。\cyr
utf8
book.cls
\addcontentsline{toc}{part}{\unexpanded\expandafter{{#1}}}%
% !TeX program = pdflatex
% !TeX encoding = utf8
% !TeX spellcheck = uk_UA
% !BIB program = bibtex8
\documentclass[12pt]{book}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T2A,T1]{fontenc}
\usepackage[ukrainian]{babel}
\usepackage{indentfirst}
\usepackage{misccorr}
\makeatletter
\def\@part[#1]#2{%
\thispagestyle{empty}
\addcontentsline{toc}{part}{\unexpanded\expandafter{{#1}}}%
{\centering
\interlinepenalty \@M
\normalfont
\Huge \sffamily\bfseries #1\par}%
\@endpart
}
\makeatother
\begin{document}
\tableofcontents
\part{Перша}
іва
\part{Друга}
іфавіфав
\end{document}
Toc
好像
\select@language {ukrainian}
\contentsline {part}{{\IeC {\CYRP }\IeC {\cyre }\IeC {\cyrr }\IeC {\cyrsh }\IeC {\cyra }}}{3}
\contentsline {part}{{\IeC {\CYRD }\IeC {\cyrr }\IeC {\cyru }\IeC {\cyrg }\IeC {\cyra }}}{7}
答案1
您可以嘗試使用\detokenize
.
用於hyperref
:需要同時使用\texorpdfstring
和\phantomsection
的補丁\@part
。
\documentclass[12pt]{book}
\usepackage[a4paper]{geometry}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ukrainian]{babel}
\usepackage{indentfirst}
\usepackage{misccorr}
% update for hyperref compatibility
\makeatletter
\def\@part[#1]#2{%
\thispagestyle{empty}%
\phantomsection
\addcontentsline{toc}{part}{\texorpdfstring{\detokenize{#1}}{#1}}%
{\centering
\interlinepenalty \@M
\normalfont
\Huge \sffamily\bfseries #1\par
}%
\@endpart
}
\makeatother
\usepackage[pdfencoding=auto]{hyperref}
\begin{document}
\tableofcontents
\part{Перша}
іва
\part{Друга}
іфавіфав
\end{document}
toc文件的內容:
\select@language {ukrainian}
\contentsline {part}{Перша}{3}
\contentsline {part}{Друга}{7}
與hyperref
:
\select@language {ukrainian}
\contentsline {part}{Перша}{3}{section*.2}
\contentsline {part}{Друга}{7}{section*.3}
答案2
原則上,至少文件的不同部分可以使用不同的輸入編碼,因此該機制被設計為始終以編碼中性的LICR
ascii 標記寫入輔助文件。
實際上,尤其是當您使用 UTF-8 時,整個文件都使用單一編碼,但 UTF-8 以及 LaTeX 上的 UTF-8 支援比 toc 檔案的編碼支援的設計要晚一些。