![섹션 제목에서 하이퍼참조와 함께 \newrobustcmd 및 \NewDocumentCommand를 사용하는 방법](https://rvso.com/image/353010/%EC%84%B9%EC%85%98%20%EC%A0%9C%EB%AA%A9%EC%97%90%EC%84%9C%20%ED%95%98%EC%9D%B4%ED%8D%BC%EC%B0%B8%EC%A1%B0%EC%99%80%20%ED%95%A8%EA%BB%98%20%5Cnewrobustcmd%20%EB%B0%8F%20%5CNewDocumentCommand%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
활성화된 섹션 제목에 어떻게 사용할 수 \newrobustcmd
있나요 ? 아래 MWE는 렌더링된 PDF가 올바르게 보이지만 책갈피에 매크로 내용이 표시되지 않음을 보여줍니다.NewDocumentCommand
hyperref
\documentclass[11pt]{article}
\usepackage{hyperref}
\usepackage{xparse}
\usepackage{etoolbox}
\newcommand{\testA}[0]{world}
\newrobustcmd{\testB}[0]{world}
\NewDocumentCommand{\testC}{}{world}
\begin{document}
\section{Hello \testA}
\section{Hello \testB}
\section{Hello \testC}
\end{document}
파일 MWE.out
은 다음과 같습니다.
\BOOKMARK [1][-]{section.1}{Hello world}{}% 1
\BOOKMARK [1][-]{section.2}{Hello }{}% 2
\BOOKMARK [1][-]{section.3}{Hello }{}% 3
답변1
를 사용 하면 \newcommand
확장 가능한 매크로( \def
)를 정의하고 을 사용하면 \newrobustcmd
엔진 \NewDocumentCommand
보호 매크로( \protected\def
)를 정의할 수 있습니다. 북마크 문자열이 작성되는 동안 북마크 내용이 확장되지만 보호된 매크로는 확장될 수 없으므로 토큰 \testB
과 \testC
MWE의 토큰은 북마크에 있는 대로 종료됩니다. hyperref
그것들을 어떻게 해야할지 모르기 때문에 그것들을 버립니다.
Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref) removing `\testB' on input line 13.
Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref) removing `\testC' on input line 14.
따라서 보호된 매크로가 정말로 필요한 경우 두 가지 선택이 있습니다.
\section{Hello \texorpdfstring{\testB}{world}}
문서에 사용하거나hyperref
북마크에 사용될 로드 후 서문에 더 간단한 확장 가능한 정의를 추가하세요.\pdfstringdefDisableCommands{% \def\testB{world}% \def\testC{world}% }