
제목에서 알 수 있듯이 현재 etoolbox의 조건 \ifboolexpr
설명을 사용하려고 하는데 \notblank
문제가 있습니다. 관련 코드는 다음과 같습니다.
\ifboolexpr{%
test {\notblank{\Temp@Temp@Text@a}} or %
test {\notblank{\Temp@Temp@Text@b}} or %
test {\notblank{\Temp@Temp@Text@c}} %
}%
{}{}%
그러나 많은 오류가 발생합니다. 이와 같은 것을 시도해도 더 잘 작동하지 않는 것 같습니다.
\ifboolexpr{%
test {\notblank{}} or %
test {\notblank{}} or %
test {\notblank{}} %
}%
{}{}%
문제 없이 사용할 수 있는 최대값은 다음과 같습니다(MWE로 제공됩니다. 내 문제를 재현하려면 해당 문을 대체하세요 \ifbookexpr
).
\documentclass[10pt,a4paper,titlepage,twoside,onecolumn]{report}
\RequirePackage{etoolbox}
\makeatletter
\def\Temp@Temp@Text@a{testa}
\def\Temp@Temp@Text@b{testb}
\def\Temp@Temp@Text@c{testc}
\makeatother
\begin{document}
\makeatletter
\ifboolexpr{%
test {} or %
test {} or %
test {} %
}%
{true}{false}%
\makeatother
\end{document}
그래서 내 질문은 다음과 같습니다
- 내가 도대체 뭘 잘못하고있는 겁니까 ?
- 어떻게 해결하나요?
답변1
etoolbox
인수 to \ifblank
및 to가 다음과 같은 상태 에 대한 문서 \notblank
입니다.~ 아니다퍼지는. 따라서 \notblank{\xyz}
의 정의에 관계없이 "true"를 반환합니다 \xyz
.
완전한 확장을 원한다면 명시적으로 요청해야 합니다. 예를 들어
\documentclass[10pt,a4paper,titlepage,twoside,onecolumn]{report}
\usepackage{etoolbox}
\begin{document}
\makeatletter
\def\Temp@Temp@Text@a{testa}
\def\Temp@Temp@Text@b{testb}
\def\Temp@Temp@Text@c{testc}
\begingroup\edef\x{\endgroup
\noexpand\ifboolexpr{%
test {\noexpand\notblank{\Temp@Temp@Text@a}} or
test {\noexpand\notblank{\Temp@Temp@Text@b}} or
test {\noexpand\notblank{\Temp@Temp@Text@c}}
}}\x{\typeout{true}}{\typeout{false}}%
\def\Temp@Temp@Text@a{}
\def\Temp@Temp@Text@b{}
\def\Temp@Temp@Text@c{}
\begingroup\edef\x{\endgroup
\noexpand\ifboolexpr{%
test {\noexpand\notblank{\Temp@Temp@Text@a}} or
test {\noexpand\notblank{\Temp@Temp@Text@b}} or
test {\noexpand\notblank{\Temp@Temp@Text@c}}
}}\x{\typeout{true}}{\typeout{false}}%
\makeatother
\end{document}
첫 번째 인스턴스는 를 반환 true
하고 두 번째 인스턴스는 를 반환합니다 false
.
답변2
패키지 catoptions
에는 추가 코드 없이도 필요한 것이 정확하게 포함되어 있습니다. \xifblankFT
수단비어 있지 않고 완전히 확장됨. \oifblankFT
, 의미 도 있습니다 .공백이 아닌 한 단계 확장됨.
\documentclass{report}
\usepackage{catoptions}
\def\vgap{\par\bigskip}
\begin{document}
\def\tempa{testa}
\def\tempb{testb}
\def\tempc{testc}
First test (true):
\ifexprTF{%
test {\xifblankFT{\tempa}} or
test {\xifblankFT{\tempb}} or
test {\xifblankFT{\tempc}}
}{
true
}{
false
}
\vgap
\def\tempa{}
\def\tempb{}
\def\tempc{}
Second test (false):
\ifexprTF{%
test {\xifblankFT{\tempa}} or
test {\xifblankFT{\tempb}} or
test {\xifblankFT{\tempc}}
}{
true
}{
false
}
\def\tempd{x}
\vgap
Third test (false):
\ifexprTF{%
( test {\xifblankTF{\tempa}} or test {\xifblankTF{\tempb}} )
and
( test {\xifblankFT{\tempc}} and test {\xifblankFT{\tempd}} )
}{
true
}{
false
}
\vgap
\def\tempe{00}
\newif\iftestbool
Fourth test (true):
\ifexprTF{%
( switch {tempe} or bool {testbool} )
and
( ( test {\xifblankTF{\tempc}} and not test {\xifblankTF{\tempd}} )
or
( test {\xifstrcmpTF\tempa\tempb} or not test {\ifxTF\tempc\tempd} )
)
}{
true
}{
false
}
\end{document}
이러한 유형의 부울 계산은 비용이 많이 듭니다. 이 주장을 확인하려면 추적 로그만 보면 됩니다. 훨씬 간단한 테스트로 99%의 시간을 수행할 수 있습니다. 예를 들어, \xifstrcmpFT
확장 가능하므로 경제적인 테스트가 있습니다.
\def\do#1{\ifx\do#1\relax\else+\xifstrcmpFT{#1}{}01\expandafter\do\fi}
\ifnum0=\numexpr0\do\tempa\tempb\tempc\tempd\do
true
\else
false
\fi