6

pgfkeys seems to have no problem with leading spaces. For instance, adapting the solution from How to create a command with key values?, I can define a key text= as follows:

\pgfkeys{ % <-- NOTE: Space here is ok
    /MyMacro/.is family,
    /MyMacro,
    default MyMacro options/.style={  % <-- NOTE: Space here is ok
        text={},
    },
    text/.store in = \Text,
}

and things work as desired. However, when I attempt to actuall use this key I need to supress the leading space:

\MyMacro{% <-- How to eliminate requiring this?
    text={Some Text},
}%

I would be nice to not require that additional %. Is there an easy to way to do that?

Note:

  • This a only a minor inconvenience, so easy to live with, but thought I should ask in case I am missing something. Also, options in tikzpicture and axis environment don't have these issue, so am thinking that there is some switch that can resolve this.

    However, no need to spend too much valuable procastingting time solving this issue -- plus I have a few other real problems realted to pgfkeys so you can procastinate on those if desired (just gotta build the MWE).

Code:

\documentclass{article}
\usepackage{tikz}

\pgfkeys{ % <-- NOTE: Space here is ok
    %% https://tex.stackexchange.com/a/34318/4301
    /MyMacro/.is family,
    /MyMacro,
    default MyMacro options/.style={  % <-- NOTE: Space here is ok
        text={},
    },
    text/.store in = \Text,
}

\newcommand{\MyMacro}[1]{%
    \pgfkeys{/MyMacro/.cd, default MyMacro options, #1}%
    \Text
}%

\begin{document}
    \MyMacro{% <-- How to eliminate requiring this?
        text={Some Text},
    }%
\end{document}
4

The definition text of \MyMacro has a space between the comma and the following #1.
You deliver another space when supplying the argument to \MyMacro.
Thus there will be two consecutive space tokens while it seems that pgfkeys does "expect" at most one space token.

Therefore I suggest removing the space between the comma and #1 within the definition text of \MyMacro:

\documentclass{article}
\usepackage{tikz}

\pgfkeys{ % <-- NOTE: Space here is ok
    %% http://tex.stackexchange.com/a/34318/4301
    /MyMacro/.is family,
    /MyMacro,
    default MyMacro options/.style={  % <-- NOTE: Space here is ok
        text={},
    },
    text/.store in = \Text,
}

\newcommand{\MyMacro}[1]{%
    \pgfkeys{/MyMacro/.cd, default MyMacro options,#1}%<-space between comma and #1 removed
    \Text
}%

\begin{document}
    \MyMacro{
        text={Some Text},
    }%
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.