Hyperref 'pdftitle' 和 'pdfauthor' 带有自定义标题和作者命令

Hyperref 'pdftitle' 和 'pdfauthor' 带有自定义标题和作者命令

我想设置hyperref为使用我的自定义命令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}

答案1

尝试这个设置。

(苏门答腊)

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}

相关内容