expl3 中的扩展问题

expl3 中的扩展问题

以下代码有问题。虽然我设法在相应的星期一前面写下星期数,但我无法使用此数字来表示所讨论的星期是否属于给定的星期列表。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{xparse,expl3}
\usetikzlibrary{calendar}
\usepackage[landscape,margin=.5cm]{geometry}

\ExplSyntaxOn
\NewDocumentCommand{\pgfcalendarcurrentweek}{}
{
    \pgfcalendardatetojulian{\pgfcalendarcurrentyear-01-01}{\l_tmpb_int}
    \int_eval:n{(\pgfcalendarcurrentjulian-\l_tmpb_int)/7+1}
}

\begin{document}

\seq_new:N\g_foo_weeks_seq
\seq_set_from_clist:Nn\g_foo_weeks_seq{36,38}

%Calendrier
\begin{tikzpicture}
    \calendar[
        dates=17-09-01 to 17-09-30,
        name=cal,
        execute~at~begin~day~scope=
        {
            % each day is shifted down according to the day of month
            \pgftransformyshift{-.5*\pgfcalendarcurrentday cm}
        },
        day~code=
        {
            \node[name=\pgfcalendarsuggestedname,every~day,shape=rectangle,minimum~height=.5cm, text~width =.5cm]{\tikzdaytext};
            \draw[anchor=west] (0,3pt) node{\pgfcalendarweekdayshortname{\pgfcalendarcurrentweekday}};
            \ifdate{Monday}
            {
                \node[circle,gray,inner~sep=0,anchor=east] at (-.7cm,3pt) {\pgfcalendarcurrentweek};
            }{}

            % The following part does not work as I intend
            \ifdate{Tuesday}
            {
                \cs_generate_variant:Nn\seq_if_in:NnTF {NfTF}
                \seq_if_in:NxTF\g_foo_weeks_seq\pgfcalendarcurrentweek
                {
                    \node[circle,gray,inner~sep=0,anchor=east] at (-.7cm,3pt) {Yes};
                }
                {
                    \node[circle,gray,inner~sep=0,anchor=east] at (-.7cm,3pt) {No};
                }
            }
        }
    ];
\end{tikzpicture}
\ExplSyntaxOff

\end{document}

答案1

你需要一些扩展为整数周数,而不是进行一些复杂的赋值序列,然后最终排版这样的数字。

一种方法是遵循

\pgfcalendardatetojulian{\pgfcalendarcurrentyear-01-01}{\l_tmpb_int}

其中计算的值放在一个宏中,可以用来扩展为数字。

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{xparse,expl3}
\usetikzlibrary{calendar}
\usepackage[landscape,margin=.5cm]{geometry}
\errorcontextlines1000
\ExplSyntaxOn
\NewDocumentCommand{\pgfcalendarcurrentweek}{}
{
    \pgfcalendardatetojulian{\pgfcalendarcurrentyear-01-01}{\l_tmpb_int}
    \tl_set:Nx\l_current_week_int{\int_eval:n{(\pgfcalendarcurrentjulian-\l_tmpb_int)/7+1}}
}

                \cs_generate_variant:Nn\seq_if_in:NnTF {NfTF}

\begin{document}

\seq_new:N\g_foo_weeks_seq
\seq_set_from_clist:Nn\g_foo_weeks_seq{36,38}

%Calendrier
\begin{tikzpicture}
    \calendar[
        dates=17-09-01 to 17-09-30,
        name=cal,
        execute~at~begin~day~scope=
        {
            % each day is shifted down according to the day of month
            \pgftransformyshift{-.5*\pgfcalendarcurrentday cm}
        },
        day~code=
        {
         %   \node[name=\pgfcalendarsuggestedname,every~day,shape=rectangle,minimum~height=.5cm, text~width =.5cm]{\tikzdaytext};
          %  \draw[anchor=west] (0,3pt) node{\pgfcalendarweekdayshortname{\pgfcalendarcurrentweekday}};
            \ifdate{Monday}
            {
                \node[circle,gray,inner~sep=0,anchor=east] at (-.7cm,3pt) {
\pgfcalendarcurrentweek
\l_current_week_int
                };
            }{}
            % The following part does not work as I intend
            \ifdate{Tuesday}
            {
\pgfcalendarcurrentweek
                \seq_if_in:NxTF\g_foo_weeks_seq\l_current_week_int
                {
                    \node[circle,gray,inner~sep=0,anchor=east] at (-.7cm,3pt) {Yes (\l_current_week_int)};
                }
                {
                    \node[circle,gray,inner~sep=0,anchor=east] at (-.7cm,3pt) {No (\l_current_week_int)};
                }
            }
        }
    ];
\end{tikzpicture}
\ExplSyntaxOff

\end{document}

相关内容