0

I want to set hyperref to use my custom command for title & author.

\documentclass{article} % or report or book

\makeatletter

\newcommand{\titlul}[1]{% \newcommand{@titlul}{#1} }

\newcommand{\autor}[1]{% \newcommand{@autor}{#1} }

\newcommand{\dotitle}{% \begingroup \thispagestyle{empty}% \centering \vspace*{1cm} \ifcsname @titlul\endcsname {\Large\bfseries\sffamily @titlul\par}\smallskip \fi \ifcsname @autor\endcsname {\large\sffamily @autor\par}\vspace{.1cm} \fi \vspace{1cm} \endgroup }

\makeatother

\usepackage{hyperref}

\makeatletter \hypersetup{pdftitle={@titlul},pdfauthor={@autor}} % error % Undefined control sequence. % <argument> @titlul % l.40 ...tup{pdftitle={@titlul},pdfauthor={@autor}} % https://tex.stackexchange.com/questions/17218/make-hyperref-take-pdfinfo-from-title-and-author \makeatother

\titlul{Title here} \autor{Author here} \date{\today}

% start document \begin{document} \dotitle

\end{document}

Mafsi
  • 664

1 Answers1

1

Try this setup.

(Sumatra)

a

(Adobe Reader)

b

\documentclass{article} % or report or book

\makeatletter \newcommand{\titlul}[1]{% \newcommand{@titlul}{\Large\bfseries\sffamily #1} }

\newcommand{\autor}[1]{% \newcommand{@autor}{\large\sffamily #1}}

\newcommand{\dotitle}{% \begingroup \thispagestyle{empty}% \centering \vspace*{1cm} \ifcsname @titlul\endcsname% { @titlul\par}\smallskip% \fi \ifcsname @autor\endcsname% { @autor\par}\vspace{.1cm} \fi% \vspace{1cm} \endgroup }

\makeatother

\titlul{Title here} \autor{Author here} \date{\today}

\usepackage{hyperref}

\hypersetup{ pdftitle={\titlul\ }, pdfauthor={\autor\ Copyright \textcopyright\ \number\year\ }, pdfsubject={Subject I, Subject II}, pdfkeywords={keyOne; keyTwo; keyThree}, pdfcreator={Simon Dispa}, } % Set up

% start document \begin{document} \dotitle

\end{document}

Simon Dispa
  • 39,141
  • Can you please explain to me why putting titlul{bla} & autor{blabla} on last position gives me error and above hyperref package, not? – Mafsi Feb 24 '22 at 16:22
  • @Mafsi I am sorry but I do not understand the question. The setup of the package are different. For example, the spaces are important. – Simon Dispa Feb 24 '22 at 17:25
  • Please run this code and note that I put \titlul & autor below hyperreff https://pastebin.com/VwtnNVTJ I get
    \titlul #1->\newcommand {\@titlul
                                      }{\Large \bfseries \sffamily #1}
    l.38 }
         % Set up
    ?
    
    – Mafsi Feb 24 '22 at 18:32
  • @Mafsi I think you already discover the problem: \titlul{Title here} and \autor{Author here} should be place before \hypersetup. – Simon Dispa Feb 24 '22 at 21:15
  • Thanks, but as the first question I asked, I want to know why. – Mafsi Feb 25 '22 at 09:09
  • @Mafsi hyperref is not a passive package that loads and adds some commands that you may or may not use. Instead, when loaded, many commands of LaTeX and other packages are redefined and the .aux file is also changed.

    The general rule is to load it last. (There are exceptions: see https://tex.stackexchange.com/questions/1863/which-packages-should-be-loaded-after-hyperref-instead-of-before)

    In your case, it can't do its job if \title and \author weren't previously defined as the error message indicates

    – Simon Dispa Feb 25 '22 at 21:09