
나는 TeX/LaTeX 전문가가 아닙니다. 최근에 문서 끝에 표시할 '문제' 및 '해결책'에 관한 패키지를 작성했지만 해당 목적에만 국한되지는 않습니다. 이러한 동작을 달성하기 위해 다른 기능 중에서도 xkeyval
많은 주요 매크로와 부울 키가 포함된 패키지를 사용했습니다.
나는 더 나은 버전을 제공하고 기본적으로 비슷해 보이지만 몇 가지 플래그를 설정하고 지루한 LaTeX 코드 입력을 다음과 같은 짧은 명령으로 대체하는 수십 개의 주요 매크로 정의 줄과 부울 키 정의를 제거하고 싶습니다.
\GenerateBoolKey[true]{SomeKeys}{DummyBoolKey}
이는 마치 DummyBoolKey
가족에 속하는 부울 키를 정의해야 합니다 .SomeKeys
\define@boolkey{SomeKeys}{DummyBoolKey}[true]{%
\ifKV@SomeKeys@DummyBoolKey%
%Do something if true%
\else%
%Do something different if false%
\fi%
}%
문서 (버전 2.6b)에는 7페이지에 다음 과 같이 xkeyval
매크로가 정의되어 있다고 나와 있습니다.\ifKV@fam@key
\newif
글쎄, 위 명령을 작성하고 \ifKV
매크로를 사용하는 데 실패했습니다. 여기에 오류 메시지와 함께 컴파일하는 동안 실패하는 최소한의(비) 작동 예제가 있습니다.
! Too many }'s.
다음은 최소한의 예입니다.
\documentclass{minimal}
\usepackage{xkeyval}
\makeatletter
\providecommand{\GenerateBoolKey}[3][false]{%
\define@boolkey{#2}{#3}[#1]{%
\csname ifKV@#2@#3 \endcsname%
\typeout{true}% % Do something if true
\else%
\typeout{false}% % Do something different if false
\fi%
}% End of \define@boolkey
}% End of \providecommand
\makeatother
% Key Family is called SomeKeys
% Use a fake command for testing purposes
\providecommand{\DummyCommand}[1][false]{%
\setkeys{SomeKeys}{#1}%
% Do something useful inside this command...
}%
\begin{document}
\GenerateBoolKey{SomeKeys}{DummyBoolKey}%
\DummyCommand[DummyBoolKey=true]%
\end{document}
\newif
부울 테스트를 제공하기 위해 '래퍼' 코드를 사용하여 즉시 명령을 제공하려면 어떻게 해야 합니까 \ifKV
?
답변1
조건부 중첩에 문제가 있는 것 같습니다. 여기서 가장 좋은 접근 방식은 '직접' 이름을 강제로 확장하여 '손으로' 얻을 수 있는 것과 동일한 정의를 갖게 하는 것 같습니다.
\documentclass{article}
\usepackage{xkeyval}
\makeatletter
\providecommand{\GenerateBoolKey}[3][false]{%
\begingroup
\edef\x{\endgroup
\noexpand\define@boolkey{#2}{#3}[#1]{%
\expandafter\noexpand\csname ifKV@#2@#3\endcsname%
\noexpand\typeout{true}% % Do something if true
\noexpand\else%
\noexpand\typeout{false}% % Do something different if false
\noexpand\fi%
}% End of \define@boolkey
}% End of defintion of \x
\x
}% End of \providecommand
\makeatother
% Key Family is called SomeKeys
% Use a fake command for testing purposes
\providecommand{\DummyCommand}[1][false]{%
\setkeys{SomeKeys}{#1}%
% Do something useful inside this command...
}%
\begin{document}
\GenerateBoolKey{SomeKeys}{DummyBoolKey}%
\DummyCommand[DummyBoolKey=true]%
\end{document}
\x
이는 닫혀 있는 그룹 내부를 정의함으로써 작동합니다 .사용 \x
, 다른 항목을 확장하지 않고 이름을 강제로 확장합니다(따라서 \noexpand
s가 많이 표시됨).