![如何向 hypersetup 提供标题和作者变量?](https://linux22.com/image/341748/%E5%A6%82%E4%BD%95%E5%90%91%20hypersetup%20%E6%8F%90%E4%BE%9B%E6%A0%87%E9%A2%98%E5%92%8C%E4%BD%9C%E8%80%85%E5%8F%98%E9%87%8F%EF%BC%9F.png)
我尝试使用以下命令动态设置 pdf 元数据:
\def\date#1{\def\@date{#1}}
\def\author#1{\def\@author{#1}}
\def\title#1{\def\@title{#1}}
\def\subtitle#1{\def\@subtitle{#1}}
\def\location#1{\def\@location{#1}}
\def\thesisdirector#1{\def\@thesisdirector{#1}}
\def\thesiscodirector#1{\def\@thesiscodirector{#1}}
\def\discipline#1{\def\@discipline{#1}}
\def\doctoralschool#1{\def\@doctoralschool{#1}}
\def\doctoralschoolnumber#1{\def\@doctoralschoolnumber{#1}}
\def\nationalthesisnumber#1{\def\@nationalthesisnumber{#1}}
\makeatletter
\hypersetup{
final = true,
colorlinks = true,
urlcolor = blue,
citecolor = blue,
linkcolor = MidnightBlue,
unicode = true,
linktoc = section,
pdfauthor = {\@author},
pdfkeywords = {biocomputing, biotechnology, software , scientific},
pdftitle = {\@title},
pdfsubject = {Genomic expert annotation}
}
\makeatother
或这个
\makeatletter
\def\date#1{\def\@date{#1}}
\def\author#1{\gdef\@author{#1}\gdef\@@author{#1}}
\let\@@author\@empty
\def\title#1{\gdef\@title{#1}\gdef\@@title{#1}}
\let\@@title\@empty
\def\subtitle#1{\def\@subtitle{#1}}
\def\location#1{\def\@location{#1}}
\def\thesisdirector#1{\def\@thesisdirector{#1}}
\def\thesiscodirector#1{\def\@thesiscodirector{#1}}
\def\discipline#1{\def\@discipline{#1}}
\def\doctoralschool#1{\def\@doctoralschool{#1}}
\def\doctoralschoolnumber#1{\def\@doctoralschoolnumber{#1}}
\def\nationalthesisnumber#1{\def\@nationalthesisnumber{#1}}
\hypersetup{
final = true,
colorlinks = true,
urlcolor = blue,
citecolor = blue,
linkcolor = MidnightBlue,
unicode = true,
linktoc = section,
pdfauthor = {\@@author},
pdfkeywords = {biocomputing, biotechnology, software , scientific},
pdftitle = {\@@title},
pdfsubject = {Genomic expert annotation}
}
\makeatother
这段代码被放在所需包之后,放入我的 cls 文件中。
但那不成立:
You can't use `\spacefactor' in internal vertical mode. \maketitle
我同意你的观点,这是一个常见的错误。我发现了很多报告(一些参考:1,2)
但每次答案都没有MWE或者不起作用
谢谢你的光芒
答案1
解决了
问题是 hypersetup 声明位于所需包之后的 cls 文件中。在此位置定义了变量,但设置为其最终值。我将 hypersetup 语句移动到设置了 title 和 author 变量之后。这样就成功了。
在我的 cls 文件中
\RequirePackage[xetex]{hyperref}
\def\date#1{\def\@date{#1}}
\let\@date\@empty
\def\author#1{\def\@author{#1}}
\let\@author\@empty
\def\title#1{\def\@title{#1}}
\let\@title\@empty
\def\keywords#1{\def\@keywords{#1}}
\let\@keywords\@empty
进入主 tex 文件:
\author{blah}
\title{blah}
\makeatletter
\hypersetup{%
final = true,
colorlinks = true,
urlcolor = blue,
citecolor = blue,
linkcolor = MidnightBlue,
unicode = true,
linktoc = section,
pdflang = fr-FR,
pdfauthor = {\@author},
pdfkeywords = {\@keywords},
pdftitle = {\@title},
pdfsubject = {...}
}
\makeatother
\begin{document}
...