I want to define a custom aux file that contains some data, stored in a pgfkey. This data has to be stored from the keys and then written to the keys.
However, when I take a look at the aux file, it does not contain the data I saved, but the internal variable. Reading does not work either, because it seems to store the \readaline function in the key and not the output after evaluation (this part has been commented).
Thus, my questions: * How can I write the stored data to file (and the stored data only, no (La)TeX commands or internal structures. * How can I assign the actual data an not the macro?
MWE:
\documentclass{beamer}
\usepackage{pgfkeys}
\usepackage{newfile}
\usepackage{pgfplots}
% source: http://tex.stackexchange.com/questions/37094
\newcommand{\setvalue}[1]{\pgfkeys{/variables/#1}}
\newcommand{\getvalue}[1]{\pgfkeysvalueof{/variables/#1}}
\newcommand{\declare}[1]{%
\pgfkeys{
/variables/#1.is family,
/variables/#1.unknown/.style = {\pgfkeyscurrentpath/\pgfkeyscurrentname/.initial = ##1}
}%
}
\declare{sec/}
\newinputstream{ccin} % create input stream
\IfFileExists{cleancolor.aux}{% only try to open file if it exists
\openinputfile{cleancolor.aux}{ccin}%
\setvalue{sec/number = \readaline{ccin}}%
%\foreach \x in {1,...,\getvalue{sec/number}} {%
% \setvalue{sec/descr\x = \readaline{ccin}}%
%}%
\closeinputstream{ccin}%
}
\newcommand*{\ccdone}{%
\newoutputstream{ccout}%
\openoutputfile{cleancolor.aux}{ccout}%
%\newcounter{ccoutnumber}%
\addtostream{ccout}{4}%
\foreach \x in {1,...,3} {
\addtostream{ccout}{\getvalue{sec/descr\x}}%
}
\closeoutputstream{ccout}%
}
\begin{document}
\begin{frame}
%\getvalue{sec/number}
%\getvalue{sec/descr1}
%\getvalue{sec/descr2}
\end{frame}
\begin{frame}
\setvalue{sec/descr1 = Just}
\setvalue{sec/descr2 = {Some Simple}}
\setvalue{sec/descr3 = {Text}}
\getvalue{sec/descr1}
\getvalue{sec/descr2}
\getvalue{sec/descr3}
\end{frame}
\ccdone
\end{document}
cleandata.aux:
4
\pgfk@/variables/sec/descr1
\pgfk@/variables/sec/descr2
\pgfk@/variables/sec/descr3
Update 1
What I want to do is stated above, but some ask why. Well, my goal is to define a new beamer theme. This theme is a bit special in the sense that I want to add a description to sections because often they are one-word titles and need a bit of clarification. So what I do is:
- Redefine the section command to add the description
- Add file input and output to save the descriptions.
- redefine tableofcontents
The goal is to have all the sides in the MWE below be the same (and equal to the last slide).
\documentclass{beamer}
\usepackage{pgfkeys}
\usepackage{newfile}
\usepackage{pgfplots}
\usepackage{framed}
% source: http://tex.stackexchange.com/questions/37094
%\newcommand{\setvalue}[1]{\pgfkeys{/variables/#1}}
%\newcommand{\getvalue}[1]{\pgfkeysvalueof{/variables/#1}}
\newcommand{\declare}[1]{%
\pgfkeys{
/variables/#1.is family,
/variables/#1.unknown/.style = {\pgfkeyscurrentpath/\pgfkeyscurrentname/.initial = ##1}
}%
}
% declare key
\declare{sec/}
% read descriptions from file
\newinputstream{ccin} % create input stream
\IfFileExists{cleancolor.aux}{% only try to open file if it exists
\openinputfile{cleancolor.aux}{ccin}%
\pgfkeys{/variables/sec/number = \readaline{ccin}}%
%\foreach \x in {1,...,\getvalue{sec/number}} {%
% \pgfkeys{/variables/sec/descr\x = \readaline{ccin}}%
%}%
\closeinputstream{ccin}%
}
% write descriptions to file
\newcommand*{\ccdone}{%
\newoutputstream{ccout}%
\openoutputfile{cleancolor.aux}{ccout}%
%\newcounter{ccoutnumber}%
\addtostream{ccout}{4}%
\foreach \x in {1,...,3} {
\addtostream{ccout}{\pgfkeysvalueof{/variables/sec/descr\x}}%
}
\closeoutputstream{ccout}%
}
% redefine table of contents
\defbeamertemplate*{section in toc}{}[1][]{
\begin{leftbar}
{\usebeamerfont{tocsection}\inserttocsection}\\ {\textit{\pgfkeysvalueof{/variables/sec/descr\inserttocsectionnumber}}}
\end{leftbar}
}
% redefine the section command
% 1st parameter: section name
% 2nd parameter: section description
\let\oldsection\section
\renewcommand{\section}[2]{\oldsection{#1}\pgfkeys{/variables/sec/descr\thesection = #2}}
\begin{document}
\frame{\tableofcontents}
\section{Technical set-up}{How it all comes together}
\frame{\tableofcontents}
\section{Functionality}{How will the end-user interact with the device?}
\frame{\tableofcontents}
\section{Results}{How accurate is location detection?}
\frame{\tableofcontents}
\ccdone
\end{document}
The desired aux-file should look like this:
4
How it all comes together
How will the end-user interact with the device?
How accurate is location detection?
Note: some of the variables are currently hard coded, this is to make the examples more simple.
\setvalueis a single argument. Similarly for\getvalue. Try using e.g.\pgfkeyssetvalue\pgfkeysgetvalueetc. instead. Or define a command which reflects the structure of arguments etc. you want But right now, I don't see why you define\getvalueor\setvalueat all - seems like trying to reinvent the wheel for no obvious reason. – cfr Jul 21 '15 at 21:34