%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B.png)
次のようにするには、どのように[
すればいいでしょうか:]
\ref{myref}
[1.1]
これは動作しません:
\documentclass{article}
\usepackage[colorlinks=true,allcolors=blue]{hyperref}
\let\oldref\ref
\renewcommand{\ref}[1]{[\oldref{#1}]}
\begin{document}
\section{Section}
Why cannot include square brackets around cross references? \ref{S}
\subsection{Subsection\label{S}}
This is a subsection.
\end{document}
回答: をコメントアウトする\usepackage[colorlinks=true,allcolors=blue]{hyperref}
と動作します。しかし、 が必要ですhyperref
が、 は使いたくありません。amsmath
また、plastex の使用など、後で他のものと衝突する傾向があるため、パッケージを追加したくないのです。どうすればよいでしょうか?
答え1
hyperref
は の後のものを で再定義するので、 を次のように\begin{document}
延期することができます。renewcommand
\AfterBeginDocument
ノート:
- これは、星付きのバリアントでは機能しません
\ref*
。
コード:
\documentclass{article}
\usepackage{letltxmacro}
\usepackage[colorlinks=true,allcolors=blue]{hyperref}
\AtBeginDocument{%
\LetLtxMacro\oldref{\ref}%
\DeclareRobustCommand{\ref}[2][]{[\oldref#1{#2}]}%
}
\begin{document}
\section{Section}
Why cannot include square brackets around cross references? \ref{S}
\subsection{Subsection\label{S}}
This is a subsection.
\end{document}
答え2
私のコメントは回答のようですので、回答にアップグレードします。
を使用する代わりに\eqref
、前文に以下を記述します。
\usepackage{fncylab}
\labelformat{equation}{(#1)}
\ref
方程式のラベルに適用された は、通常は や のようにスタイル設定され、\eqref
がhyperref
使用されると、リンクは括弧を囲みます。
このテクニックは他の種類のラベルにも使用できますが、 にはバグがあるamsthm
ため、 の\newtheorem
形式で を使用すると\newtheorem{<new theorem>}[<old theorem>]{...}
、<new theorem>
には文字通りと同じカウンタ<old theorem>
、およびfncylab
(そして実際、cleverref
)は、それらを同じようにラベル付けします。回避策は、定理を定義した後、それらのカウンタも複製する必要があることです。
\usepackage{aliascnt}
\newaliascnt{<new theorem>}{<old theorem>}
\labelformat{<new theorem>}{...}
これは期待どおりに動作します。私は、自分が書くものすべてにおいて、多数のカウンターでこれを実行します。