5

I'd like to typeset today's month and year, where "today" is determined automatically. However, I'd like to do so using polyglossia's Hebrew locale. I've tried to adapt this answer as follows:

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\usepackage{fontspec}
\setmainfont{Arial}
\setmonofont{Arial}
\setsansfont{Arial}
\usepackage[useregional]{datetime2}
\DTMlangsetup[he]{showdayofmonth=false}
\begin{document}
\today
\end{document}

However, this prints the day of the month (I used XeLaTeX):

Hebrew date with day-of-month

Instead of the desired:

Hebrew date without day-of-monty

* The package datetime2-hebrew is installed in my TeX installation.

2 Answers 2

2

Multiple things are intertwining.

With the current code setup, datetime2 is ignoring the option:

Package datetime2 Warning: Region `he' has ignored 
(datetime2)                the following settings:
(datetime2)                showdayofmonth=false

and polyglossia is calculating the date via hebrewcal.sty where the output routine hard-codes the day number using a formatting command defined as:

\def\@FormatForHebrew#1#2#3{%
  \Hebrewnumeral{#1}~ב\HebrewMonthName{#2}{#3}~%
  \HebrewYearName{#3}}

To fix that, as a workaround, put the following code in the preamble, before \begin{document}:

\makeatletter
\def\@FormatForHebrew#1#2#3{%
  \HebrewMonthName{#2}{#3}~%
  \HebrewYearName{#3}}
\makeatother

so that \today produces this:

month year

Alternatively, to restrict the redefinition to a particular instance only, use braces { } and put the code in the body of the document with the \today command, such that

\today

{
\makeatletter
\def\@FormatForHebrew#1#2#3{%
  \HebrewMonthName{#2}{#3}~%
  \HebrewYearName{#3}}
\makeatother
\today
}

\today

produces this:

braced code

MWE

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}

\setmainfont{Arial}
\setmonofont{Arial}
\setsansfont{Arial}
\usepackage[useregional]{datetime2}
\DTMlangsetup[he]{showdayofmonth=false}

%%for global change:
%\makeatletter
%\def\@FormatForHebrew#1#2#3{%
%  \HebrewMonthName{#2}{#3}~%
%  \HebrewYearName{#3}}
%\makeatother

\begin{document}
\today

{
\makeatletter
\def\@FormatForHebrew#1#2#3{%
  \HebrewMonthName{#2}{#3}~%
  \HebrewYearName{#3}}
\makeatother
\today
}

\today
\end{document}

A longer-term solution will require deeper investigation, particularly as multi-way package interactions are involved.

5
  • Thaank you! Would you consider this a bug? Should I report it? If so, to which package should I address the bug report?
    – Evan Aad
    Commented Aug 14, 2021 at 8:41
  • 1
    Good question. It's an unintended result of independent packages interacting. Probably a feature request for polyglossia; datetime2-hebrew.ldf is assuming either \hebrewdate or \hebdate (I'm guessing one is polyglossia and one is babel) and datetime2 also issues the message about the option setting, so it looks like datetime2 is downstream.
    – Cicada
    Commented Aug 14, 2021 at 8:51
  • Could you elaborate please: what feature should I request from polyglossia's developers? In what way should they modify \hebrewdate?
    – Evan Aad
    Commented Aug 14, 2021 at 9:00
  • 1
    So that there is an option so that \today prints month and year, without the day. As in your question.
    – Cicada
    Commented Aug 14, 2021 at 9:02
  • 2
    It might be a useful long-term outcome if someone writes a standalone calendars package, rather than there being individual adhoc calculations going on in this package or that package.
    – Cicada
    Commented Aug 14, 2021 at 9:06
3

Perhaps a simpler solution.

(See also format the year)

a

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}

\usepackage{fontspec}
\setmainfont{Arial}
\setmonofont{Arial}
\setsansfont{Arial}
\usepackage[useregional]{datetime2}


\newcommand{\ToNoDay}{% just month and year
 \hebrewsetreg\HebrewMonthName{\hebrewmonth}{\hebrewday}~\HebrewYearName{\hebrewyear}}

\begin{document}
    
\begin{english} 
\bigskip \hfill TODAY 
\end{english}

\today
    
\begin{english} 
\bigskip    \hfill  MONTH
\end{english}   
    
\HebrewMonthName{\hebrewmonth}{\hebrewday} % It needs \today to be run earlier

\begin{english} 
    \bigskip    \hfill  YEAR
\end{english}   

\HebrewYearName{\hebrewyear} % It needs \today to be run earlier
    
\begin{english} 
\bigskip    \hfill  MONTH YEAR
\end{english}   

\ToNoDay % date without the day     

\end{document}
4
  • Can you explain the benefit of this solution over @cicada's?
    – einpoklum
    Commented Apr 26, 2022 at 20:21
  • @einpoklum It does not produce the warning and in my (sporadic) use the macros are easier to remember. Commented Apr 27, 2022 at 17:36
  • Ok, but - I would add this information to the answer, as it's not immediately clear why it's "simple".
    – einpoklum
    Commented Apr 27, 2022 at 20:02
  • @einpoklum simpler to understand and apply. No TeX, no hacks. Adjectives with qualifiers always carry bias. Commented Apr 27, 2022 at 20:18

You must log in to answer this question.

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