Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up author or address string variables in LaTeX

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.

like image 767
meduz Avatar asked Feb 25 '10 17:02

meduz


People also ask

What is Maketitle in LaTeX?

The \maketitle command generates a title on a separate title page - except in the article style, where the title normally goes at the top of the first page. Information used to produce the title is obtained from the following declarations, which should precede the \maketitle command. \author. \date. \thanks.

How do you write variables in LaTeX?

the first step: the backslash and the name of the command to create other commands, i.e. \newcommand. the second step: the creation of a variable that, being a command, needs its backslash, i.e. \vbname (which means variablename)

How do I center a title in LaTeX?

If you want to center some text just use \centering . If you want to align it differently you can use the environment \raggedleft for right-alignment and \raggedright for left-alignment.


1 Answers

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.

like image 115
meduz Avatar answered Sep 23 '22 19:09

meduz