在 LaTeX 中设置作者或地址字符串变量
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
元数据会失败!使用 \Title 不匹配! \let 的参数有一个额外的 }.
LaTeX is a wonderful language for writing documents. With the hyperref
package and pdflatex
, you easily generate documents with metadata, a nice feature to get your documents referenced right on the web.
I often use templates like:
\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}
So far, it's well. My question pops out from the example: is there a way to define string variables in the header so that they can be passed as arguments to hyperref
and then to the frontmatter or to the text. Something like:
\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}
This fails for the \maketitle
part and for the hyperref
metadata with ! Use of \Title doesn't match ! Argument of \let has an extra }.
but also for including the keywords.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确的模板应如下所示:
编译良好,元数据在 pdf 阅读器中显示良好。
The correct template should look like:
Compiles fine and the metadata shows fine in the pdf reader.
尝试使用
\newcommand{\Author}{My name}
而不是\def
。Try using
\newcommand{\Author}{My name}
instead of\def
.