10

I teach classes and in my notes I have "Fall 2015" during fall semester and "Spring 2016" during Spring semester. I can use

\the\year

for the year. But is there something like

\the\season

for Fall and Spring? And if so, how can I customize which months define the semester?

  • year is a count register, but season is a range of counter values actually – user31729 Feb 12 '16 at 19:22
  • 4
    Of course, all this breaks down if you want to get ahead of things and produce some notes for spring term in December, for instance. Seems that something like \newcommand\term{Spring 2015} is simple and easily changed for next term. Sometimes over-automation creates more work than it alleviates. – dedded Feb 12 '16 at 20:46
14

Without any extra package and providing support for northern or southern hemisphere:

\documentclass{article}

\newif\ifnorthernhemisphere
\northernhemispheretrue

\newcommand{\season}{%
  \ifnorthernhemisphere
  \ifcase\month
  \or Winter
  \or Winter
  \or Spring
  \or Spring
  \or Spring
  \or Summer
  \or Summer
  \or Summer
  \or Fall
  \or Fall
  \or Fall
  \or Winter
  \fi
  \else
  \ifcase\month
  \or Summer
  \or Summer
  \or Fall
  \or Fall
  \or Fall
  \or Winter
  \or Winter
  \or Winter
  \or Spring
  \or Spring
  \or Spring
  \or Summer
  \fi
  \fi
}



\begin{document}
Northern hemisphere

\the\month\ \season

\month=5
\the\month\ \season

\month=9
\the\month\ \season

Southern hemisphere

\month=2
\northernhemispherefalse
\the\month\ \season


\month=5
\the\month\ \season

\month=9
\the\month\ \season

\end{document}

enter image description here

Update Here's a variant with optional argument:

\documentclass{article}

\newif\ifnorthernhemisphere
\northernhemispheretrue

\newcommand{\season}[1][\month]{%
  \ifnorthernhemisphere
  \ifcase#1
  \or Winter
  \or Winter
  \or Spring
  \or Spring
  \or Spring
  \or Summer
  \or Summer
  \or Summer
  \or Fall
  \or Fall
  \or Fall
  \or Winter
  \fi
  \else
  \ifcase#1
  \or Summer
  \or Summer
  \or Fall
  \or Fall
  \or Fall
  \or Winter
  \or Winter
  \or Winter
  \or Spring
  \or Spring
  \or Spring
  \or Summer
  \fi
  \fi
}



\begin{document}
Northern hemisphere

\season


\season[5]


\season[9]

Southern hemisphere


\northernhemispherefalse
\season

\season[5]

\season[9]

\end{document}

**Another version -- with xparse and expl3 features:

\documentclass{article}


\usepackage{xparse}

\ExplSyntaxOn

\seq_new:N \g_default_spring_semester_seq
\seq_new:N \g_default_fall_semester_seq

\seq_new:N \g_spring_semester_seq
\seq_new:N \g_fall_semester_seq

\seq_set_from_clist:Nn \g_default_spring_semester_seq {1,2,3,4,5,6}

\NewDocumentCommand{\SetSpringSemesterMonths}{m}{%
  \seq_set_from_clist:Nn \g_spring_semester_seq {#1}
}

\NewDocumentCommand{\SetFallSemesterMonths}{m}{%
  \seq_set_from_clist:Nn \g_fall_semester_seq {#1}
}

\SetSpringSemesterMonths{1,2,3,4,5,6}
\SetFallSemesterMonths{7,8,9,10,11,12}

\NewDocumentCommand{\season}{}{%
  \seq_if_empty:NTF \g_spring_semester_seq 
  {\seq_set_eq:NN \l_tmpa_seq \g_default_spring_semester_seq}
  {\seq_set_eq:NN \l_tmpa_seq \g_spring_semester_seq}
  \seq_if_empty:NTF \g_fall_semester_seq {\seq_set_eq:NN \l_tmpb_seq \g_default_fall_semester_seq}
  {\seq_set_eq:NN \l_tmpb_seq \g_fall_semester_seq}
  \seq_if_in:NVTF \l_tmpa_seq {\month} {
    Spring%
  }{%
    \seq_if_in:NVTF \l_tmpb_seq {\month} {%
      Fall%
    }{}
  }
}

\ExplSyntaxOff

\begin{document}

\season

\end{document}
7

What about:

\documentclass{article}
\usepackage{ifthen}

\begin{document}

The term now is: \ifthenelse{\month<6}{Spring}{Fall} 

\end{document}

With the ifthen package you can build quite complex conditional text.

Obviously you have to adapt it to your case, but you can nest \ifthenelse and even use \month or \day in it to fine-tune the result.

The term now is: \ifthenelse{\month<9}{%
    \ifthenelse{\month<6}{Spring}{Summer}}%
    {Fall}

(this last suppose Spring term for Jan to May, Fall from Sep to Dec, and the rest Summer. YMMV)

  • The problem is that the spring occurs in different months in North/South hemisphere. – Sigur Feb 12 '16 at 19:24
  • 2
    @Sigur: That's hard to track from LaTeX unless there are geolocation tools in LaTeX ;-) – user31729 Feb 12 '16 at 19:27
  • @ChristianHupfer And what about TeX? You used TeX primitives in your answer, this has no connection to LaTeX. – wipet Feb 12 '16 at 19:36
  • @wipet: Fair point. I know, you find LaTeX horrible, especially mixing TeX and LaTeX, but in this case I found TeX much simpler. If I would kick out the LaTeX specific commands it would work with TeX too, I suppose – user31729 Feb 12 '16 at 19:43
  • The title only asks for this two mode output, but your test should be month<7. – Andrew Swann Feb 17 '16 at 8:08
7

Here is a solution

\documentclass{article}
\begin{document}
\ifnum\month<7
Spring
\else
Fall
\fi

\month=11
\ifnum\month<7
Spring
\else
Fall
\fi
\end{document}
  • This does assume that there's only Spring or Fall? ;-) – user31729 Feb 12 '16 at 20:33
  • 5
    This is what the OP ask for :-) – touhami Feb 12 '16 at 20:39
  • Oh my bad, it's in the title :/ – user31729 Feb 12 '16 at 20:41
7

Update: Crazier code, no properties list! :)

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn
\clist_new:N \g_season_clist
\bool_new:N \g_season_northenhemisphere_bool
\bool_gset_false:N \g_season_northenhemisphere_bool

\NewDocumentCommand { \getseason } { m } {
   \clist_item:Nn \g_season_clist {
    \int_mod:nn {
      \int_div_round:nn { #1 - 1 } { 3 } + \bool_if:NTF \g_season_northenhemisphere_bool { 3 } { 1 } 
    } { 4 } + 1
  }
}

\NewDocumentCommand { \setseasons } { m } {
  \clist_gset:Nn \g_season_clist { #1 }
}

\NewDocumentCommand { \northenhemisphere } { } {
  \bool_gset_true:N \g_season_northenhemisphere_bool
}

\NewDocumentCommand { \southernhemisphere } { } {
  \bool_gset_false:N \g_season_northenhemisphere_bool
}
\ExplSyntaxOff

\begin{document}

\setseasons{Spring,Summer,Fall,Winter}

\northenhemisphere
In the Northen Hemisphere, we have \getseason{\month}.

\southernhemisphere
In the Southern Hemisphere, we have \getseason{\month}.

\end{document}

Original attempt: Crazy code ahead! :)

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn
\clist_new:N \g_season_clist
\prop_new:N \g_season_prop

\prop_gput:Nnn \g_season_prop { 12 } { 4 }
\prop_gput:Nnn \g_season_prop { 1 } { 4 }
\prop_gput:Nnn \g_season_prop { 2 } { 4 }
\prop_gput:Nnn \g_season_prop { 3 } { 1 }
\prop_gput:Nnn \g_season_prop { 4 } { 1 }
\prop_gput:Nnn \g_season_prop { 5 } { 1 }
\prop_gput:Nnn \g_season_prop { 6 } { 2 }
\prop_gput:Nnn \g_season_prop { 7 } { 2 }
\prop_gput:Nnn \g_season_prop { 8 } { 2 }
\prop_gput:Nnn \g_season_prop { 9 } { 3 }
\prop_gput:Nnn \g_season_prop { 10 } { 3 }
\prop_gput:Nnn \g_season_prop { 11 } { 3 }

\bool_new:N \g_season_northenhemisphere_bool
\bool_gset_false:N \g_season_northenhemisphere_bool

\NewDocumentCommand { \getseason } { m } {
   \clist_item:Nn \g_season_clist {
    \int_mod:nn {
      \prop_item:Nn \g_season_prop { #1 } + \bool_if:NTF \g_season_northenhemisphere_bool { 3 } { 1 } 
    } { 4 } + 1
  }
}

\NewDocumentCommand { \setseasons } { m } {
  \clist_gset:Nn \g_season_clist { #1 }
}

\NewDocumentCommand { \northenhemisphere } { } {
  \bool_gset_true:N \g_season_northenhemisphere_bool
}

\NewDocumentCommand { \southernhemisphere } { } {
  \bool_gset_false:N \g_season_northenhemisphere_bool
}
\ExplSyntaxOff

\begin{document}

\setseasons{Spring,Summer,Fall,Winter}

\northenhemisphere
In the Northen Hemisphere, we have \getseason{\month}.

\southernhemisphere
In the Southern Hemisphere, we have \getseason{\month}.

\end{document}

The output:

Quack

One could add a babel hook to setup seasons names according to the current language or even use datetime to format any date, like, for example, \season\today. Hope it helps! :)

  • 8
    I should be writing my thesis instead, I should be writing my thesis instead, I should be writing my thesis instead, I should be writing my thesis instead... – Paulo Cereda Feb 12 '16 at 20:56
  • Ah, the solution from the southern hemisphere :-P – user31729 Feb 12 '16 at 20:57
  • @Christian: ducks do understand about seasons. :) – Paulo Cereda Feb 12 '16 at 20:58
  • And Black Foresters know how to upvote ... and now back to your thesis :-P – user31729 Feb 12 '16 at 20:59
  • The variables should be global, in my opinion. – egreg Feb 12 '16 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.