在LaTeX中设置作者或地址字符串变量

med*_*duz 7 latex hyperref pdflatex

LaTeX是一种用于编写文档的精彩语言.使用hyperref软件包pdflatex,您可以轻松生成包含元数据的文档,这是一个很好的功能,可以在Web上引用您的文档.

我经常使用以下模板:

\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}
Run Code Online (Sandbox Code Playgroud)

到目前为止,它很好.我的问题从示例中弹出:有没有办法在标题中定义字符串变量,以便它们可以作为参数传递给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}
Run Code Online (Sandbox Code Playgroud)

这对于\maketitle零件和 hyperref元数据来说都是失败的,! Use of \Title doesn't match ! Argument of \let has an extra }.但也包括关键字.

med*_*duz 10

正确的模板应如下所示:

\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}
Run Code Online (Sandbox Code Playgroud)

编译正常,元数据在pdf阅读器中显示正常.