
다음과 같은 최소한의 문서
\documentclass{article}
\usepackage{hyperref}
\newcounter{projno}
\newcommand{\proj}{%
\stepcounter{projno}%
\theprojno}
\begin{document}
\section{Project \protect\proj }
\end{document}
오류가 발생합니다
! Missing \endcsname inserted.
<to be read again>
\csname\endcsname
l.14 \section{Project \protect\proj }
주석을 달면 오류가 사라집니다 \usepackage{hyper ref}
. 누구든지 이 딜레마에서 벗어날 수 있는 방법을 알고 있습니까?
답변1
매크로로 \proj
인해 북마크에 문제가 발생합니다. TeX의 위장 기계 대부분은 여기서 작동하지 않습니다. 확장 가능한 명령은 책갈피에서 제대로 작동하지만 할당(카운터 증분, ...)은 작동하지 않습니다. 패키지는 책갈피 내에서 재정의되거나 필터링되어야 하는 명령을 hyperref
제공 \texorpdfstring
하거나 \pdfstringdefDisableCommands
처리합니다.
\section{Project\texorpdfstring{\protect\proj}{\theprojno}}
또는 님의 북마크 코드 \proj
에 알려질 수 있습니다 .hyperref
...
\usepackage{hyperref}
\pdfstringdefDisableCommands{\let\proj\theprojno}
...
\begin{document}
...
\section{Project\protect\proj}
힌트:
\proj
로 정의한 경우 다음을 사용할 때\DeclareRobustCommand
명시적인\protect
것이 필요하지 않습니다proj
.\newcommand*{\proj}{}% check, whether \proj is undefined \DeclareRobustCommand*{\proj}{\stepcounter{projno}}
egreg의 중요한 힌트그의 코멘트:
\stepcounter
더 잘 활용해야 해~ 전에\section
. 그렇지 않으면 페이지 스타일에 따라 목차 및 헤드 라인의 항목에 따라 카운터가 증가합니다.