
Я пытаюсь объединитьЗаглавные буквы, курсив и гиперссылки в toc scrartcl без использования tocstyleиГлава в верхнем регистре с KOMA-скриптом:
\renewcommand\addsectiontocentry[2]{%
\addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
\addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsubsectiontocentry[2]{%
\addtocentrydefault{subsubsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hskip#2#3}{\MakeUppercase{#4}}%
}
\makeatother
Однако ссылки TOC никуда не ведут. Есть идеи, как это исправить?
Я пытался заменить
\addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
с
\addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{\MakeUppercase{#2}}}%
но я получаю \MakeUppercase ...ppercaseUnsupportedInPdfStrings
ошибку. Документ создан с помощью pandoc, поэтому я могу добавить только некоторые фрагменты latex.
Я полный новичок в LaTeX, поэтому был бы очень признателен не только за решение, но и за любые подсказки о том, как самостоятельно устранять такие проблемы.
UPD: ниже приведен минимально воспроизводимый пример:
% Run "xelatex example.tex" (twice) to compile to pdf
\documentclass{scrartcl}
\usepackage{blindtext}% only for dummy text
\setcounter{tocdepth}{\subsubsectiontocdepth}
\renewcommand\addsectiontocentry[2]{%
\addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
\addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsubsectiontocentry[2]{%
\addtocentrydefault{subsubsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hskip #2#3}{\MakeUppercase{#4}}%
}
\makeatother
\renewcommand{\sectioncatchphraseformat}[4]{%
\hskip #2#3\MakeUppercase{#4}%
}
\usepackage{hyperref}
% This command breaks TOC hyperlinks
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\begin{document}
\tableofcontents
\blinddocument
\blinddocument
\end{document}
решение1
Обновлять:
Даже если я добавлю \setcounter{secnumdepth}{-\maxdimen}
код все равно работает у меня, но я использую обновленную версию KOMA-Script 3.31 (2020/07/22). В предыдущих версиях была проблема с hyperref
и ненумерованными разделами, см.Исправленные проблемы и дополнения в KOMA-Script 3.30(Немецкий). Так что, возможно, вам придется обновиться.
% Run "xelatex example.tex" (twice) to compile to pdf
\documentclass{scrartcl}[2020/07/22]% version 3.31 or newer
\usepackage{blindtext}% only for dummy text
\setcounter{tocdepth}{\subsubsectiontocdepth}
\renewcommand\addsectiontocentry[2]{%
\addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
\addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsubsectiontocentry[2]{%
\addtocentrydefault{subsubsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hskip #2#3}{\MakeUppercase{#4}}%
}
\makeatother
\renewcommand{\sectioncatchphraseformat}[4]{%
\hskip #2#3\MakeUppercase{#4}%
}
\usepackage{hyperref}
% This command breaks TOC hyperlinks
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\begin{document}
\KOMAScriptVersion% added to show the KOMA-Script version in the document
\tableofcontents
\blinddocument
\blinddocument
\end{document}
Оригинальный ответ:
Жду комментария:
Следующий пример мне подходит.
\documentclass{scrartcl}
\usepackage{blindtext}% only for dummy text
\setcounter{tocdepth}{\subsectiontocdepth}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hskip#2#3}{\MakeUppercase{#4}}%
}
\makeatother
\renewcommand{\sectioncatchphraseformat}[4]{%
\hskip#2#3\MakeUppercase{#4}%
}
\renewcommand\addsectiontocentry[2]{%
\addtocentrydefault{section}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\renewcommand\addsubsectiontocentry[2]{%
\addtocentrydefault{subsection}{#1}{\texorpdfstring{\MakeUppercase{#2}}{#2}}%
}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\blinddocument
\blinddocument
\end{document}
Результат: