我正在使用scrlttr2
,并且想用已经存在的 pdfinfo 元数据填充komavars
。
\documentclass[]{scrlttr2}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\setkomavar{subject}{Subject Line}
\setkomavar{fromname}{John Doe}
\setkomavar{fromaddress}{8, Valley Str\\
49584 Livingston}
\setkomavar{place}{Livingston}
\usepackage[pdftex]{hyperref}
%% use given komavars to populate pdfinfo vars:
\hypersetup{%
pdfinfo = {%
Author={\usekomavar{fromname}},
Subject={\usekomavar{subject}},
Keywords={KeyA, KeyB, KeyD},
Producer={Latex with scrlttr2, hyperref},
Creator={pdflatex}}}
\begin{document}
\begin{letter}{ACME Inc.\\123, Bull Str\\72348 Washington}
\opening{Dear Mr Miller}
\lipsum[1]
\closing{Sincerely, }
\end{letter}
\end{document}
生成的 pdf 看上去不错。
不幸的是,\usekomavar{subject}
没有进行插值,但是变量的名称被保留了。
在编译期间(使用pdflatex a-minimal.tex
)我收到以下警告:
`Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref) removing `\@ifnextchar' on input line 19.`
有人能幫助我嗎?
和我
答案1
来自文档:
\usekomavar
和命令\usekomavar*
与所有存在星号版本或可以采用可选参数的命令一样,不是完全可扩展的。
但是您可以使用可选参数来\usekomavar
用已经存在的信息填充 pdfinfo:
\newcommand\mypdfinfo[2]{\hypersetup{pdfinfo={#1=#2}}}
\usekomavar[\mypdfinfo{Author}]{fromname}
\usekomavar[\mypdfinfo{Subject}]{subject}
例子:
\documentclass[]{scrlttr2}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\setkomavar{subject}{Subject Line}
\setkomavar{fromname}{John Doe}
\setkomavar{fromaddress}{8, Valley Str\\
49584 Livingston}
\setkomavar{place}{Livingston}
\usepackage[pdftex]{hyperref}
%% use given komavars to populate pdfinfo vars:
\newcommand\mypdfinfo[2]{\hypersetup{pdfinfo={#1=#2}}}
\usekomavar[\mypdfinfo{Author}]{fromname}
\usekomavar[\mypdfinfo{Subject}]{subject}
\hypersetup{%
pdfinfo = {%
Keywords={KeyA, KeyB, KeyD},
Producer={Latex with scrlttr2, hyperref},
Creator={pdflatex}}}
\begin{document}
\begin{letter}{ACME Inc.\\123, Bull Str\\72348 Washington}
\opening{Dear Mr Miller}
\lipsum[1]
\closing{Sincerely, }
\end{letter}
\end{document}
结果: