6

Is there a way to extract the 3 first letters of the current month in French but WITHOUT acented characters AND with the first letter capitalized - e.g. Fev for Février (February in english) - AND with 2 exceptions: Juillet = Jul and Juin = Jun (the third letter in the abbreviation correspond in reality to the fourth letter of the month for these 2 exceptions)?

So, for all 12 month I would like to obtain the following results: Jan,Fev,Mar,Avr,Mai,Jun,Jul,Aou,Sep,Oct,Nov,Dec.

It would be nice to have something like a \currentMonthAbbreviated command wich directly output the corresponding abreviation to the current month.

Is there a way to do it with datetime2 package or something else?

2 Answers 2

6

The datetime2 package provides \DTMfrenchshortMonthname, but defines it by

\newcommand*{\DTMfrenchMonthname}[1]{%
  \ifcase#1
  \or
  Janvier%
  \or
  F\protect\'evrier%
  \or
  Mars%
  \or
  Avril%
  \or
  Mai%
  \or
  Juin%
  \or
  Juillet%
  \or
  Ao\protect\^ut%
  \or
  Septembre%
  \or
  Octobre%
  \or
  Novembre%
  \or
  D\protect\'ecembre%
  \fi
}

and what you have to do is to redefine it according to your wish:

\renewcommand*{\DTMfrenchshortMonthname}[1]{%
  \ifcase#1\or
  Jan\or Fev\or Mar\or Avr\or Mai\or Jun\or
  Jul\or Aou\or Sep\or Oct\or Nov\or Dec\fi
}

On the other hand this can be completely independent of datetime2. You can define your own command

\ExplSyntaxOn
\NewExpandableDocumentCommand{\shortfrenchmonth}{m}
 {
  \int_case:nnF { #1 }
   {
    {1}{Jan}{2}{Fev}{3}{Mar}{4}{Avr}{5}{Mai}{6}{Jun}
    {7}{Jul}{8}{Aou}{9}{Sep}{10}{Oct}{11}{Nov}{12}{Dec}
   }
   {BAD MONTH NUMBER}
 }
\ExplSyntaxOff

Complete example:

\documentclass{article}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\shortfrenchmonth}{m}
 {
  \int_case:nnF { #1 }
   {
    {1}{Jan}{2}{Fev}{3}{Mar}{4}{Avr}{5}{Mai}{6}{Jun}
    {7}{Jul}{8}{Aou}{9}{Sep}{10}{Oct}{11}{Nov}{12}{Dec}
   }
   {BAD MONTH NUMBER}
 }
\ExplSyntaxOff

\begin{document}

\shortfrenchmonth{\month}

\shortfrenchmonth{7}

\end{document}

enter image description here

2
  • Perfect! Thanks a lot! BTW, I guess it's \ re newcommand*{\DTMfrenchshortMonthname} and not just \newco[..] ;-)
    – zetyty
    Commented Apr 28, 2022 at 9:43
  • @SylvainRigal Yes, of course!
    – egreg
    Commented Apr 28, 2022 at 10:40
6

Brute force:

\documentclass{article}

\newcommand{\frabbmonth}{\ifcase\month What?\or
    Jan\or Fev\or Mar\or Avr\or Mai\or Jun\or Jul\or
    Aou\or Sep\or Oct\or Nov\or Dec\else What?\fi}

\begin{document}

\frabbmonth

\end{document}

Explanation: \month contains the current month number in the range 1...12. So the \ifcase will select the correct abbreviation for the existing months, and give out "What?" if the number is out of range.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .