TeX Output

When you are writing a paper or some other text, which uses data that is produced by a experiment, it is very useful to have direct access from your TeX sources to your experiment results. This is especially useful if you want to reproduce your paper with a different version of your programs.

class versuchung.tex.DatarefDict(filename='data.tex', key='')[source]

Can be used as: input parameter and output parameter

DatarefDict is like PgfKeyDict, but generates keys for dataref.

class versuchung.tex.Macros(filename='data.tex')[source]

Can be used as: input parameter and output parameter

A Macros file is a normal File with the extension, that you can define TeX macros easily. This is especially useful for writing texts. You may have a experiment, which may be an analysis to an experiment that produces raw data. The produced numbers should appear in your LaTeX document. So instead of copying the numbers you can define TeX macros and use them in the text. This is especially useful if you work on the experiment and the text in parallel and the numbers change often.

>>> from versuchung.tex import Macros
>>> macro = Macros("/tmp/test.tex")
>>> macro.macro("MyNewTexMacro", 23)
>>> print macro.value
\newcommand{\MyNewTexMacro} {23}
comment(comment)[source]

Add a comment in the macro file

macro(macro, value)[source]

Define a new tex macro with \newcommand. This will result in:

\newcommand{%(macro)s} { %(value)s}
newline()[source]

Append an newline to the texfile

class versuchung.tex.PgfKeyDict(filename='data.tex', pgfkey='/versuchung', setmacro='pgfkeyssetvalue')[source]

Can be used as: input parameter and output parameter

PgfKeyDict is very similar to Macros, but instead of \newcommand directives it uses pgfkeys, can be used as a dict and it is possible to read it in again to produce the (almost) same dict again.

>>> from versuchung.tex import PgfKeyDict
>>> pgf = PgfKeyDict("/tmp/test.tex")
>>> pgf["abcd"] = 23
>>> pgf.flush()  # flush method of File
>>> print open("/tmp/test.tex").read()
\pgfkeyssetvalue{/versuchung/abcd}{23}

In the TeX source you can do something like:

\usepackage{tikz}
\pgfkeys{/pgf/number format/.cd,fixed,precision=1}
[...]
\newcommand{\versuchung}[1]{\pgfkeysvalueof{/versuchung/#1}}
\versuchung{abcd}

Note

It is better to use PgfKeyDict instead of Macros, because you can also use spaces and other weird characters in pgfkeys, which cannot be used in TeX macro names.

after_read(value)[source]

To provide filtering of file contents in subclasses, overrwrite this method. It is gets the file content as a string and returns the value()

before_write(value)[source]

To provide filtering of file contents in subclasses, overrwrite this method. This method gets the value() and returns a string, when the file is written to disk

flush()[source]

Flush the cached content of the file to disk