带有外文数字的 tikz 日历

带有外文数字的 tikz 日历

我想用多语种的梵文数字表示日期数字。后者提供了\devanagaridigits{}数字转换功能,但简单地执行\devanagaridigits{\tikzdaytext}\pgfkeys{/tikz/day code= {...}}操作不起作用。

这是我的妈妈:

\documentclass{beamer}

\mode<presentation>
{    \usetheme{metropolis}    }

\geometry{verbose,papersize={160mm,90mm}}

\usepackage{fontsize,fix-cm}

\usepackage{polyglossia}
\newfontfamily\devanagarifontsf[Script=Devanagari]{NotoSansDevanagari}

\setmainlanguage{sanskrit}
\setmainfont[Script=Devanagari]{NotoSansDevanagari}
 
\usepackage{tikz}
\usetikzlibrary{calendar,fit}

\pgfkeys{/tikz/day code =
  {
    \node (lower right) at (0,0) [above left,font=\large] {
      \tikzdaytext};  
% here \devanagaridigits{\tikzdaytext} is not working

    \node (upper left) at (-\cellwidth,\cellheight)
    [below right,align=left,text width=\cellwidth-\pgflinewidth,
    font=\tiny,black] {};
    \node (lower left) at (-\cellwidth,0) {};
    \node[rounded corners, draw,
          fit=(lower right) (upper left) (lower left),
          inner sep=1mm] {};
  }
}

\pgfkeys{/tikz/inner sep = 0pt}
\pgfkeys{/tikz/day xshift=\cellwidth+2mm+2mm}
\pgfkeys{/tikz/day yshift=\cellheight+2mm+2mm}

\newlength{\cellheight}
\setlength{\cellheight}{5mm}
\newlength{\cellwidth}
\setlength{\cellwidth}{7mm}

\begin{document}
\begin{frame}{दिनदर्शिका}

  \begin{tikzpicture}
    \calendar (mycal) [dates=\year-10-29 to \year-11-2,
    day list right];
  \end{tikzpicture}

\end{frame}
\end{document}

答案1

默认\tikzdaytext值为速记 \%d-(最短表示,即没有前导零)默认情况下不可扩展。

您需要使用

  • \%d0或者\pgfcalendarcurrentday,一个只包含日期数字但带有前导零的宏,或者
  • \number\%d0\relax将数字转换为失去前导零的数字。

在第一种情况下,我们需要\%d0适当扩展(实际上是两次)

\expandafter\devanagaridigits\expanded{{\%d0}}

但我们不需要它\pgfcalendarcurrentday

代码

% !TeX TS-program = lualatex
\documentclass{beamer}
\mode<presentation>{\usetheme{metropolis}}
\geometry{verbose,papersize={160mm,90mm}}
\usepackage{fontsize,fix-cm}
\usepackage{polyglossia}
\newfontfamily\devanagarifontsf[Script=Devanagari]{NotoSansDevanagari}
\setmainlanguage{sanskrit}
\setmainfont[Script=Devanagari]{NotoSansDevanagari}
\usepackage{tikz}
\usetikzlibrary{calendar}
\tikzset{
  my calendar/.style={
    day list right,
    days={
      anchor=base, font=\large,
      text width=7mm-2*(\pgfkeysvalueof{/pgf/inner xsep}),
      align=right, text depth=+0pt,
      rounded corners, draw,
    },
    day xshift=7mm+4mm,
    day yshift=5mm+4mm,
  },
  use devanagari zerofill/.style={
    day text=\devanagaridigits{\pgfcalendarcurrentday}},
  use devanagari shortest/.style={
    day text=\devanagaridigits{\number\%d0\relax}},
}
\begin{document}
\begin{frame}{दिनदर्शिका}
\tikz\calendar[my calendar] (mycal) [
   dates=\year-10-29 to \year-11-2,
];

\tikz\calendar[my calendar, use devanagari zerofill] (mycal) [
   dates=\year-10-29 to \year-11-2,
];

\tikz\calendar[my calendar, use devanagari shortest] (mycal) [
   dates=\year-10-29 to \year-11-2,
];
\end{frame}
\end{document}

输出

在此处输入图片描述

相关内容