3

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:

  1. Redefine the section command to add the description
  2. Add file input and output to save the descriptions.
  3. 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.

  • The argument you pass to \setvalue is a single argument. Similarly for \getvalue. Try using e.g. \pgfkeyssetvalue \pgfkeysgetvalue etc. instead. Or define a command which reflects the structure of arguments etc. you want But right now, I don't see why you define \getvalue or \setvalue at all - seems like trying to reinvent the wheel for no obvious reason. – cfr Jul 21 '15 at 21:34
  • I'm fairly certain \pgfkeys has nothing to do with the aux file. – John Kormylo Jul 21 '15 at 21:48
  • Indeed, I changed the code (as suggested) and the output is exactly the same. – opieters Jul 21 '15 at 21:51
  • I'm not at all clear what you mean or how you changed the code. But, also, I just don't understand what you are trying to do. – cfr Jul 22 '15 at 2:53
  • @cfr, I hope the updated question clarifies my goal. – opieters Jul 22 '15 at 7:34
0

I changed the approach, I now store the command and the value in a file and just call the file.

To read the file I use:

\makeatletter
\newread\ccinstream
\immediate\openin\ccinstream=list.tex
\@whilesw\unless\ifeof\ccinstream\fi{%
\immediate\read\ccinstream to \auxcommand%
\auxcommand%
}
\immediate\closein\ccinstream
\makeatother

And to write the file:

\newwrite\ccoutstream
\immediate\openout\ccoutstream=list.tex
\newcommand{\wtxt}[2]{
\immediate\write\ccoutstream{\noexpand\pgfkeys{/variables/sec/descr#1 = #2}}
}
\AtEndDocument{\immediate\closeout\ccoutstream}

  • Why a new file ? The .aux file is perfect for your usage... – Paul Gaborit Jul 23 '15 at 23:00
  • PGF has scratch handles for openin. Search for \r@pgf@reada in the manual. – percusse Jul 24 '15 at 1:12

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.