以下代码根据希伯来历法排版了今天的日期:
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\usepackage{fontspec}
\setmainfont{Arial}
\setmonofont{Arial}
\setsansfont{Arial}
\usepackage[useregional]{datetime2}
\begin{document}
\today
\end{document}
当使用 进行编译时XeLaTeX
,此代码产生:
- 没有撇号:. 这种格式例如用于伊奈特:
- 没有首字母以及以下撇号:. 这种格式例如用于国土报:
我该如何指定这些替代年份格式?我对最简洁的版本特别感兴趣,即《国土报》使用的版本。
答案1
这个答案完全基于hebrewcal.sty
(多语种的希伯来日历)。
当前的希伯来年份是 5781。缩写格式(如 Ha'aretz 所用)仅引用 781。
代码可以使用fullyear
密钥提供完整年份或短年份格式。
在hebrewcal.sty
键中默认fullyear
设置为false
,但宏中的相应分支
\HebrewYearName
未完全执行。(第 53 行hebrewcal.sty)
。我添加了一个\relax
来纠正这个问题。
使用带有 Arial 字体的 xelatex 和带有 New Computer Modern 字体的 lualatex 进行了测试。
正常\today
情况下是这样的:
%!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}
扩展答案
为了涵盖希伯来年份的一些常见格式,我添加了 2 个键:
(1) fullyear = false/true
. True= 显示当前千年 (5)。 False: 隐藏 5,但如果千年小于 5000,则显示千年。
(默认=false => \setkeys{hebrew}{fullyear=false}
)
(2)firstapos = false/true
. False= 隐藏全年显示中的第一个撇号。
(默认=false => \setkeys{hebrew}{firstapost=false}
)
全局默认值是\setkeys{hebrew}{firstapost=false, fullyear=false}
密钥可以放在任何地方,并且从那时起就会影响文档。
该宏\HebrewYearName{<year>}
接受年份或\hebrewyear
当前年份的数值。
笔记
控制第一个撇号的宏\@hebrew@@numeral
来自babel-hebrewalph.def
控制完整或简短格式的宏\HebrewYearName
来自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}