2010-02-25 31 views
7

LaTeX是寫文檔的絕妙語言。使用hyperref包和pdflatex,您可以輕鬆生成帶有元數據的文檔,這是一個很好的功能,可以在Web上正確引用文檔。在LaTeX中設置作者或地址字符串變量

我經常使用像模板:

\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一部分,並與! Use of \Title doesn't match ! Argument of \let has an extra }.hyperref元數據也爲包括關鍵字。

+1

我相信在這種情況下,'\ def \ Title'作爲參數定界符(儘管我不確定它是否允許使用無參數宏)。這意味着你必須調用'\ Title ='而不是普通的'\ Title'。 '\ Title ='也可以工作(分隔符不是名稱的一部分)。但它不會具有(可能是預期的)任務的意義。 – 2010-02-25 17:57:36

+0

謝謝,我糾正了錯字!問題總共打開了15分鐘! – meduz 2010-02-25 18:21:22

+0

我投票結束這個問題作爲題外話,因爲這個問題不能在現代發行版中重現。 – Werner 2015-08-05 00:18:50

回答

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} 

編譯罰款和元數據顯示在pdf閱讀器的罰款。

2

嘗試使用\newcommand{\Author}{My name}而不是\def

+0

這應該沒有什麼區別。 – Werner 2015-08-05 16:24:05