Hyperref: 脚注を含むすべてのリンクのフォントを変更する

Hyperref: 脚注を含むすべてのリンクのフォントを変更する

hyperrefによって生成されたすべてのリンクのフォントを、たとえば に変更したいと思いますsffamily。このために、パッケージを使用して、次のようにコマンドetoolboxにパッチを適用しました。\Hy@colorlink

\usepackage{etoolbox}
\makeatletter
\patchcmd{\Hy@colorlink}{\begingroup}{\begingroup\sffamily}{}{}%
\makeatother

これは、脚注を除くすべてのタイプのリンクで機能します。なぜそうなるのかはわかりません。便宜上、最小限の動作例を以下に示します。

ご協力をよろしくお願いいたします!

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{etoolbox}

% This throws an error
%\AtBeginDocument{%
%    \makeatletter
%    \patchcmd{\Hy@colorlink}{\begingroup}{\begingroup\sffamily}{}{}%
%    \makeatother
%}

\begin{document}
\makeatletter
\patchcmd{\Hy@colorlink}{\begingroup}{\begingroup\sffamily}{}{}%
\makeatother

\tableofcontents

\section{A section}\label{sec:toto}

\begin{enumerate}
    \item Pageref: page~\pageref{sec:toto}.
    \item All links have the new font except footnotes: One\footnote{One} two\footnote{Two} three.\footnote{Three}
\end{enumerate}

\end{document}

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

答え1

脚注マークを作成するための標準コマンドには、\normalfont コマンドが含まれています。これを削除すれば機能します。

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{etoolbox}
\makeatletter
 \AtBeginDocument{%
    \patchcmd{\Hy@colorlink}{\begingroup}{\begingroup\sffamily}{}{}%
    \patchcmd{\@makefnmark}{\normalfont}{\selectfont}{}{}%
}
\makeatother
\begin{document}

\tableofcontents

\section{A section}\label{sec:toto}

\begin{enumerate}
    \item Pageref: page~\pageref{sec:toto}.
    \item All links have the new font except footnotes: One\footnote{One} two\footnote{Two} three.\footnote{Three}
\end{enumerate}

\end{document}

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

関連情報