%EB%A5%BC%20%EC%B6%94%EA%B0%80%ED%95%98%EC%84%B8%EC%9A%94.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>}{...}
이는 예상대로 작동합니다. 나는 내가 쓰는 모든 것에서 많은 카운터를 사용하여 이 작업을 수행합니다.