Extract the Three First Letters of Current Month in French without Accented Characters

datedatetime2frenchstrings

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?

Best Answer

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