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

发布于 2024-08-22 23:07:19 字数 1343 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉南桥 2024-08-29 23:07:19

正确的模板应如下所示:

\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 阅读器中显示良好。

The correct template should look like:

\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}

Compiles fine and the metadata shows fine in the pdf reader.

与之呼应 2024-08-29 23:07:19

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

Try using \newcommand{\Author}{My name} instead of \def.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文