在 LaTeX 样式表中自动设置 pdftitle 和 pdfauthor
我使用下面的代码在 pdf 文档属性中设置标题和作者。
\usepackage[pdftex]{hyperref}
\hypersetup{
pdftitle = {The documents title},
pdfauthor = {me}
}
我想通过将其放入样式表(.sty)中来自动执行此操作,下面是我的尝试,但它不起作用。 pdf 编译(pdflatex)有错误。但 pdf 文档属性仍然为空。
\usepackage[pdftex]{hyperref}
\hypersetup{
pdftitle = {\@title},
pdfauthor = {\@author}
}
我使用 \@title 和 \@author 变量来创建自定义标题页。所以我知道这些有效。
有什么建议吗?
I use the code below to set the title and author in the pdf document properties.
\usepackage[pdftex]{hyperref}
\hypersetup{
pdftitle = {The documents title},
pdfauthor = {me}
}
I would like to automate this by putting it in a stylesheet (.sty) Below is my attempt, but it is not working. The pdf is compiled (pdflatex) with errors. But the pdf document properties remain empty.
\usepackage[pdftex]{hyperref}
\hypersetup{
pdftitle = {\@title},
pdfauthor = {\@author}
}
I use the \@title and the \@author variables to create a custom titlepage. So I know those work.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果出现编译错误,我猜问题出在
@
字符上。您需要将代码包装在\makeatletter
和\makeatother
中。另一个可能的问题是您在执行\title
和\author
命令之前执行此操作。一个很好的解决方法是使用\AtBeginDocument
,它允许您将其放置在序言中的任何位置。请注意,您必须在\begin{document}
之前定义\title
和\author
信息。更新:将相关部分放入名为
xxx.sty
的样式文件中:If you get compile errors, I'm guessing the problem is the
@
character. You need to wrap your code in\makeatletter
and\makeatother
. Another possible problem is that you do this before you execute the\title
and\author
commands. A nice fix for this would be to use\AtBeginDocument
, which would allow you to place this anywhere in your preamble. Note that you have to define the\title
and\author
information before\begin{document}
.UPDATE: Putting the relevant parts in a style file named
xxx.sty
:有一个包选项
pdfusetitle
,请参阅 让 hyperref 从 \title 和 \author 获取 pdfinfo。There is the package option
pdfusetitle
for it, see Make hyperref take pdfinfo from \title and \author.