Como passar dias para o calendário tikz usando macros

Como passar dias para o calendário tikz usando macros

Gostaria de passar para o calendário alguns nomes de dias usando um comando pessoal, para que o usuário possa alterar os dias facilmente e criar um calendário pessoal.

Eu defini o comando \mydayscom um argumento, que é passado para list \mydayslist.

Como usar essa lista dentro do calendário?

MWE

\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}

\newcommand*{\mydays}[1]{%
 \def\mydayslist{#1}%
}
\mydays{Monday,Friday}

\begin{document}

I want to pass the days \mydayslist\ to the calendar.

\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [dates=2014-02-01 to 2014-07-last, month list, month label left,%
month text=\textcolor{black}{\%mt}, month yshift=1.7em, black!20]
%
if (Tuesday) [black] 
% if (\mydayslist) [black] %% <-- insert \mydayslist
;
\end{tikzpicture}

\end{document}

Responder1

Você pode usar as ifteclas para definir um estilo para testarumdia ( myifno meu exemplo). Então você pode usar um .expand oncemanipulador (ou .expandedmanipulador) para expandir sua macro e um .listmanipulador para aplicar sua lista.

\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}

\newcommand*{\mydays}[1]{%
 \def\mydayslist{#1}%
}
\mydays{Monday,Friday}

\begin{document}

I want to pass the days \mydayslist\ to the calendar.

\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]

\calendar (cal) [dates=2014-02-01 to 2014-07-last,month list,month label left,
month text=\textcolor{black}{\%mt},month yshift=1.7em, black!20,
myif/.style={if=(#1)[black]},
myif/.list/.expand once={\mydayslist},
];
\end{tikzpicture}

\end{document}

Primeira edição

Um exemplo com andcondição deCalendário TikZ e testes condicionais.

\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
% code from https://tex.stackexchange.com/a/141027/14500
\makeatletter
\def\pgfcalendar@matchesfalse{\global\let\ifpgfcalendar@matches\iffalse}
\def\pgfcalendar@matchestrue{\global\let\ifpgfcalendar@matches\iftrue}
\pgfcalendar@matchesfalse
\pgfqkeys{/pgf/calendar}{and/.code 2 args={%
    \begingroup
      \ifdate{#1}{\ifdate{#2}{\pgfcalendar@matchestrue}{}}{}%
    \endgroup
    \ifpgfcalendar@matches\pgfcalendarmatchestrue\pgfcalendar@matchesfalse\fi}}
\makeatother
%------
\newcommand*{\mydays}[1]{%
 \def\mydayslist{#1}%
}
\mydays{Monday,Friday}

\begin{document}

I want to pass the days \mydayslist\ to the calendar.

\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]

\calendar (cal) [
dates=2014-02-01 to 2014-07-last,
month list,month label left,
month text=\textcolor{black}{\%mt},
month yshift=1.7em, black!20,
myif2/.style={if={(and={between=2014-04-01 and 2014-05-32}{#1})[red]}},
myif2/.list/.expanded={\mydayslist},
];
\end{tikzpicture}

\end{document}

Segunda edição

Aqui está a mistura da soluçãoA resposta de Guhoe solução anterior. Defini uma nova chave daypara testar uma lista de dias:

\pgfkeys{
  /pgf/calendar/@day/.style={#1},
  /pgf/calendar/day/.style={@day/.list/.expanded=#1},
}

Com essas chaves, você sempre pode usar a sintaxe de especificação (p. 524 do pgfmanual).

Exemplo com andcondição deCalendário TikZ e testes condicionais.

insira a descrição da imagem aqui

\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
% code from https://tex.stackexchange.com/a/141027/14500
\makeatletter
\def\pgfcalendar@matchesfalse{\global\let\ifpgfcalendar@matches\iffalse}
\def\pgfcalendar@matchestrue{\global\let\ifpgfcalendar@matches\iftrue}
\pgfcalendar@matchesfalse
\pgfqkeys{/pgf/calendar}{and/.code 2 args={%
    \begingroup
      \ifdate{#1}{\ifdate{#2}{\pgfcalendar@matchestrue}{}}{}%
    \endgroup
    \ifpgfcalendar@matches\pgfcalendarmatchestrue\pgfcalendar@matchesfalse\fi}}
\makeatother
%------
\pgfkeys{
  /pgf/calendar/@day/.style={#1},
  /pgf/calendar/day/.style={@day/.list/.expanded=#1},
}
\newcommand*{\mydays}[1]{%
 \def\mydayslist{#1}%
}
\mydays{Monday,Friday}

\begin{document}

I want to pass the days \mydayslist\ to the calendar.

\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]

\calendar (cal) [
dates=2014-02-01 to 2014-07-last,
month list,month label left,
month text=\textcolor{black}{\%mt},
month yshift=1.7em, black!20,
]
if (day=Sunday) [black,font=\itshape]
if (day=\mydayslist) [green]
if (and={between=2014-04-01 and 2014-05-32}{day=\mydayslist}) [red]
;
\end{tikzpicture}

\end{document}

Terceira edição

Minha terceira solução define a macro \calkeys(para gerenciar pares de valores-chave como \pgfkeysou \tikzsetmas com /pgf/calendar/prefixo). Com esta macro, você pode definir qualquer seletor de calendário como um estilo nomeado:

\def\calkeys#1{\pgfkeys{/pgf/calendar/.cd,#1}}
\calkeys{
  my day list/.style={Friday,Saturday},
  april/.style={between=2014-04-01 and 2014-04-30},
  my day list in april/.style={and={april}{my day list}},
}

Exemplo:

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar}
% code from https://tex.stackexchange.com/a/141027/14500
\makeatletter
\def\pgfcalendar@matchesfalse{\global\let\ifpgfcalendar@matches\iffalse}
\def\pgfcalendar@matchestrue{\global\let\ifpgfcalendar@matches\iftrue}
\pgfcalendar@matchesfalse
\pgfqkeys{/pgf/calendar}{and/.code 2 args={%
    \begingroup
      \ifdate{#1}{\ifdate{#2}{\pgfcalendar@matchestrue}{}}{}%
    \endgroup
    \ifpgfcalendar@matches\pgfcalendarmatchestrue\pgfcalendar@matchesfalse\fi}}
\makeatother
% -----
\def\calkeys#1{\pgfkeys{/pgf/calendar/.cd,#1}}
\calkeys{
  my day list/.style={Friday,Saturday},
  april 2014/.style={between=2014-04-01 and 2014-04-30},
  my day list in april 2014/.style={and={april 2014}{my day list}},
}

\begin{document}
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [dates=2014-02-01 to 2014-07-last,month list,month label left,
month text=\textcolor{black}{\%mt},month yshift=1.7em, black!20]
if (my day list) [red]
if (my day list in april 2014) [green]
;
\end{tikzpicture}
\end{document}

Responder2

Aqui está uma versão com um comando wrapper para o tikzcódigo, que pré-expande o argumento (aqui \mydayslist) - o problema usual com interfaces de valores-chave é a falta de expansão dos valores-chave, que é o caso aqui!

\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}

\usetikzlibrary{calendar}


\def\mydayslist{}
\newcommand*{\mydays}[1]{%
 \def\mydayslist{#1}%
}

\mydays{Monday,Tuesday,Friday}

\newcommand{\sigurslittlehelper}[1]{%
  if (#1) [black]
  ;
}


\newcommand{\tikzdo}[1]{% Expand the list first, then use the tikz code
  \expandafter\sigurslittlehelper\expandafter{#1}%
}



\begin{document}

I want to pass the days \mydayslist\ to the calendar.

\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [dates=2014-02-01 to 2014-07-last, month list, month label left,%
month text=\textcolor{black}{\%mt}, month yshift=1.7em, black!20]
\tikzdo{\mydayslist}
\end{tikzpicture}

\end{document}

insira a descrição da imagem aqui

Responder3

Isso parece funcionar. Ele define uma chave para expandir a sequência de controle antes de passá-la para o internal \ifdate. Derivado deesta resposta.

\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}

\newcommand*{\mydays}[1]{%
 \def\mydayslist{#1}%
}
\mydays{Monday,Friday}
\pgfqkeys{/pgf/calendar}{fromcs/.code={\expandafter\ifdate\expandafter{#1}{}{}}}%<=====added
\begin{document}

I want to pass the days \mydayslist\ to the calendar.

\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [dates=2014-02-01 to 2014-07-last, month list, month label left,%
month text=\textcolor{black}{\%mt}, month yshift=1.7em, black!20]
%
if (Tuesday) [black] 
if (fromcs={\mydayslist}) [black] %% <-- insert \mydayslist
;
\end{tikzpicture}

\end{document}

calendário resultante

informação relacionada