我正在尝试使用.pdf
此代码将数据传递给文件的元数据设置,但在传递数据时它给我带来了一个错误
\def\author#1{\gdef\insertauthor{#1}\gdef\@author{#1}}
\def\title#1{\gdef\inserttitle{#1}\gdef\@title{#1}}
\def\firstsupervisor#1{\gdef\insertsupervisor{#1}}
\def\secondsupervisor#1{\gdef\insertsupervisor{#1}}
\def\institution#1{\gdef\insertinstitution{#1}}
\def\degree#1{\gdef\insertdegree{#1}}
\def\faculty#1{\gdef\insertfaculty{#1}}
\def\department#1{\gdef\insertdepartment{#1}}
\def\submitdate#1{\gdef\insertsubmitdate{#1}}
\def\keywords#1{\gdef\insertkeywords{#1}}
\submitdate{\number\the\year}
\RequirePackage[final,breaklinks,bookmarks]{hyperref}
\hypersetup{%
colorlinks=true,allcolors=black,
pdftitle = {\inserttitle},
pdfkeywords = {\insertkeywords},
pdfauthor = {\textcopyright\ \insertauthor},
pdfcreator = {\LaTeX\ with package \flqq hyperref\frqq},
pdfproducer = {pdfeTeX-0.\the\pdftexversion\pdftexrevision}
}
\RequirePackage{hypcap}
错误说Undefined control sequence. }
答案1
\hypersetup
在使用之前生效\title
,因此它会尝试在那时获取未定义的命令。和 也是\inserttitle
如此。 LaTeX 会在 上报错,因为它是 中使用的三个命令中的第一个。\insertauthor
\insertkeywords
\inserttitle
\hypersetup
由于\hypersetup
没有前导码限制命令,如果需要的话,它可以被多次使用,甚至可以在文档主体中使用。
我建议使用\title
etc. 命令自动插入相关数据。只要\title
之前没有使用过 etc. ,它hyperref
就会加载并预设\hypersetup
基本与作者/文档内容无关的数据,这样就可以了
显然,所显示的片段来自.cls
或.sty
文件,我围绕它构建了一个文档,并将那里的\makeatletter...\makeatother
各种\def....
命令包装在一起。
\documentclass{article}
\makeatletter
\def\author#1{\gdef\insertauthor{#1}\gdef\@author{#1}\hypersetup{pdfauthor={\textcopyright\ #1}}}
\def\title#1{\gdef\inserttitle{#1}\gdef\@title{#1}\hypersetup{pdftitle={#1}}}
\def\firstsupervisor#1{\gdef\insertsupervisor{#1}}
\def\secondsupervisor#1{\gdef\insertsupervisor{#1}}
\def\institution#1{\gdef\insertinstitution{#1}}
\def\degree#1{\gdef\insertdegree{#1}}
\def\faculty#1{\gdef\insertfaculty{#1}}
\def\department#1{\gdef\insertdepartment{#1}}
\def\submitdate#1{\gdef\insertsubmitdate{#1}}
\def\keywords#1{\gdef\insertkeywords{#1}\hypersetup{pdfkeywords={#1}}}
\submitdate{\number\the\year}
\makeatother
\RequirePackage[final,breaklinks,bookmarks]{hyperref}
\hypersetup{%
colorlinks=true,allcolors=black,
% pdftitle = {\inserttitle},%
% pdfkeywords = {\insertkeywords},
% pdfauthor = {\textcopyright\ \insertauthor},%
pdfcreator = {\LaTeX\ with package \flqq hyperref\frqq},
pdfproducer = {pdfeTeX-0.\the\pdftexversion\pdftexrevision}
}
\title{Theory on Brontosaurs}
\author{Miss Ann Elk}
\keywords{Brontosaurs,Monty Python,LaTeX is fun}
\begin{document}
\maketitle%
Lorem ipsum
\end{document}
请注意,在许多类中\maketitle
重新定义\title
、和\author
等,使其实际上变为无。
答案2
第一次调用\hypersetup
要设置 PDF 文档属性的位置时,需要所有宏都存在,否则您会收到错误消息。因此,我的建议是确保所有这些新\insert...
宏都存在。为此,请添加
\providecommand{\insertauthor}{}
\providecommand{\inserttitle}{}
\providecommand{\insertfirstsupervisor}{}
\providecommand{\insertsecondsupervisor}{}
\providecommand{\insertinstitution}{}
\providecommand{\insertdegree}{}
\providecommand{\insertfaculty}{}
\providecommand{\insertdepartment}{}
\providecommand{\insertsubmitdate}{}
\providecommand{\insertkeywords}{}
到你的序言。其次,将 PDF 文档属性的设置延迟到文档末尾,使用
\AtEndDocument{
\hypersetup{
pdftitle = \inserttitle,
pdfkeywords = \insertkeywords,
pdfauthor = \insertauthor
}
}