if 문 테스트 관련 문제

if 문 테스트 관련 문제

if 문을 구현하는 데 문제가 있습니다. 오늘과 지금부터 5일이 같은 달에 속하는지 알고 싶습니다. 인쇄할 해당 월의 올바른 값을 얻었지만 두 숫자가 모두 같은지 테스트하려고 하면 작동하지 않습니다. 테스트는 항상 거짓입니다. 아마도 예상 결과를 저장하지 않는 \newcommand와 관련이 있을 것 같지만 해결 방법을 찾을 수 없습니다.


\documentclass{article}
\usepackage{advdate}

\makeatletter
\renewcommand\AdvanceDate[1][\@ne]{\global\advance\day#1 \FixDate}
\makeatother
\usepackage{ifthen}

\begin{document}
\SetDate[30/08/2020]

\newcommand{\dd}{{\AdvanceDate[0]\the\month}}
\newcommand{\ddo}{{\AdvanceDate[1]\the\month}}
\newcommand{\ddf}{{\AdvanceDate[5]\the\month}}


\today \quad is during month \dd \quad and tomorrow is during month \ddo \quad but we are still {\AdvanceDate[-1]\today}
\newline

\today \quad is during month \dd \quad and five days from now is during month \ddf \quad but we are still {\AdvanceDate[-5]\today}
\newline

"Today and tomorrow happen in the same month" is \ifthenelse{\equal{\dd}{\ddo}}{TRUE}{FALSE} and we are still \today
\newline

"Today and five days from now happen in the same month" is \ifthenelse{\equal{\dd}{\ddf}}{TRUE}{FALSE} but we are still {\AdvanceDate[-5]\today}

\end{document}

감사해요!

답변1

매크로는 \dd직접 전달하지 않지만 \the\month이를 달성하기 위해 여러 할당 지침을 수행합니다.

또한 에 전역 할당을 수행하고 싶지 않습니다 \day.

\documentclass{article}
\usepackage{advdate}
\usepackage{ifthen}

\newcommand{\ifsamemonthTF}[4]{%
  \begingroup % compute the first date's month
  \AdvanceDate[#1]%
  \edef\x{\endgroup\def\noexpand\firstincrementmonth{\the\month}}\x
  \begingroup % compute the first date's month
  \AdvanceDate[#2]%
  \edef\x{\endgroup\def\noexpand\secondincrementmonth{\the\month}}\x
  \ifthenelse{\firstincrementmonth=\secondincrementmonth}{#3}{#4}%
}
\newcommand{\dd}{{\AdvanceDate[0]\the\month}}
\newcommand{\ddo}{{\AdvanceDate[1]\the\month}}
\newcommand{\ddf}{{\AdvanceDate[5]\the\month}}

\begin{document}
\SetDate[30/08/2020]

\today\ is during month \dd\ and tomorrow is during 
month \ddo\ but we are still \today

\today\ is during month \dd\ and five days from now is during 
month \ddf\ but we are still \today

``Today and tomorrow happen in the same month'' is 
\ifsamemonthTF{0}{1}{TRUE}{FALSE} and we are still \today

``Today and five days from now happen in the same month'' is 
\ifsamemonthTF{0}{5}{TRUE}{FALSE} but we are still \today

\end{document}

여기에 이미지 설명을 입력하세요

관련 정보