3

I have been using tikzset{style name/.provide style={}}from Is there something like \providetikzstyle similar to \providecommand? defined as

\tikzset{/handlers/.provide style/.code={%
    \pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}{}%
        {\pgfkeys {\pgfkeyscurrentpath /.code=\pgfkeysalso {#1}}}%
}}

and have found it very handy. What is the similar version for \pgfplotsset. The following does not seem to work:

\pgfplotsset{/handlers/.provide style/.code={%
    \pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}{}%
        {\pgfkeys {\pgfkeyscurrentpath /.code=\pgfkeysalso {#1}}}%
}}

The MWE below produces the image on the left, but should produce the image on the right once .provide style is working for \pgfplotsset (ie, no x tick labels and a thick red box):

enter image description here

References:

Code:

\documentclass[border=2pt]{standalone}

\usepackage{pgfplots}

% https://tex.stackexchange.com/questions/22640/is-there-something-like-providetikzstyle-similar-to-providecommand \tikzset{/handlers/.provide style/.code={% \pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}{}% {\pgfkeys {\pgfkeyscurrentpath /.code=\pgfkeysalso {#1}}}% }}

%% How to define this??? \pgfplotsset{/handlers/.provide style/.code={% \pgfkeysifdefined{\pgfkeyscurrentpath/.@cmd}{}% {\pgfkeys {\pgfkeyscurrentpath /.code=\pgfkeysalso {#1}}}% }}

\begin{document} \pgfplotsset{tick label style/.provide style={% output should be as if this was ".style" instead of ".provide style" xticklabels={}, draw=red, ultra thick, }}

%% This should be ignored as it was already defined above. \pgfplotsset{tick label style/.provide style={ xticklabels={}, yticklabels={}, draw=blue, ultra thick, }}

\begin{tikzpicture} \begin{axis}[% tick label style,% <---- y ticklabels shown, x ticklabels suppressed, axis in red ] \addplot {x^2}; \end{axis} \end{tikzpicture} \end{document}

Peter Grill
  • 223,288

0 Answers0