latex3 / latex3/hyperref

\Hy@DisableOption in \PDF@FinishDoc is local, hence do nothing

Open
#97 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TeX
Stars
205
Forks
41
PR merge metrics
No merged PRs in 30d

Description

Currently, hyperref, at the time of first page break, uses \PDF@FinishDoc to set PDF info fields like pdftitle and make related options disable. After that, any key-val setting to options like pdftitle will not influence the corresponding field in the output PDF, and should raise warning \Hy@WarnOptionDisabled.

But, since

  • the \PDF@FinishDoc is executed inside commands of atbegshi package, and
  • the \define@key (provided by keyval package) used by \Hy@DisableOption only locally (re)defines key,

options like pdftitle are never disabled, hence usages after first page break won't raise any warning.

Following is a quick fix (with test by showing the meaning of \KV@Hyp@pdftitle) by providing global variant of \define@key and using it inside \PDF@FinishDoc.

  • Without fix, \KV@Hyp@pdftitle is not redefined after the first page break.
  • With the fix, \KV@Hyp@pdftitle is redefined as desired and warning \Hy@WarnOptionDisabled is raised after the first page break.
\documentclass{article}
\usepackage{hyperref}
\hypersetup{pdftitle={preamble}}

\makeatletter
%% redifined to use \define@key@g
\def\Hy@DisableOption#1{%
  \ltx@ifundefined{KV@Hyp@#1@default}{%
    \define@key@g{Hyp}{#1}%
  }{%
    \define@key@g{Hyp}{#1}[]%
  }%
  {\Hy@WarnOptionDisabled{#1}}%
}

%% add \global version of \defin@key
\def\define@key@g#1#2{%
  \@ifnextchar[{\KV@def@g{#1}{#2}}{\global\long\@namedef{KV@#1@#2}####1}}

%% add \global version of \KV@def
\def\KV@def@g#1#2[#3]{%
  \global\long\@namedef{KV@#1@#2@default\expandafter}\expandafter
  {\csname KV@#1@#2\endcsname{#3}}%
  \global\long\@namedef{KV@#1@#2}##1}
\makeatother
\listfiles


\begin{document}
%% this one succeeds in changing the Title field
\hypersetup{pdftitle={before first newpage}}
a
\newpage

%% with fix, this one raises warning
\hypersetup{pdftitle={after first newpage}}

%% check meaing of \KV@Hyp@pdftitle
\makeatletter
\ttfamily
\meaning\KV@Hyp@pdftitle
\makeatother
\end{document}

This issue is first reported, in Chinese, in https://github.com/CTeX-org/forum/issues/42.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace \PDF@FinishDoc, \Hy@DisableOption, and the key definitions from keyval and atbegshi to identify where local scoping prevents the option handler from being replaced. Use the minimal document in the issue to compare \KV@Hyp@pdftitle before and after the first page break; done means the handler is disabled globally and \Hy@WarnOptionDisabled is raised afterward.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, tex
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.