# Parametric tikzset style with argument

I am working on a way to curtomize @percusse from Simulating hand-drawn lines to make it parametric.

My idea is to have something like:

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


or even better (because penciline is a decoration anyway):

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


How do I manage to pass PGF style arguments to penciline? It seems that jag ration is not handled from here.

My MWE is:

\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)
{\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}

• the {} button (or control-l or just indent by 4 spaces) is better than <code> for code sections – David Carlisle Dec 17 '14 at 21:27
• Can you please stop using this decoration? :P I promised to fix it for arcs but still didn't finalize it, I get embarrassed everytime I see it. – percusse Dec 17 '14 at 21:45
• Here my question is more about how to use parametrized tikzset. The decoration is just a support. I feel sorry if I embarrassed you. – renard Dec 17 '14 at 21:48
• @renard No problem at all. It was meant to be a joke but I failed. – percusse Dec 17 '14 at 21:55
• @cfr I post the answer as you recommended. – renard Dec 17 '14 at 23:14

Finally I got this from Key that takes a list of other keys as argument and sets them

\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);
}