Estilo tikzset paramétrico com argumento

Estilo tikzset paramétrico com argumento

Estou trabalhando em uma forma de encurtar @percusse deSimulando linhas desenhadas à mãopara torná-lo paramétrico.

Minha ideia é ter algo como:

  \draw[penciline={jag ratio=2},decorate,thick] (-0.4cm,-0.8cm) rectangle (1.2,-2);

ou melhor ainda (porque pencilineé uma decoração mesmo):

\draw[penciline={jag ratio=2},thick] (-0.4cm,-0.8cm) rectangle (1.2,-2);

Como consigo passar argumentos de estilo PGF para penciline? Parece que isso jag rationnão é tratado daqui.

Meu MWE é:

\documentclass[border=1cm]{standalone}

\RequirePackage{tikz}
\usetikzlibrary{calc,patterns,decorations,plotmarks}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}


\pgfdeclaredecoration{penciline}{initial}{
  \state{initial}[width=+\pgfdecoratedinputsegmentremainingdistance,
    auto corner on length=1mm,
  ]{
    \pgfpathcurveto%
        {% 1st control point
          \pgfpoint
              {\pgfdecoratedinputsegmentremainingdistance*rnd*1pt}
              {\pgfkeysvalueof{/tikz/penciline/jag ratio}*rand*\pgfdecorationsegmentamplitude}
        }
        {%% 2nd control point
          \pgfpoint
          %% Make sure random number is always between origin and target points
              {(.5pt+0.25*rand)*\pgfdecoratedinputsegmentremainingdistance}
              {\pgfkeysvalueof{/tikz/penciline/jag ratio}*rand*\pgfdecorationsegmentamplitude}
        }
        {% 2nd point (1st one is implicit)
          \pgfpointadd
              {\pgfpointdecoratedinputsegmentlast}
              {\pgfpoint{rand*1pt}{rand*1pt}}
        }
  }
  \state{final}{}
}

\tikzset{
  penciline/.code={\pgfqkeys{/tikz/penciline}{#1}},
  penciline={
    jag ratio/.initial=5,
  },
  penciline/.style = {
    decorate,
    decoration={penciline},
  },
}


\def\Grid{
  \draw[penciline,decorate,style=help lines] (-2,-2) grid[step=1cm] (4,4);
}

\begin{tikzpicture}
  \Grid{}
  \draw[penciline,decorate,thick] (-0.4cm,-0.8cm) rectangle (1.2,-2);


\end{tikzpicture}


\end{document}

Responder1

Finalmente consegui isso deChave que recebe uma lista de outras chaves como argumento e as define

\tikzset{
  penciline/.code={\pgfqkeys{/tikz/penciline}{#1}},
  penciline={
    jag ratio/.initial=5,
  },
  penciline/.style = {
    decorate,
    decoration={penciline},
    penciline/.cd,
    #1,
    /tikz/.cd
  },
  decorate
}


\def\Grid{
  \draw[penciline={jag ratio=1},style=help lines] (-2,-2) grid[step=1cm] (4,4);
}

informação relacionada