암호

암호

새 페이지에 이상한 동작이 있습니다.(그것이 아니라는 점을 지적해준 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

두 번째 실행 후에 얻은 결과는 다음과 같습니다.

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
}
  1. 그러면 메타데이터가 다음과 같이 aux 파일에 기록됩니다.

예를 들어

\mysetproducer{Tester Schmoe}
  1. 다음 실행에서는 즉시 aux를 구문 분석 \begin{document}하고 실행합니다.

예를 들어

 \mysetproducer{Tester Schmoe}

my@pdfproducer그러면 다음을 포함하는 명령이 생성됩니다.Tester Schmoe

예를 들어

 \expandafter\xdef\csname my@pdfproducer\endcsname{#1}}
  1. 매크로가 존재하는 경우 사용자 수준 명령은 \myproducer이 값을 가져옵니다(aux 파일이 생성된 후에만, 즉 적어도 한 번 실행한 후에).

예를 들어

\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}

관련 정보