매크로의 PDF-메타데이터 정의가 외부 .tex 파일에서 작동하지 않습니다.

매크로의 PDF-메타데이터 정의가 외부 .tex 파일에서 작동하지 않습니다.

두 개의 파일이 있습니다. 내 기본 tex 파일과 여러 정의가 포함된 파일(.sty 파일이 아니라 다른 .tex 파일).

\@title-command 를 사용하여 -macros 에서 PDF 메타데이터를 설정하려고 하면 \AtBeginDocument(그러나 외부 파일에 정의됨) 다음과 같은 오류가 발생합니다.

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding): (hyperref) removing `\spacefactor' on input line 14.
Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding): (hyperref) removing `\@m' on input line 14.

내 메타데이터는 "제목"일 뿐입니다. 그러나 코드를 기본 파일에 배치하면 예상대로 작동합니다. mwe는 다음과 같습니다.


% main file
\documentclass{scrartcl}

\input{externalfile.tex}

\title{This is a test}

% WORKS
% \makeatletter
% \hypersetup{
%     pdftitle={\@title}
% }
% \makeatother

\begin{document}
    test
\end{document}

% external file
\usepackage{hyperref}

% DOESN'T WORK
\AtBeginDocument{
    \makeatletter
    \hypersetup{
        pdftitle={\@title}
    }
    \makeatother
}

어떤 아이디어라도 감사하겠습니다. 그러나 외부 파일을 .tex 파일로 유지하고 싶습니다. (그리고 .sty 파일로 전환하지 마십시오. 이것이 차이가 있다면)

관련 정보