![pgfkeys + hyperxmp + utf8 问题](https://linux22.com/image/468775/pgfkeys%20%2B%20hyperxmp%20%2B%20utf8%20%E9%97%AE%E9%A2%98.png)
我正在尝试定义一个命令,用于pgfkeys
处理多个选项。其中一些用于使用设置 pdf 中的元信息hyperxmp
。示例:
\documentclass{article}
\usepackage{pgfkeys}
\usepackage{hyperxmp}
\makeatletter
\pgfkeys{/example-title/entities/.cd,
subtitle/.initial={},
}
\def\example@title@params@set@keys#1{\pgfkeys{/example-title/entities/.cd,#1}}
\newcommand\titlecommand[2][]{%
\example@title@params@set@keys{#1}%
\pgfkeysgetvalue{/example-title/entities/subtitle}{\@example@title@subtitle}%
\hypersetup{pdfsubtitle={\@example@title@subtitle}}
\hypersetup{pdftitle=#1}
}
\makeatother
\begin{document}
\titlecommand[subtitle={Ìncrëdíblé cómplîcätêd látéx}]{Test}
File is not empty
\end{document}
当我通过 pgfkeys 传递 utf8 字符时,就会出现问题。标题(直接使用传递的字符串 #1)在 pdf 元数据中是正确的(例如使用“exiftool -a -G1 [filenamepdf]”):
[XMP-dc] Title : subtitle=Ìncrëdíblé cómplîcätêd látéx
但是当存储和检索字符串时,pgfkeys
我得到以下信息:
[XMP-prism] Subtitle : ÄncrëdÃblé cómplîcätêd látéx
我究竟做错了什么?
答案1
这是 hyperxmp 中的一个错误,它将字幕两次转换为 utf8。您应该报告此问题。作为替代方案,您可以使用 LaTeX-pdfmanagement:
\DocumentMetadata{}
\documentclass{article}
\usepackage{pgfkeys}
\usepackage{hyperref}
\makeatletter
\pgfkeys{/example-title/entities/.cd,
subtitle/.initial={},
}
\def\example@title@params@set@keys#1{\pgfkeys{/example-title/entities/.cd,#1}}
\newcommand\titlecommand[2][]{%
\example@title@params@set@keys{#1}%
\pgfkeysgetvalue{/example-title/entities/subtitle}{\@example@title@subtitle}
\hypersetup{pdfsubtitle={\@example@title@subtitle}}
\hypersetup{pdftitle={#2}}
}
\makeatother
\begin{document}
\titlecommand[subtitle={Ìncrëdíblé cómplîcätêd látéx}]{Test}
File is not empty
\end{document}