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.
This is what a normal \today
looked like:
%!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
%!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}
polyglossia
'shebrewcal.sty
's\HebrewYearName
macro. Another possibility is setting up a custom definition file (forpolyglossia
, or possiblydatetime2
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 ownifcase
-type statement (inspired by the js, or however those pages do it).<span>ז' באלול התשפ"א</span>
. So does ha'aretz:<span class="atm hk atn ato atp atq atr ats nv hq hr">ז׳ אלול תשפ״א</span>
. So no calculation tips there.