Thi*_*rry 26 latex stylesheet hyperref
我使用下面的代码在pdf文档属性中设置标题和作者.
\usepackage[pdftex]{hyperref}
\hypersetup{
pdftitle = {The documents title},
pdfauthor = {me}
}
Run Code Online (Sandbox Code Playgroud)
我希望通过将它放在样式表中来自动化(.sty)以下是我的尝试,但它不起作用.编译pdf(pdflatex)时出错.但是pdf文档属性仍然是空的.
\usepackage[pdftex]{hyperref}
\hypersetup{
pdftitle = {\@title},
pdfauthor = {\@author}
}
Run Code Online (Sandbox Code Playgroud)
我使用\ _title和\ _author变量来创建自定义标题页.所以我知道那些工作.
有什么建议?
grd*_*dev 28
如果你得到编译错误,我猜测问题就是@
角色.你需要用你的代码\makeatletter
和\makeatother
.另一个可能的问题是,在执行\title
和\author
命令之前执行此操作.一个很好的解决方法是使用\AtBeginDocument
,这将允许你把它放在你的序言中的任何地方.请注意,您必须先定义\title
和\author
信息\begin{document}
.
\documentclass{article}
\usepackage[pdftex]{hyperref}
\makeatletter
\AtBeginDocument{
\hypersetup{
pdftitle = {\@title},
pdfauthor = {\@author}
}
}
\makeatother
\title{Test title}
\author{Sam Author}
\begin{document}
\maketitle
\end{document}
Run Code Online (Sandbox Code Playgroud)
更新:将相关部分放在名为的样式文件中xxx.sty
:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{xxx}
\RequirePackage{hyperref}
\makeatletter
\AtBeginDocument{
\hypersetup{
pdftitle = {\@title},
pdfauthor = {\@author}
}
}
\makeatother
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12566 次 |
最近记录: |