
我使用XeLaTeX
with fontspec
、polyglossia
和biblatex
packages hyperref
(等)將我的文件排版為\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= ...}
.
我在這裡缺少什麼?網站上有很多非常相似的問題,但似乎沒有一個能解決我的特定問題:
- 在 hyperref pdfinfo 中的作者姓名和標題中使用非 ASCII 字符,但我已經使用了
\hypersetup
- 我還嘗試創建一個沒有換行符的新變量,但錯誤似乎一直在傳播。
- 使用特殊字元的程式碼(例如
\040
應該是空格)不會產生任何差異。
- hyperref:pdftitle 和錯誤的字元編碼,同樣的論點。
- pdfinfo 似乎不起作用,同樣的論點再次出現。
- hyperref :打破 pdftitle 和其他欄位中的長行。
\textLF
並且\textCR
不能解決我的問題。 Foxit Reader 無法識別這些字符,而 Adobe Acrobat 和 Acrobat Reader 僅顯示第一行。我的問題在於hyperref
. - hyperref 的 pdftitle 中不顯示非 ascii 字元:「unicode」選項中存在錯誤?。就我而言,
\usepackage[pdfencoding=unicode]{hyperref}
不會改變任何事情。 - 讓 hyperref 從 \title 和 \author 取得 pdfinfo。不可否認,如果我使用
\usepackage[pdfusetitle]{hyperref}
則已\hypersetup
過時,換行符號會自動轉換為空格(對於 pdftitle)和逗號(對於 pdfauthor)。然而,如前所述,我想要靜態文字和 的組合\thetitle
,所以\hypersetup
是不可避免的。- 這個
\@title
方法沒有幫助,因為它已經被用來定義\thetitle
。
- 這個
這是我的 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}