1

The following piece of code typesets today's date according to the Hebrew calendar:

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

When compiled with XeLaTeX, this code produced:

Full Hebrew date

The part of this line that represents the year is Hebrew year. There are other formats for the Hebrew year that are in common use:

  • Without the apostrophe: Hebrew year without apostrophe after the initial letter. This format is used e.g. by ynet:

Ynet Hebrew date format

  • Without the initial letter as well as the following apostrophe: Hebrew date without the first letter. This format is used e.g. by Ha'aretz:

Ha'aretz Hebrew date format

How can I specify these alternative year formats? I'm particularly interested in the most succinct version, the one used by Ha'aretz.

9
  • One possibility is redefining polyglossia's hebrewcal.sty's \HebrewYearName macro. Another possibility is setting up a custom definition file (for polyglossia, or possibly datetime2 maybe) with all the options. Alternatively, someone may know a simple and plain solution. Alternatively, a manual solution for a one-off or short-term use, but presumably you want an automatic convertor and don't want to code up your own ifcase-type statement (inspired by the js, or however those pages do it).
    – Cicada
    Commented Aug 15, 2021 at 10:09
  • ynet just insert the date as text: <span>ז&#x27; באלול התשפ&quot;א</span>. So does ha'aretz: <span class="atm hk atn ato atp atq atr ats nv hq hr">ז׳ אלול תשפ״א</span>. So no calculation tips there.
    – Cicada
    Commented Aug 15, 2021 at 10:30
  • @Cicada: If you could possibly come up with a solution in the same vein as your answer here that'd be great.
    – Evan Aad
    Commented Aug 15, 2021 at 11:24
  • @Cicada: An acceptable solution would be to assume that there is exactly one letter preceding the apostrophe, and therefore the two alternatives can be obtained by removing the first, respectively the first 2, characters of the year.
    – Evan Aad
    Commented Aug 15, 2021 at 11:30
  • You could use a regex expression in expl3 syntax to do that.
    – Cicada
    Commented Aug 15, 2021 at 11:50

1 Answer 1

2

This answer is exclusively based on hebrewcal.sty (Hebrew calendar for polyglossia).

The current hebrew year is 5781. The abbreviated format (as used by Ha'aretz) is to quote only 781.

The code can deliver the full year or the short year format using the fullyear key.

In hebrewcal.sty the fullyear key is set to false by default, but the corresponding branch in the macro \HebrewYearName was not fully executed. (line #53 of hebrewcal.sty). I added a \relax to correct the problem.

Tested with xelatex with Arial fonts and lualatex with the New Computer Modern fonts.

z1

h

This is what a normal \today looked like:

x1

 %!TeX TS-program = xelatex

\documentclass{article}

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

\usepackage{fontspec}

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

\makeatletter   
\hebrewsetreg
\def\HebrewYearName#1{{%
        \@tempcnta=#1\divide\@tempcnta by 1000\multiply\@tempcnta by 1000
        \ifnum#1=\@tempcnta\relax % divisible by 1000: disambiguate
        \Hebrewnumeral{#1}\ (לפ"ג)%
        \else % not divisible by 1000
        \ifnum#1<1000\relax     % first millennium: disambiguate
        \Hebrewnumeral{#1}\ (לפ"ג)%
        \else%
        \ifnum#1<5000
        \Hebrewnumeral{#1}%
        \else%
        \ifnum#1<6000 % current millenium, print without thousands
        \@tempcnta=#1\relax
        \if@hebrew@fullyear\else\advance\@tempcnta by -5000\relax\fi % changed <<<<<<
        \Hebrewnumeral{\@tempcnta}%
        \else % #1>6000
        \Hebrewnumeral{#1}%
        \fi
        \fi
        \fi
        \fi}}

\makeatother

\newcommand{\ThisHebrewMonth}{%
\HebrewMonthName{\hebrewmonth}{\hebrewday}
}

\newcommand{\ThisHebrewYear}{%
\HebrewYearName{\hebrewyear}
}

\newcommand{\ThisHebrewDay}{%
\Hebrewnumeral{\hebrewday}
}

\newcommand{\HaToday}{%
\ThisHebrewDay\ThisHebrewMonth\ThisHebrewYear
}

\begin{document}
    
    \begin{english}     
        \bigskip    \hfill This day  
    \end{english}   
    
    \ThisHebrewDay
    
    \begin{english}     
        \bigskip    \hfill This month    
    \end{english}
    
    \ThisHebrewMonth
    
    \begin{english}     
        \bigskip    \hfill This year    
    \end{english}   
    
    \ThisHebrewYear
    
    \begin{english} 
        \bigskip  \hfill Today,  Ha'aretz way   
    \end{english}   
    
    \HaToday
    
\end{document}

Expanded answer

To cover some of the common formats for the Hebrew year I added 2 keys:

(1) fullyear = false/true. True= displays the present millennium (5). False: suppress the 5, but display the millennium if it is less than 5000.

(default=false => \setkeys{hebrew}{fullyear=false})

(2) firstapos = false/true. False= suppress the first apostrophe in a full year display.

(default=false => \setkeys{hebrew}{firstapost=false} )

The global default is \setkeys{hebrew}{firstapost=false, fullyear=false}

Keys can be placed anywhere and will affect the document from that point onwards.

The macro \HebrewYearName{<year>} accepts a numeric value for a year or \hebrewyear the current year.

Notes

The macro \@hebrew@@numeral controlling the first apostrophe is from babel-hebrewalph.def

The macro \HebrewYearName controlling the full or short format is from hebrewcal.sty

xx

 %!TeX TS-program = xelatex

\documentclass{article}

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

\usepackage{fontspec}

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

\makeatletter   
\hebrewsetreg

\define@boolkey{hebrew}[@hebrew@]{firstapost}[true]{}
\setkeys{hebrew}{firstapost=false}

\renewcommand*{\@hebrew@@numeral}[1]{%{% first apostrophe, from babel-hebrewalph.def
    \ifnum#1<\z@\space\xpg@warning{Illegal value (#1) for Hebrew numeral}%
    \else
    \@tempcnta=#1\@tempcntb=#1\relax
    \divide\@tempcntb by 1000
    \ifnum\@tempcntb=0\gim@nomil\@tempcnta\relax
    \else%
    \if@hebrew@firstapost%  
    {\@gim@apostfalse\@gim@finalfalse\@hebrew@numeral\@tempcntb}׳% 
    \else%
    \@gim@aposttrue\@gim@finalfalse\@hebrew@numeral\@tempcntb\relax% <<<<<<<<<<<
    \fi
    \multiply\@tempcntb by 1000\relax
    \advance\@tempcnta by -\@tempcntb\relax
    \gim@nomil\@tempcnta\relax
    \fi
    \fi
}
    
\def\HebrewYearName#1{{%{% full or short format, from hebrewcal.sty
        \@tempcnta=#1\divide\@tempcnta by 1000\multiply\@tempcnta by 1000
        \ifnum#1=\@tempcnta\relax % divisible by 1000: disambiguate
        \Hebrewnumeral{#1}\ (לפ"ג)%
        \else % not divisible by 1000
        \ifnum#1<1000\relax     % first millennium: disambiguate
        \Hebrewnumeral{#1}\ (לפ"ג)%
        \else%
        \ifnum#1<5000
        \Hebrewnumeral{#1}%
        \else%
        \ifnum#1<6000 % current millenium, print without thousands
        \@tempcnta=#1\relax
        \if@hebrew@fullyear\else\advance\@tempcnta by -5000\relax\fi % changed <<<<<<
        \Hebrewnumeral{\@tempcnta}%
        \else % #1>6000
        \Hebrewnumeral{#1}%
        \fi
        \fi
        \fi
        \fi}}   

\makeatother
    
\begin{document}    
        
\begin{english} 
    \bigskip  \hfill \small This year,  full format
\end{english}

\setkeys{hebrew}{firstapost=true, fullyear=true} 
\HebrewYearName{\hebrewyear} 

\begin{english} 
    \bigskip  \hfill \small 5781,  without apostrophe   
\end{english}

\setkeys{hebrew}{firstapost=false, fullyear=true} 
\HebrewYearName{5781} 

\begin{english} 
    \bigskip  \hfill \small Common usage (omitting thousands)
\end{english}

\setkeys{hebrew}{firstapost=false, fullyear=false} % default
\HebrewYearName{5781} \\

\end{document}
3
  • Thanks. I've accepted your answer, even though I don't understand your calculations and therefore can't verify that your code actually works as intended in all scenarios, but it works well today.
    – Evan Aad
    Commented Aug 16, 2021 at 6:38
  • 1
    @Evan Aad I expanded on my previous answer by adding two keys to set the three required formats for the Hebrew year. Commented Aug 16, 2021 at 22:09
  • Thanks. This is great.
    – Evan Aad
    Commented Aug 17, 2021 at 1:30

You must log in to answer this question.

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