7

LaTeX 是编写文档的绝佳语言。使用hyperref包 和pdflatex,您可以轻松地生成带有元数据的文档,这是一个很好的功能,可以让您的文档在网络上被引用。

我经常使用这样的模板:

\documentclass[11pt]{article}
\usepackage[pdftex, pdfusetitle,colorlinks=false,pdfborder={0 0 0}]{hyperref}%
\hypersetup{%
pdftitle={My title},%
pdfauthor={My name},%
pdfkeywords={my first keyword, my second keyword, more keywords.},%
}%
\begin{document}

\title{My title}
\author{My name}
\date{}
\maketitle

{\bf Keywords:} my first keyword, my second keyword, more keywords.%

My text is here...

\end{document}

到目前为止,一切都很好。我的问题从示例中跳出来:有没有办法在标题中定义字符串变量,以便它们可以作为参数传递hyperref给 frontmatter 或文本。就像是:

\documentclass[11pt]{article}
%-------definitions-----
\def\Author{My name}
\def\Title{My title}
\def\Keywords{my first keyword, my second keyword, more keywords.}
%--------------------------
\usepackage[pdftex, pdfusetitle,colorlinks=false,pdfborder={0 0 0}]{hyperref}%
\hypersetup{%
pdftitle={\Title},%
pdfauthor={\Author},%
pdfkeywords={\Keywords},%
}%
\begin{document}
\title{\Title}
\author{\Author}
\date{}
\maketitle

{\bf Keywords:} \Keywords %

My text is here...

\end{document}

这对于包含关键字的\maketitle部件和 hyperref元数据都失败了。! Use of \Title doesn't match ! Argument of \let has an extra }.

4

2 回答 2

13

正确的模板应如下所示:

\documentclass[11pt]{article}
%-------definitions-----
\newcommand{\Author}{My name} 
\newcommand{\Title}{My title}
\newcommand{\Keywords}{my first keyword, my first keyword, more keywords.}
%--------------------------
\usepackage[pdftex, pdfusetitle,colorlinks=false,pdfborder={0 0 0}]{hyperref}%
\hypersetup{%
pdftitle={\Title},%
pdfauthor={\Author},%
pdfkeywords={\Keywords},%
}%
\begin{document}
\title{\Title}
\author{\Author}
\date{}
\maketitle
{\bf Keywords:} \Keywords %

My text is here...

\end{document}

编译良好,元数据在 pdf 阅读器中显示良好。

于 2010-02-25T18:23:04.350 回答
2

尝试使用\newcommand{\Author}{My name}而不是\def.

于 2010-02-25T17:21:26.940 回答