我想排版今天的月份和年份,其中“今天”是自动确定的。但是,我想使用 polyglossia 的希伯来语语言环境来实现这一点。我尝试适应这个答案如下:
\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}
但是,这会打印出月份的日期(我使用了XeLaTeX
):
而不是期望的:
* 该包datetime2-hebrew
已安装在我的 TeX 安装中。
答案1
多种事物相互交织。
使用当前代码设置,datetime2
忽略该选项:
Package datetime2 Warning: Region `he' has ignored
(datetime2) the following settings:
(datetime2) showdayofmonth=false
并通过输出例程使用如下定义的格式化命令对日期进行硬编码polyglossia
来计算日期:hebrewcal.sty
\def\@FormatForHebrew#1#2#3{%
\Hebrewnumeral{#1}~ב\HebrewMonthName{#2}{#3}~%
\HebrewYearName{#3}}
为了修复此问题,作为一种解决方法,请将以下代码放在序言中,在之前\begin{document}
:
\makeatletter
\def\@FormatForHebrew#1#2#3{%
\HebrewMonthName{#2}{#3}~%
\HebrewYearName{#3}}
\makeatother
因此\today
产生了这样的结果:
或者,要将重新定义仅限制到特定实例,请使用括号{
}
并将代码与命令一起放在文档正文中\today
,例如
\today
{
\makeatletter
\def\@FormatForHebrew#1#2#3{%
\HebrewMonthName{#2}{#3}~%
\HebrewYearName{#3}}
\makeatother
\today
}
\today
产生这个:
平均能量损失
\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}
长期解决方案需要更深入的研究,特别是涉及多路包交互。
答案2
也许是一个更简单的解决方案。
(也可以看看格式化年份)
\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}