
다음 MWE는 다음으로 컴파일되지만 hyperref
다음으로는 컴파일되지 않습니다 nohyperref
.
\documentclass{article}
\usepackage{xifthen}
\usepackage{nohyperref} %with hyperref it compiles perfectly wihtout warnings
\newcommand{\f}[1]{
\ifthenelse{\equal{#1}{}}{f}{f(#1)}
}
\newcommand{\D}{\hyperref[eq:D]{\normalcolor D}}
\begin{document}
\begin{equation}\label{eq:D}
\f{\D}
\end{equation}
\end{document}
내가 교체하면 \ifthenelse{\equal{#1}{}}
적어도 \ifblank{#1}
컴파일되지만 여전히 오류가 발생합니다.
답변1
나는 당신이 잘못된 도구를 사용하고 있다는 인상을 받았습니다 \ifthenelse
. 어쨌든, \hyperref
튼튼하게 만들어라. 그러면 당신은 길을 갈 것이다.
\documentclass{article}
\usepackage{xifthen}
\usepackage{nohyperref} %with hyperref it compiles perfectly wihtout warnings
\MakeRobust{\hyperref}
\newcommand{\f}[1]{%
\ifthenelse{\equal{#1}{}}{f}{f(#1)}%
}
\newcommand{\D}{\hyperref[eq:D]{\normalcolor D}}
\begin{document}
\begin{equation}\label{eq:D}
\f{\D}
\end{equation}
\end{document}
답변2
패키지는 절대 안 써요nohyperref.
hyperref 패키지를 사용하여 하이퍼링크 켜기/끄기 사이를 전환하기 위해 일반적으로 내부에서만 수행되는 작업을 TeX에서 전역적으로 수행하도록 했습니다.하이퍼레프환경 NoHyper
; 북마크도 관리해야 합니다.
\documentclass{article}
\usepackage{xifthen}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% For turning off hyperlinks activate, %
%% for turning on hyperlinks turn into a comment %
%% the following line: %
\PassOptionsToPackage{bookmarks=false}{hyperref}\newcommand\ProbablySwitchOffHyperlinks{\NoHyper}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{hyperref}
\providecommand\ProbablySwitchOffHyperlinks{}%
\ProbablySwitchOffHyperlinks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\f}[1]{\ifthenelse{\equal{#1}{}}{f}{f(#1)}}
\newcommand{\D}{\hyperref[eq:D]{\normalcolor D}}
\begin{document}
\tableofcontents
\section{bla}
\section{blu}
\begin{equation}\label{eq:D}
\f{\D}
\end{equation}
\end{document}
답변3
\ifthenelse{\equal{#1}{}}...
매크로 정의의 ⟨대체 텍스트⟩에 있는 테스트는 \f
매개변수가 나타내는 인수가 토큰으로 구성되어 있는지 여부에 대한 테스트의 근사치로 의도된 것으로 보이며 #1
, 이를 처리하면 출력에 영역이 생성됩니다. 클릭 가능한 하이퍼링크로 만들 수 있는 파일(.pdf 파일 또는 .dvi 파일)입니다.
\DeclareRobustCommand{\D}
대신 수행하면 \newcommand{\D}
오류 메시지 없이 코드가 컴파일됩니다.
\documentclass{article}
\usepackage{xifthen}
\usepackage{nohyperref} %with hyperref it compiles perfectly wihtout warnings
\newcommand{\f}[1]{%
\ifthenelse{\equal{#1}{}}{f}{f(#1)}%
}
\DeclareRobustCommand{\D}{\hyperref[eq:D]{\normalcolor D}}
\begin{document}
\begin{equation}\label{eq:D}
\f{\D}
\end{equation}
\begin{equation}\label{eq:empty}
\f{}
\end{equation}
\end{document}
이 솔루션은 다른 패키지를 로드하지 않고 기존 매크로를 패치하지 않고도 작동합니다.
이 솔루션은 다음에도 효과적입니다.하이퍼참조를 금지하는 저널. ;-)
방정식의 구성 요소를 동일한 방정식의 수로 이어지는 하이퍼링크로 바꾸는 것은 실제 시나리오와 유사하지 않을 수 있지만 귀하의 예는 상황에 따라 명령 동작이 달라지는 것과 관련된 문제를 보여주기 위한 것입니다. 그들은 수행됩니다. (-test를 평가하는 동안 \ifthenelse
명령은 \hyperref
출력 파일(.dvi-file/.pdf-file) 내에서 하이퍼링크를 조판하고 생성하는 상황에서의 동작과 다른 방식으로 동작합니다.)
\ifthenelse{\equal{#1}{}}...
매크로 정의의 ⟨대체 텍스트⟩에 있는 테스트는 \f
매개변수가 나타내는 인수가 토큰으로 구성되어 있는지 여부에 대한 테스트의 근사치로 의도된 것으로 보이며 #1
, 이를 처리하면 출력에 영역이 생성됩니다. 클릭 가능한 하이퍼링크로 만들 수 있는 파일(.pdf 파일 또는 .dvi 파일)입니다.
\ifthenelse
로컬 범위 내의 다른 항목 아래에 있는 명령은 \let\equal\TE@equal
테스트 인수를 평가하는 동안 수행됩니다.
이 사실은 현재 매크로 인스턴스의 테스트 인수를 평가하는 상황에 있는지 여부 \ifthenelse
와 이 경우 수행할 수 없거나 필요하지 않은 토큰을 생략/제거하는지 여부에 따라 분기에 사용될 수 있습니다.
\documentclass{article}
\usepackage{xifthen, xcolor}
\usepackage{nohyperref}
\makeatletter
\newcommand\CheckWhetherCurrentlyEvaluatingIfthenelseTest{%
\ifx\equal\TE@equal\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
}%
\newcommand{\D}{%
\CheckWhetherCurrentlyEvaluatingIfthenelseTest{\@firstofone}{\hyperref[eq:D]}%
{\CheckWhetherCurrentlyEvaluatingIfthenelseTest{}{\normalcolor}D}%
}%
\makeatother
\newcommand{\f}[1]{\ifthenelse{\equal{#1}{}}{f}{f(#1)}}
\begin{document}
\color{blue}
\tableofcontents
\section{bla}
\section{blu}
\begin{equation}\label{eq:D}
\f{\D}
\end{equation}
\begin{equation}\label{eq:empty}
\f{}
\end{equation}
\end{document}
이 예는 다소 과잉입니다. 그러나 이는 확장/수행되는 상황에 따라 확장 가능한 명령이 어떻게 다른 작업을 수행하도록 설계될 수 있는지 보여줍니다.
불행하게도 LaTeX에는 상황 유형의 레퍼토리와 상황에 따른 명령 동작의 레퍼토리를 확장하는 것은 물론이고 현재 LaTeX가 어떤 종류의 상황에 있는지 언제든지 안정적으로 쿼리할 수 있는 "상황 관리"가 없습니다.