除非从地址字段中删除链接,否则以下最小示例无法编译\href
。信件的地址字段中怎么会有链接dinbrief
?
\documentclass{dinbrief}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\hypersetup{colorlinks,citecolor=gray,urlcolor=gray}
\newcommand{\mailto}[1]{\href{mailto:#1}{#1}}
\begin{document}
\address{
From me\\
\href{https://google.com/}{my website}
}
\begin{letter}{ To you }
\opening{Dear you,}
\closing{Best regards,}
Text
\end{letter}
\end{document}
这是从错误日志中提取的,它并不能帮助我找到修复方法:
! Undefined control sequence.
\hyper@linkurl ...tionraw >>}\relax \Hy@colorlink
\@urlcolor #1\Hy@xspace@en...
\@hyper@readexternallink ...se \hyper@hash #2\fi }
\fi \fi \fi \fi
\href@split ...2#$3\\$4->\hyper@@link {$1}{$2}{$4}
\endgroup
\@fromaddress ...{https://google.com/}{my website}
\ka@db@tsfromaddress ...raggedright \@fromaddress
\vss }\nointerlineskip \fi
\ka@db@placefromaddress ...t{\ka@db@tsfromaddress
\vss }\nointerlineskip
\opening ...} \fi \fi \fi \ka@db@placefromaddress
\ka@db@placewindowtics \ka...
l.16 \opening{Dear you,}
答案1
问题是 dinbrief 会覆盖核心命令,从而破坏 LaTeX 钩子。如果您使用当前的 LaTeX 执行此操作
\documentclass{dinbrief}
\AtBeginDocument{\newcommand\blub{Hallo!}}
\begin{document}
\blub
\end{document}
然后你会得到一个未定义的控制序列错误:
! Undefined control sequence.
l.14 \blub
例如,对于其他类,article
它可以编译成功。
hyperref 在 begindocument 钩子中执行各种代码,并且由于丢失链接命令不再正常工作。
这是无法从外部纠正的问题,而且它也会困扰您使用其他软件包。因此,除非 dinbrief 已更新(这不太可能,我们尝试联系了作者),否则建议使用其他软件来写信。
答案2
这个 hack 帮我编译了旧的 dinbrief 文档(在 之前添加\begin{document}
):
\makeatletter
\AddToHook{env/document/begin}{
\begingroup
\def\@bd@hook{\UseOneTimeHook{begindocument}}
\expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter\@preamblecmds\expandafter\expandafter\expandafter{\expandafter\@bd@hook\@preamblecmds}
\endgroup
}
\makeatother
就我而言,我必须使用pdfpagelabels=false
hyperref 选项......(这可能是可以修复的),但对于这里的示例来说这不是必需的:
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref,xcolor}
\hypersetup{colorlinks,citecolor=gray,urlcolor=gray}
\newcommand{\mailto}[1]{\href{mailto:#1}{#1}}
\makeatletter
\AddToHook{env/document/begin}{
\begingroup
\def\@bd@hook{\UseOneTimeHook{begindocument}}
\expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter\@preamblecmds\expandafter\expandafter\expandafter{\expandafter\@bd@hook\@preamblecmds}
\endgroup
}
\makeatother
\begin{document}
\address{
From me\\
\href{https://google.com/}{my website}
}
\begin{letter}{ To you }
\opening{Dear you,}
\closing{Best regards,}
Text
\end{letter}
\end{document}
(请注意,我还必须添加xcolor
,否则urlcolor=gray
会失败。)