当文档类已加载选项时,如何将选项传递给 Hyperref?

当文档类已加载选项时,如何将选项传递给 Hyperref?

我想将特定选项传递给 moderncv 文档。

问题是选项已经被 moderncv 类 (debian 上的文件 /usr/share/texlive/texmf-dist/tex/latex/moderncv/moderncv.cls) 加载。

此 moderncv.cls 文件包含一个 hyperref 设置部分:

% hyper links (hyperref is loaded at the end of the preamble to pass options required by loaded packages such as CJK)
\newcommand*\pdfpagemode{UseNone}% do not show thumbnails or bookmarks on opening (on supporting browsers); set \pdfpagemode to "UseOutlines" to show bookmarks
\RequirePackage{url}
\urlstyle{tt}
\AtEndPreamble{
  \pagenumbering{arabic}% has to be issued before loading hyperref, as to set \thepage and hence to avoid hyperref issuing a warning and setting pdfpagelabels=false
  \RequirePackage[unicode]{hyperref}% unicode is required for unicode pdf metadata
  \hypersetup{
    breaklinks,
    baseurl       = http://,
    pdfborder     = 0 0 0,
    pdfpagemode   = \pdfpagemode,
    pdfstartpage  = 1,
    pdfcreator    = {\LaTeX{} with 'moderncv' package},
%    pdfproducer   = {\LaTeX{}},% will/should be set automatically to the correct TeX engine used
    bookmarksopen = true,
    bookmarksdepth= 2,% to show sections and subsections
    pdfauthor     = {\@firstname{}~\@lastname{}},
    pdftitle      = {\@firstname{}~\@lastname{}\notblank{\@title}{ -- \@title}{}},
    pdfsubject    = {Resum\'{e} of \@firstname{}~\@lastname{}},
    pdfkeywords   = {\@firstname{}~\@lastname{}, curriculum vit\ae{}, resum\'{e}}}}

我不想修改这个文件因为它会被更新删除。

我宁愿在我的 .tex 文档中输入超级设置选项,并希望它们覆盖 .cls 文件中描述的默认选项。

在我的 .tex 文档中,\hypersetup{}无法识别。如果我添加,则\usepackage{hyperref}因为LaTeX Error: Option clash for package hyperref.hyperref 被调用了两次(在 .cls 和 .tex 中)。以下是完整的日志:

The package hyperref has already been loaded with options:
  []
There has now been an attempt to load it with options
  [unicode]
Adding the global options:
  ,unicode
to your \documentclass declaration may fix this.

我添加了“unicode”,\documentclass[11pt,a4paper,roman,unicode]{moderncv}但仍然出现同样的错误。

答案1

您显示的代码正在加载 hyperref \AtEndPreamble{,因此您可以在此之前加载它(包括unicode避免冲突的选项)或\hypersetup在内部使用\AtEndPreamble,以便在 hyperref 加载后稍后执行

相关内容