
나는 현재 첫 번째 문서 클래스 파일(개인화된 이력서 클래스)을 작성하는 중이며, 내가 정확히 무엇을 하고 있는지 더 잘 이해하고 싶습니다. 그래서 지금은 다음과 같은 구조를 통해 변수에 값을 할당할 수 있는 명령을 설정하고 있습니다(이 단어가 실제로 사용해야 하는 단어인지는 확실하지 않음).
\newcommand{\institution}[1]{\def\@institution{#1}}
\newcommand{\datesattended}[1]{\def\@datesattended{#1}}
\newcommand{\degree}[1]{\def\@degree{#1}}
따라서 .tex 파일에서 사용자는 명령을 사용하여 \institution{University of Whatever}
"University of Everything"이라는 문자열을 에 저장할 수 있으며 \@institution
, 이 문자열은 나중에 다른 명령에 의해 클래스 파일 내에서 호출됩니다.
이 모든 것이 내가 원하는 대로 작동하지만 이제 출력을 제어하기 위한 몇 가지 조건식을 만들고 싶습니다. 마찬가지로, \education
문서에서 호출될 때 사용자가 이미 입력한 기관 이름, 참석 날짜, 학위 정보 등을 고려하여 이력서에 대한 교육 섹션의 형식을 지정하는 명령이 있습니다 . 클래스 파일에서 이를 설정하여 이러한 \@variable
변수가 정의되었는지 확인한 다음 정의된 변수와 비어 있는 변수에 따라 출력 형식을 다르게 지정할 수 있기 를 원합니다 .
주로 내 문제의 대부분은 정의가 무엇 \@variable
인지, 정의로 무엇을 할 수 있는지를 실제로 이해하지 못한다는 것입니다.
내가 달성하려는 전체 예는 다음과 같습니다(LaTeX/의사).
\newcommand{\showeducation}{%
\@institutionname -- \@degree
if \@datesattended is defined:
\newline \@datesattended
clear \@institutionname, \@datesattended, \@degree
}
따라서 \@datesattended
정의된 경우 이를 수용하도록 형식이 변경됩니다. 그렇지 않으면 명령이 해당 명령을 전달하고 제공된 정보를 인쇄합니다.
답변1
명령 에는 특별한 것이 없습니다 \@variable
. 이는 다른 작업을 수행하기보다는 콘텐츠를 저장하기 위한 매크로일 뿐입니다. 따라서 \ifdefined
(e-TeX) 프리미티브를 사용하여 정의되었는지 테스트하는 것이 가능합니다.
\documentclass[11pt,a4paper]{article}
\makeatletter
\newcommand{\@institutionname}{Ministry of Silly Walks}
\newcommand{\@degree}{Minster of Silly Walks}
%\newcommand{\@datesattended}{1969}
\newcommand{\showeducation}{%
\@institutionname\ -- \@degree
\ifdefined\@datesattended
\newline \@datesattended % Please use some 'better' setup here
\else
\let\@institutionname\relax
\let\@datesattended\relax
\let\@degree\relax
\fi
}
\makeatother
\begin{document}
\showeducation % Date should not be printed
\makeatletter
\newcommand{\@datesattended}{1969}
\makeatother
\showeducation % Now it should be printed, but the rest is \relax`ed
\end{document}
편집하다\ifdef
from etoolbox
패키지를 사용하여 동일한 작업을 수행할 수 있어야 합니다.
답변2
\newcommand[1]...
toks 레지스터를 사용하는 것 보다 더 나을 수도 있습니다 .
\newtoks\institution \newtoks\datesattended \newtoks\degree
사용자가 말한다면
\institution{Ministry of Silly Walks}
그런 다음 매크로에서 이 값을 다음과 같이 사용할 수 있습니다.
\the\institution
테스트가 필요한 경우 "변수" 값이 이미 설정되어 있으면 다음을 수행할 수 있습니다.
\if\relax\the\degree\relax The degree isn't set.\else The degree is set.\fi