
babel
의 옵션은 자동으로 문자 앞에 를 추가하여 문자를 frenchb
활성화합니다 . 이러한 활성 문자는 의 북마크 섹션에서 적절하게 지원됩니다. 그러나 사양을 사용하여 나만의 섹션 명령을 만들려고 하면 다음 MWE에서 지적한 것처럼 잘 알려진 경고가 표시됩니다 .!
\thinspace
hyperref
\addcontentsline
Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding)
\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{hyperref}
\newcommand{\mynaivesection}[1]{%
\textbf{#1}%
\addcontentsline{toc}{section}{#1}%
}
\begin{document}
\tableofcontents
\section{Foo !}
\mynaivesection{Bar !}
\end{document}
이 경고를 없애기 위해 (의도적으로 순진하게) 사용자 정의된 섹션 명령에 누락된 것은 무엇입니까?
지금:
- 이 사용자 정의 섹션 명령을 제거하면 경고가 없습니다
\textbf{#1}%
. 다소 이상합니다... bookmark
패키지는 여기서 도움이 되지 않습니다.
답변1
인수를 삭제하는 것은 하이퍼참조가 아닙니다. \section
와 명령 의 주요 차이점은 이 \addcontentsline
수직 모드에서 처음으로 실행된다는 것입니다. 그리고 ! 모드에 따라 다릅니다.
\french@sh@!@ ->\ifhmode \ifdim \lastskip >\z@ \unskip \penalty \@M \FBthinspace
\else \FDP@thinspace \fi \fi \string !
a를 삽입하면 (그리고 vmode에서와 같이 \par
앞에 텍스트가 없으면 ) 경고가 사라집니다.\addcontentsline
\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[]{hyperref}
\usepackage{etoolbox}
\pretocmd\addcontentsline{\ifvmode \message{V-Mode!#3}\else\message{H-Mode!#3}\fi}{}{}
\newcommand{\mynaivesection}[1]{%
#1\addcontentsline{toc}{section}{{#1}}}%
\begin{document}
\tableofcontents
\section{Foo !}
\mynaivesection{Bar!}
\renewcommand{\mynaivesection}[1]{%
#1\par\addcontentsline{toc}{section}{{#1}}}%
\mynaivesection{FooBar!}
\end{document}
답변2
\FBthinspace
아무것도 하지 않도록 로컬로 재정의할 수 있습니다 .
\newcommand{\mynaivesection}[1]{%
\textbf{#1}%
\begingroup%
\renewcommand{\FBthinspace}{}%
\addcontentsline{toc}{section}{#1}%
\endgroup%
}
MWE:
\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{hyperref}
\newcommand{\mynaivesection}[1]{%
\textbf{#1}%
\begingroup%
\renewcommand{\FBthinspace}{}%
\addcontentsline{toc}{section}{#1}%
\endgroup%
}
\begin{document}
\tableofcontents
\section{Foo !}
\mynaivesection{Bar !}
\end{document}
산출: