TransWikia.com

Problem with a test in if statement

TeX - LaTeX Asked on March 9, 2021

I’m having trouble with the implementation of a if statement. I want to know if today and five days from now happen in the same month. I get the correct values of the corresponding month to print but when I want to test if both numbers are equal it does not work. The test is always false.
It probably has something to do with the newcommand that does not store the expected result or something like that but I cant find a workaround.


documentclass{article}
usepackage{advdate}

makeatletter
renewcommandAdvanceDate[1][@ne]{globaladvanceday#1 FixDate}
makeatother
usepackage{ifthen}

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

newcommand{dd}{{AdvanceDate[0]themonth}}
newcommand{ddo}{{AdvanceDate[1]themonth}}
newcommand{ddf}{{AdvanceDate[5]themonth}}


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}

Thanks!

One Answer

The macro dd does not directly deliver themonth, but does several assignment instructions in order to get at it.

You also don't want to do global assignments to day.

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

newcommand{ifsamemonthTF}[4]{%
  begingroup % compute the first date's month
  AdvanceDate[#1]%
  edefx{endgroupdefnoexpandfirstincrementmonth{themonth}}x
  begingroup % compute the first date's month
  AdvanceDate[#2]%
  edefx{endgroupdefnoexpandsecondincrementmonth{themonth}}x
  ifthenelse{firstincrementmonth=secondincrementmonth}{#3}{#4}%
}
newcommand{dd}{{AdvanceDate[0]themonth}}
newcommand{ddo}{{AdvanceDate[1]themonth}}
newcommand{ddf}{{AdvanceDate[5]themonth}}

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}

enter image description here

Correct answer by egreg on March 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP