
新しいページで奇妙な動作が発生する(David Carlisle氏に、それが唯一のものではないことを指摘していただき感謝します\clearpage
)\hypersetup
これにより、ドキュメントの後半での操作が妨げられます。
新しいページの後にメタデータを生成するので、次回の実行のためにこのデータを何らかの方法で保存する必要があります。
詳細については、以下のデモをご覧ください。
コード
\documentclass{article}
\usepackage{fontspec} % typeset with xelatex
\usepackage{hyperref}
\newcommand\insertproducer{placeholder}
\hypersetup{pdfproducer=Tester Schmoe (set in preamble)}
\AtEndDocument{%
\renewcommand\insertproducer{Tester Schmidt (set in body just before end)}
\hypersetup{pdfproducer=\insertproducer}
}%
\begin{document}
\null
%\clearpage % <-- uncommenting this results in \hypersetup failure
\end{document}
pdfinfo test.pdf
出力(コメント付き\clearpage
)
期待される出力。
Creator: LaTeX with hyperref package
Producer: Tester Schmidt (set in body just before end)
CreationDate: Tue Jun 7 12:13:48 2016
Tagged: no
Pages: 1
Encrypted: no
Page size: 612 x 792 pts (letter)
File size: 2149 bytes
Optimized: no
PDF version: 1.5
pdfinfo test.pdf
出力(コメントなし\clearpage
)
予期しない出力です。
Creator: LaTeX with hyperref package
Producer: Tester Schmoe (set in preamble)
CreationDate: Tue Jun 7 12:16:44 2016
Tagged: no
Pages: 1
Encrypted: no
Page size: 612 x 792 pts (letter)
File size: 2138 bytes
Optimized: no
PDF version: 1.5
答え1
セットアップを簡素化する方法はいくつかあります。
\documentclass{article}
\usepackage{hyperref}
\hypersetup{pdfproducer=Tester Schmitty (set in preamble)}
\AtBeginDocument{%
\hypersetup{
pdfproducer = \myproducer,
}
}
\makeatletter
\newcommand*\myhypersetuptoaux[1]{% command to tell LaTeX to save the value for the next run
\AtEndDocument{%
\immediate\write\@auxout{\string\my@producer{#1}}%
}%
}
\newcommand*{\my@producer}[1]{\protected@xdef\myproducer{#1}}
\newcommand*{\myproducer}{% initial value
This baby needs extra TLC, run it again.%
}
\makeatother
\begin{document}
\null
\clearpage
\myhypersetuptoaux{Tester Schmoe}
\end{document}
pdfinfo
最初の実行後に得たものはこれです
Title:
Subject:
Keywords:
Author:
Creator: LaTeX with hyperref package
Producer: This baby needs extra TLC, run it again.
CreationDate: Thu Jun 9 09:17:16 2016
ModDate: Thu Jun 9 09:17:16 2016
Tagged: no
Form: none
Pages: 1
Encrypted: no
Page size: 612 x 792 pts (letter) (rotated 0 degrees)
File size: 8416 bytes
Optimized: no
PDF version: 1.5
2 回目の実行後に得られる結果は次のとおりです。
Title:
Subject:
Keywords:
Author:
Creator: LaTeX with hyperref package
Producer: Tester Schmoe
CreationDate: Thu Jun 9 09:20:39 2016
ModDate: Thu Jun 9 09:20:39 2016
Tagged: no
Form: none
Pages: 1
Encrypted: no
Page size: 612 x 792 pts (letter) (rotated 0 degrees)
File size: 8389 bytes
Optimized: no
PDF version: 1.5
答え2
AUX ファイル ソリューション
これは潜在的に単純化される可能性があり、弱点があるかもしれません。私は AUX ファイルの書き込み/読み取りの実験を始めたばかりです。
ドキュメントの早い段階で特定の項目を設定する必要があることに注意することが非常に重要です。
\hypersetup{
colorlinks=true,
linkcolor=red,
urlcolor=red,
hyperfootnotes=false,
hypertexnames,
bookmarks=true % Causes clash if hyperref parameters loaded before bookmark, because bookmark loads hyperref without any parameters
}
- これにより、メタデータが次のように aux ファイルに書き込まれます。
例えば
\mysetproducer{Tester Schmoe}
- 次の実行では
\begin{document}
、直後に aux を解析して実行します。
例えば
\mysetproducer{Tester Schmoe}
my@pdfproducer
これにより、次のようなコマンドが作成されます。Tester Schmoe
例えば
\expandafter\xdef\csname my@pdfproducer\endcsname{#1}}
- ユーザーレベルのコマンドは、
\myproducer
マクロが存在する場合にこの値を取得します(auxファイルが作成された後、つまり少なくとも1回実行された後のみ)。
例えば
\expandafter\ifx\csname my@pdfproducer\endcsname\relax This baby needs extra TLC, run it again.\else
\csname my@pdfproducer\endcsname\fi}
完全なコード
\documentclass{article}
\usepackage{fontspec} % typeset with xelatex
\usepackage{hyperref}
\usepackage{atveryend}
\hypersetup{pdfproducer=Tester Schmitty (set in preamble)}
\AtBeginDocument{%
\hypersetup{
pdfproducer = \myproducer{}
}
}
\makeatletter
\newcommand*\myhypersetuptoaux[1]{% command to tell LaTeX to save the value for the next run
%\AfterLastShipout{%
\immediate\write\@auxout{%
%\protected@write\@mainaux{}{%
\string\mysetproducer{#1}%
%}%
}%
%}%
}
\makeatother
\makeatletter
\newcommand*{\mysetproducer}[1]{% called by the aux file and creates command my@producer that expands to input of myhypersetuptoaux
\expandafter\xdef\csname my@pdfproducer\endcsname{#1}}
\makeatother
\makeatletter
\newcommand*{\myproducer}{% user-level command to retrieve value of my@pdfproducer
\expandafter\ifx\csname my@pdfproducer\endcsname\relax This baby needs extra TLC, run it again.\else
\csname my@pdfproducer\endcsname\fi}
% \@ifundefined{stored@#1}{???}{\csname stored@#1\endcsname}%
\makeatother
\begin{document}
\null
\clearpage
\myhypersetuptoaux{Tester Schmoe}
\end{document}