# pgfkeys inside newenvironment [duplicate]

Consider the following MWE:

\documentclass{article}

\usepackage{tikz}

\newenvironment{env}{
\pgfkeys{/env/.initial=hello}
}{}
\newcommand{\comm}{
\pgfkeys{/comm/.initial=hello}
}{}

\begin{document}

\begin{env}\end{env}
\comm{}

\pgfkeys{
/env/.get=\envval,
/comm/.get=\commval,
}

Value of key set using environment: \envval

Value of key set using command: \commval

\end{document}


It produces

Value of key set using environment:
Value of key set using command: hello


Is this an known issue, and are there any workarounds?

• An environment creates a TeX group. Definitions are local to that group unless you make them global. If you want values to remain accessible outside the group, you need to make them global before closing it. – cfr Feb 8 '17 at 4:27
• @Andrew It is not really a properly of pgfkeys in particular. It is the same for any other way of writing \def. – cfr Feb 8 '17 at 4:28
• @cfr Yes that's true , but I've always thought that this was a conscious design choice in pgfkeys (but I don't know for sure, so perhaps it isn't). – user30471 Feb 8 '17 at 4:31
• One way of making the changes global is to use \pgfkeysgsetvalue{/env}{Hello}, where the macro \pgfkeysgsetvalue is defined in Martin Scharrer's answer in the post I linked to above. He also defines a .gcode handler. – user30471 Feb 8 '17 at 4:35
• @cfr In what sense? Also L3 keys obey scoping rules. – egreg Feb 8 '17 at 10:08