
-file에서 다음 명령을 사용하여 내용을 변경하는 두 개의 새로운 매크로와 명령을 정의합니다 .cls
.
\newcommand{\@mymacroa}{}
\newcommand{\mymacroa}[1]{\renewcommand{\@mymacroa}{#1}}
\newcommand{\@mymacrob}{}
\newcommand{\mymacrob}[1]{\renewcommand{\@mymacrob}{#1}}
이제 이들 중 하나(또는 둘 다)가 비어 있지 않은지(즉, 기본값에서 수정되었는지) 테스트하고 이들 중 하나에 내용이 있으면 해당 값을 인쇄하고 싶습니다. \ifthenelse
, \@ifnotmtarg
및 일반 TeX를 사용한 이전 시도는 \if
성공하지 못했습니다.
의사 코드에서 내가 달성하고 싶은 것은 다음과 같습니다.
\@ifnotmtarg{\@mymacroa}\or\@ifnotmtarg{\@mymacrob}
do {print some text and the macros which are non-empty}
답변1
이 데이터가 패키지에서 어떤 다른 방식으로 사용될지 알지 못한 채 이를 수행하는 가장 좋은 방법을 말하기는 어렵습니다. 특히 제가 패키지에 익숙하지 않기 때문입니다.계보 나무패키지.
이 경고를 사용하여 이를 수행하는 한 가지 방법은 및 \DateOfBirth
와 같은 \PlaceOfBirth
매크로에 저장할 수 있는 생년월일과 장소를 각각 설정하는 명령을 정의하는 것입니다 . 이 두 매크로의 기본값을 로 설정하면 이제 새 부울(예 : )을 정의하고 다음과 같은 것을 사용하여 둘 중 하나가 재정의되었는지 테스트할 수 있습니다 .\@dateofbirth
\@placeofbirth
\relax
\ifHaveDateOrPlace
% include the date and/or place of birth if available
\HaveDateOrPlacefalse% reset date and place boolean
\if\@dateofbirth\relax\else\HaveDateOrPlacetrue\fi
\if\@placeofbirth\relax\else\HaveDateOrPlacetrue\fi
\ifHaveDateOrPlace\gtrsymBorn \@placeofbirth \@dateofbirth \fi
물론 이미지 파일의 이름과 사람의 이름을 얻으려면 매크로가 필요할 수도 있지만 아마도 이러한 매크로는 이미 제공되어 있을 것입니다.계보 나무. 이를 사용하면 \MugShot
코드가 다음과 같이 매크로를 정의할 수 있습니다.
\MugShot
\PlaceOfBirth{Mars}
\MugShot
\DateOfBirth{Tuesday}
\MugShot
\PlaceOfBirth{Venus}
\DateOfBirth{Wednesday}
\MugShot
다음을 생산할 것입니다 :
(제 기본 사진은 물음표 입니다.)
이 MWE의 전체 코드는 라텍스 파일로 구성됩니다.
\documentclass{myclass}
\begin{document}
\MugShot
\PlaceOfBirth{Mars}
\MugShot
\DateOfBirth{Tuesday}
\MugShot
\PlaceOfBirth{Venus}
\DateOfBirth{Wednesday}
\MugShot
\end{document}
myclass.cls
모든 내용을 포함하는 클래스 파일과 함께 :
\LoadClass[12pt]{amsart}
\RequirePackage{genealogytree}
\RequirePackage{graphicx}
% boolean to keep track of place and date of birth
\newif\ifHaveDateOrPlace
% place of birth
\providecommand\@placeofbirth{\relax}
\newcommand\PlaceOfBirth[1]{\renewcommand\@placeofbirth{\space#1}}
% date of birth
\providecommand\@dateofbirth{\relax}
\newcommand\DateOfBirth[1]{\renewcommand\@dateofbirth{\space#1}}
\providecommand\@personpicture{{\Huge?}}
\newcommand\Picture[2][]{\edef\@personpicture{\noexpand\includegraphics[width=30mm,#1]{#2}}}
% reset the people data
\newcommand\ResetData{%
\renewcommand\@placeofbirth{\relax}%
\renewcommand\@dateofbirth{\relax}%
}
\newcommand\MugShot{%
\begin{tabular}{c}
\@personpicture\\
% include the date and/or place of birth if available
\HaveDateOrPlacefalse% reset date and place boolean
\if\@dateofbirth\relax\else\HaveDateOrPlacetrue\fi
\if\@placeofbirth\relax\else\HaveDateOrPlacetrue\fi
\ifHaveDateOrPlace\gtrsymBorn \@placeofbirth \@dateofbirth \fi
\end{tabular}%
\ResetData
}
\endinput
이 데이터가 한 번만 사용된다면 더 나은 접근 방식은 관련 데이터와 함께 사진을 인쇄하기 위한 단일 매크로를 정의하거나 다음과 같은 것을 사용하는 것입니다.pgfkeys키-값 구문을 사용하여 모든 것을 지정할 수 있습니다.