子节 hyperref、titletoc 和 babel 西班牙语冲突

子节 hyperref、titletoc 和 babel 西班牙语冲突

尝试使用 overleaf 的模板,它在英语中运行良好。但添加西班牙语的 babel 会弄乱文档。

如果我尝试添加,则会收到错误\subsection{}

我看过其他提到和之间冲突的问题babel,我相信这里也发生了类似的事情,但我就是想不通。hyperrefappendix

帮助我消除错误的方法是删除hyperref包或不插入目录。

这是我能采取的最简单的模板,用于重现错误(我认为)。我正在使用xelatex,不确定这是否能告诉你什么。

\documentclass[
    a4paper, % Paper size, use either a4paper or letterpaper
    12pt, % Default font size, the template is designed to look good at 12pt so it's best not to change this
]{article}

\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage[spanish]{babel}

%----------------------------------------------------------------------------------------
%   REQUIRED PACKAGES AND MISC CONFIGURATIONS
%----------------------------------------------------------------------------------------

\usepackage{etoolbox} % Required for conditional logic and easily changing commands

\newtoggle{unnumberedsections} % Create toggle for a class option
\settoggle{unnumberedsections}{false} % Default value for the class option
\DeclareOption{unnumberedsections}{\settoggle{unnumberedsections}{true}} % Set the class option toggle if the class option was used in the template

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} % Pass through any extra options specified to the base class
\ProcessOptions\relax % Process class options


\usepackage[document]{ragged2e} % Left align all text in the document (i.e. have a ragged right margin)

\usepackage{lastpage} % Required to determine the total number of pages

\AtBeginEnvironment{quote}{\itshape\rmfamily} % Style quotations

\usepackage{appendix} % Required for the appendices section

\usepackage{float} % Allows more precisely positioning floats e.g. \begin{figure}[H]

%----------------------------------------------------------------------------------------
%   SECTIONS
%----------------------------------------------------------------------------------------

\usepackage{titlesec} % Required for modifying sections

\iftoggle{unnumberedsections}{ % Conditional logic for the unnumbered sections class options
    \setcounter{secnumdepth}{0} % Don't number sections at any level
}{
    \setcounter{secnumdepth}{3} % Number sections down to subsubsections
}

\titleformat
    {\section} % Section type being modified
    [block] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
    {\raggedright\LARGE\bfseries} % Text formatting of the whole section, i.e. label and title
    {\thesection} % Section label (e.g. number) and its formatting
    {5pt} % Horizontal space between the section label and title
    {} % Code before the section title
    [] % Code after the section title

\titlespacing*{\section}{0pt}{\baselineskip}{4pt} % Spacing around section titles, the order is: left, before and after

%------------------------------------------------

\titleformat
    {\subsection} % Section type being modified
    [block] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
    {\raggedright\large\bfseries} % Text formatting of the whole section, i.e. label and title
    {\thesubsection} % Section label (e.g. number) and its formatting
    {5pt} % Horizontal space between the section label and title
    {} % Code before the section title
    [] % Code after the section title

\titlespacing*{\subsection}{0pt}{0.75\baselineskip}{4pt} % Spacing around section titles, the order is: left, before and after

%------------------------------------------------

\titleformat
    {\subsubsection} % Section type being modified
    [block] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
    {\raggedright\bfseries\normalsize} % Text formatting of the whole section, i.e. label and title
    {\thesubsubsection} % Section label (e.g. number) and its formatting
    {5pt} % Horizontal space between the section label and title
    {} % Code before the section title
    [] % Code after the section title

\titlespacing*{\subsubsection}{0pt}{0.5\baselineskip}{0pt} % Spacing around section titles, the order is: left, before and after

%------------------------------------------------

\titleformat
    {\paragraph} % Section type being modified
    [runin] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
    {\bfseries} % Text formatting of the whole section, i.e. label and title
    {} % Section label (e.g. number) and its formatting
    {0pt} % Horizontal space between the section label and title
    {} % Code before the section title
    [~~~~] % Code after the section title

\titlespacing*{\paragraph}{0pt}{0pt}{0pt} % Spacing around section titles, the order is: left, before and after

% %----------------------------------------------------------------------------------------
% % TABLE OF CONTENTS
% %----------------------------------------------------------------------------------------

\usepackage{titletoc} % Required for manipulating the table of contents

\setcounter{tocdepth}{2} % Show entries in the table of contents down to subsections

\renewcommand{\contentsname}{Table of Contents} % Rename the table of contents section heading

\titlecontents{section} % Section type being modified
    [0pt] % Left indentation
    {\vspace{-2pt}} % Before code
    {\textsb{\thecontentslabel}~~\textsb} % Formatting of numbered sections of this type
    {\textsb} % Formatting of numberless sections of this type
    {\titlerule*[6pt]{.}\textsb{\contentspage}} % Formatting of the filler to the right of the heading and the page number
    [\vspace{2pt}] % After code

%------------------------------------------------

\titlecontents{subsection} % Section type being modified
    [0.5cm] % Left indentation
    {\vspace{-8pt}} % Before code
    {\textsb{\thecontentslabel}~~} % Formatting of numbered sections of this type
    {} % Formatting of numberless sections of this type
    {\titlerule*[6pt]{.}\contentspage} % Formatting of the filler to the right of the heading and the page number
    [] % After code
    
%------------------------------------------------

\titlecontents{subsubsection} % Section type being modified
    [1.35cm] % Left indentation
    {\vspace{-4pt}} % Before code
    {\textsb{\thecontentslabel}~~} % Formatting of numbered sections of this type
    {} % Formatting of numberless sections of this type
    {\titlerule*[6pt]{.}\contentspage} % Formatting of the filler to the right of the heading and the page number
    [] % After code



%----------------------------------------------------------------------------------------
%   LINKS
%----------------------------------------------------------------------------------------

\usepackage{hyperref}

\hypersetup{
    colorlinks=true, % Whether to color the text of links
    urlcolor=red, % Color for \url and \href links
    linkcolor=black, % Color for \nameref links
    citecolor=black, % Color of reference citations
}


%----------------------------------------------------------------------------------------
%   MAIN DOCUMENT
%----------------------------------------------------------------------------------------

\begin{document}


%----------------------------------------------------------------------------------------
%   TABLE OF CONTENTS
%----------------------------------------------------------------------------------------

\thispagestyle{empty} 

\tableofcontents % Output the table of contents, automatically generated from the section commands used in the document

\section{Hola}

Hola

\subsection{No sirve}
    
\end{document}

这是我得到的错误

Undefined control sequence.
<argument> ...me system@active~\endcsname \textsb 
                                                  
l.2 ...section}{\numberline {1}Hola}{1}{section.1}

Undefined control sequence.
<argument> \textsb 
                   {\thecontentslabel }~~
l.3 ...umberline {1.1}No sirve}{1}{subsection.1.1}
                                                  %

请帮帮我,我快要疯了!!

答案1

定义\textsb。(之后fontspec-italic-small-caps-with-semi-bold并且先前的答案

A

% !TeX TS-program = xelatex

\documentclass[
a4paper, % Paper size, use either a4paper or letterpaper
12pt, % Default font size, the template is designed to look good at 12pt so it's best not to change this
]{article}

 %\usepackage[utf8]{inputenc} % Required for inputting international characters
%\usepackage[T1]{fontenc} % Output font encoding for international characters

\usepackage[spanish,es-notilde]{babel}% changed <<<<<<<<<<<<<<<<


%% https://tex.stackexchange.com/questions/592364/fontspec-italic-small-caps-with-semi-bold
%%  https://tex.stackexchange.com/a/264666/161015
%****************************************************** added <<<<<<<<<<<<<<<<<<<
\usepackage{fontspec}

\setmainfont{Linux Libertine O}[
BoldFont=* Bold,
BoldItalicFont=* Bold Italic,
FontFace = {sb}{n}{* Semibold},
FontFace = {sb}{it}{* Semibold Italic},
]

\DeclareRobustCommand{\sbseries}{\fontseries{sb}\selectfont}
\DeclareTextFontCommand{\textsb}{\sbseries}
%******************************************************

%----------------------------------------------------------------------------------------
%   REQUIRED PACKAGES AND MISC CONFIGURATIONS
%----------------------------------------------------------------------------------------

\usepackage{etoolbox} % Required for conditional logic and easily changing commands

\newtoggle{unnumberedsections} % Create toggle for a class option
\settoggle{unnumberedsections}{false} % Default value for the class option
\DeclareOption{unnumberedsections}{\settoggle{unnumberedsections}{true}} % Set the class option toggle if the class option was used in the template

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} % Pass through any extra options specified to the base class
\ProcessOptions\relax % Process class options


\usepackage[document]{ragged2e} % Left align all text in the document (i.e. have a ragged right margin)

\usepackage{lastpage} % Required to determine the total number of pages

\AtBeginEnvironment{quote}{\itshape\rmfamily} % Style quotations

\usepackage{appendix} % Required for the appendices section

\usepackage{float} % Allows more precisely positioning floats e.g. \begin{figure}[H]

%----------------------------------------------------------------------------------------
%   SECTIONS
%----------------------------------------------------------------------------------------

\usepackage{titlesec} % Required for modifying sections

\iftoggle{unnumberedsections}{ % Conditional logic for the unnumbered sections class options
    \setcounter{secnumdepth}{0} % Don't number sections at any level
}{
    \setcounter{secnumdepth}{3} % Number sections down to subsubsections
}

\titleformat
{\section} % Section type being modified
[block] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
{\raggedright\LARGE\bfseries} % Text formatting of the whole section, i.e. label and title
{\thesection} % Section label (e.g. number) and its formatting
{5pt} % Horizontal space between the section label and title
{} % Code before the section title
[] % Code after the section title

\titlespacing*{\section}{0pt}{\baselineskip}{4pt} % Spacing around section titles, the order is: left, before and after

%------------------------------------------------

\titleformat
{\subsection} % Section type being modified
[block] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
{\raggedright\large\bfseries} % Text formatting of the whole section, i.e. label and title
{\thesubsection} % Section label (e.g. number) and its formatting
{5pt} % Horizontal space between the section label and title
{} % Code before the section title
[] % Code after the section title

\titlespacing*{\subsection}{0pt}{0.75\baselineskip}{4pt} % Spacing around section titles, the order is: left, before and after

%------------------------------------------------

\titleformat
{\subsubsection} % Section type being modified
[block] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
{\raggedright\bfseries\normalsize} % Text formatting of the whole section, i.e. label and title
{\thesubsubsection} % Section label (e.g. number) and its formatting
{5pt} % Horizontal space between the section label and title
{} % Code before the section title
[] % Code after the section title

\titlespacing*{\subsubsection}{0pt}{0.5\baselineskip}{0pt} % Spacing around section titles, the order is: left, before and after

%------------------------------------------------

\titleformat
{\paragraph} % Section type being modified
[runin] % Section layout type, can be: hang, block, display, runin, leftmargin, rightmargin, drop, wrap, frame
{\bfseries} % Text formatting of the whole section, i.e. label and title
{} % Section label (e.g. number) and its formatting
{0pt} % Horizontal space between the section label and title
{} % Code before the section title
[~~~~] % Code after the section title

\titlespacing*{\paragraph}{0pt}{0pt}{0pt} % Spacing around section titles, the order is: left, before and after

% %----------------------------------------------------------------------------------------
% % TABLE OF CONTENTS
% %----------------------------------------------------------------------------------------

\usepackage{titletoc} % Required for manipulating the table of contents

\setcounter{tocdepth}{2} % Show entries in the table of contents down to subsections

\renewcommand{\contentsname}{Table of Contents} % Rename the table of contents section heading

\titlecontents{section} % Section type being modified
[0pt] % Left indentation
{\vspace{-2pt}} % Before code
{\textsb{\thecontentslabel}~~} % Formatting of numbered sections of this type
{\textsb} % Formatting of numberless sections of this type
{\titlerule*[6pt]{.}\textsb{\contentspage}} % Formatting of the filler to the right of the heading and the page number
[\vspace{2pt}] % After code

%------------------------------------------------

\titlecontents{subsection} % Section type being modified
[0.5cm] % Left indentation
{\vspace{-2pt}} % Before code <<<<<<<<<<<<<<<<<<<
{\textsb{\thecontentslabel}~~} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{\titlerule*[6pt]{.}\contentspage} % Formatting of the filler to the right of the heading and the page number
[] % After code

%------------------------------------------------

\titlecontents{subsubsection} % Section type being modified
[1.35cm] % Left indentation
{\vspace{-4pt}} % Before code
{\textsb{\thecontentslabel}~~} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{\titlerule*[6pt]{.}\contentspage} % Formatting of the filler to the right of the heading and the page number
[] % After code



%----------------------------------------------------------------------------------------
%   LINKS
%----------------------------------------------------------------------------------------

\usepackage{hyperref}

\hypersetup{
    colorlinks=true, % Whether to color the text of links
    urlcolor=red, % Color for \url and \href links
    linkcolor=black, % Color for \nameref links
    citecolor=black, % Color of reference citations
}


%----------------------------------------------------------------------------------------
%   MAIN DOCUMENT
%----------------------------------------------------------------------------------------

\begin{document}
    
    
    %----------------------------------------------------------------------------------------
    %   TABLE OF CONTENTS
    %----------------------------------------------------------------------------------------
    
    \thispagestyle{empty} 
    
    \tableofcontents % Output the table of contents, automatically generated from the section commands used in the document
    
    \section{Hola}
    
    Hola
    
    \textsb{Hola}
    
    \subsection{No sirve}
    
\end{document}

相关内容