Hyperref pdftitle は改行を奇妙な方法で管理します

Hyperref pdftitle は改行を奇妙な方法で管理します

私は、、、パッケージ(など)XeLaTeXを使用して、文書を としてタイプセットします。 このパッケージは本当に素晴らしいのですが、非常に厄介なバグを見つけました。fontspecpolyglossiabiblatexhyperref\documentclass[11pt,a4paper]{article}hyperref

pdftitle静的テキストと以前に定義した変数の組み合わせを使用したいと思います\thetitle。ここまでは順調です。問題は、この変数に改行 ( \\) が含まれている場合に発生します。はhyperref改行を自動的に省略するだけのようですが、これを手動で制御できるようにしたいと考えています。

改行を削除するには、次のマクロを使用します\replacelinebreaks{}{}

% A macro to remove line breaks from any text #1 and replace them 
% with #2 (can be void). E.g.: \replacelinebreaks{\thetitle}{\ }. 
\newcommand{\replacelinebreaks}[2]{%
    \begingroup\def\\{#2}#1\endgroup}

(その功績は主に書式設定(改行など)を削除する簡単な方法。) このマクロは、 を除くドキュメント全体のどこでも正常に機能します\hypersetup{pdftitle= ...}

ここで何が欠けているのでしょうか? このサイトには似たような質問がかなりたくさんありますが、どれも私の特定の問題を解決してくれないようです:

これが私の MWE です:

% !BIB TS-program = biber
% !TeX program = xelatex
% !TeX encoding = UTF-8
% !TeX spellcheck = en_GB

\documentclass[11pt,a4paper]{article}
\usepackage{polyglossia}
\usepackage{hyperref}

\newcommand{\replacelinebreaks}[2]{\begingroup\def\\{#2}#1\endgroup}

\def\thetitle{Type the\\Minimum Working Example\\Title Here\\}      
\def\firstauthor{Abra}      % Only the first author 
\def\theauthor{\firstauthor %  Add all other authors (no spaces! Use "\\" and "%")
\\Ca%                   
\\Dabra%
} 

\begin{document}
\hypersetup{
    pdftitle    = MWE No.1 \space -- \replacelinebreaks{\thetitle}{\ },
    pdfauthor   = \replacelinebreaks{\theauthor}{; },
}

\begin{center}
    {\Huge\thetitle}
\end{center}
\end{document}

その結果は次のようになります:

ここに画像の説明を入力してください

この動作を理解して修正する手助けをしてください。そうすれば、\replacelinebreaksマクロを使用するか、他の方法で目的を達成することができます。ご協力いただければ幸いです。

答え1

hyperref がこのようなトークンを処理する方法はいつでも再定義できます。

\documentclass{article}
\usepackage{hyperref}

\newcommand\myvar{abc\\cde}

\pdfstringdefDisableCommands{\def\\{XXX}}
\hypersetup{pdftitle= abc\\ cde\myvar}

\begin{document}
blub

\end{document}

ここに画像の説明を入力してください

または、適切な場所で使用されるように変数を定義することもできます\texorpdfstring

\documentclass{article}
\usepackage{hyperref}

\newcommand\myvar{abc\texorpdfstring{\\}{XXX}cde}

\hypersetup{pdftitle= abcXXXcde\myvar}

\begin{document}
\myvar

\end{document}

関連情報