3

I have a problem with the following code. Although I manage to write the number of the week in front of the corresponding Monday, I am unable to use this number to write if the week in question is a member of a given list of weeks.

\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} 
2
  • \cs_generate_variant:Nn should definitely go outside the code for the picture Commented Sep 24, 2017 at 10:58
  • 1
    \pgfcalendarcurrentweek doesn't expand to a number (it can't be used in an expansion context at all, it makes assignments), follow the model of \pgfcalendarcurrentyear-01-01}{\l_tmpb_int} and leave the result in a macro that you can use to expand to the week number Commented Sep 24, 2017 at 10:59

1 Answer 1

4

you need something that expands to an integer week number, not something that makes a complicated sequence of assignments and then finally typesets such a number.

One way is to follow the model of

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

where the value of the calculation is placed in a macro which can be used to expand to the number.

enter image description here

\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} 
2
  • \tl_set:Nx, not \cs_set:Npx; they're not interchangeable. Commented Sep 24, 2017 at 13:45
  • 2
    @egreg done, although you should just have been grateful I didn't use \edef Commented Sep 24, 2017 at 13:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.