%20%EC%84%A4%EC%A0%95.png)
이 질문은 기본적으로 제가 1년 전에 게시한 두 가지 오래된 질문에 대한 후속 질문이지만 실제로는 이 질문에 대한 해결책을 찾으려고 노력한 결과입니다.
biblatex `printbibliography`에서 토글 사용
\if
명령문(의사 코드) 과 함께 키-값 설정이 포함된 명령을 사용하고 싶습니다.
\somekeycommand[\ifdisplay somekey=A \else someotherkey=B]
변수의 상태에 따라 일부 특정 키가 설정됩니다 \ifdisplay
.
불행히도 다양한 접근 방식 중 어느 것도 작동하지 않으며 심지어 \begingroup\edef\x{\endgroup\noexpand....}\x
트릭도 성공하지 못합니다.
참고하시기 바랍니다.~하지 않다사용하고 싶다
\ifdisplay
\somekeycommand[somekey=A]
\else
\somekeycommand[someotherkey=B]
\fi
실제는 \somekeycommand
패키지의 일부 코드이며 매크로는\setkeys
실패한 MWE는 다음과 같습니다.
\documentclass{article}
\usepackage{etoolbox}
\usepackage{xparse}
\usepackage{xkeyval}
\makeatletter
\define@key{myfam}{somekey}{%
\def\somekeyvalue{#1}%
}
\define@key{myfam}{someotherkey}{%
\def\somekeyothervalue{#1}%
}
\makeatother
\NewDocumentCommand{\somekeycommand}{+O{}}{%
\begingroup
\setkeys{myfam}{#1}%
\ifdef{\somekeyvalue}{%
Key was \somekeyvalue%
}{%
}%
\endgroup
}%
\newif\ifdisplay
\displayfalse
\begin{document}
\somekeycommand[somekey=A]
\edef\x{%
\expandafter\noexpand\csname ifdisplay\endcsname%
somekey=A%
\noexpand\else%
someotherkey=B%
\noexpand\fi%
}%
\somekeycommand[\x] % fails
\somekeycommand\expandafter[\x] % fails --> expands to [ \expanded value ]
\somekeycommand[\expandafter\begingroup\edef\x{%
\ifdisplay
somekey=A%
\else%
someotherkey=B%
\fi%
}\x] %% -> fails, prints someotherkey=B,
\expandafter\somekeycommand[\begingroup\edef\x{%
\noexpand\ifdisplay
somekey=A%
\noexpand\else%
someotherkey=B%
\noexpand\fi%
}\x] %% -> fails, prints someotherkey=B,
\end{document}
내 오래된 질문은 다음과 같습니다.
답변1
\setkeys
두 번째 인수는 확장되지 않습니다 . 당신이 무엇을 추구하는지 잘 모르겠지만 이것은 효과가 있습니다.
\documentclass{article}
\usepackage{etoolbox}
\usepackage{xparse}
\usepackage{xkeyval}
\makeatletter
\define@key{myfam}{somekey}{%
\def\somekeyvalue{#1}%
}
\define@key{myfam}{someotherkey}{%
\def\somekeyothervalue{#1}%
}
\makeatother
\NewDocumentCommand{\somekeycommand}{+O{}}{%
\begingroup
\setkeys{myfam}{#1}%
\ifdef{\somekeyvalue}
{Key was \somekeyvalue}
{\ifdef{\somekeyothervalue}{Other key was \somekeyothervalue}{}}%
\endgroup
}%
\newif\ifdisplay
\displayfalse
\begin{document}
\begingroup\edef\x{\endgroup\noexpand
\somekeycommand\expandafter[\ifdisplay somekey=A\else someotherkey=B\fi]%
}\x
\displaytrue
\begingroup\edef\x{\endgroup\noexpand
\somekeycommand\expandafter[\ifdisplay somekey=A\else someotherkey=B\fi]%
}\x
\end{document}