Strings aus einer selbst definierten Umgebung speichern

Redefinition von Makros, Definition eigener Befehle sowie neuer Umgebungen


zer0nimo
Forum-Newbie
Forum-Newbie
Beiträge: 5
Registriert: Fr 31. Jul 2009, 13:10

Strings aus einer selbst definierten Umgebung speichern

Beitrag von zer0nimo »

Hi Folks!

Folgenden Beitrag hab ich schon in einem anderen LaTeX-Forum gepostet, aber scheinbar kann (oder will ^^) mir da keiner helfen :(

Deshalb versuch ich es jetzt auch nochmal bei euch, vielleicht habt ihr ja ne Idee! =)

(Das Forum war auf Englisch, deshalb auch hier meine Frage auf Englisch, aber ich denke mal, das sollte kein Problem sein. ;) )

I'm not quite a beginner, but it's the first time for me to go a little deeper :)

I'm wondering, how it's possible to continue an output-stream to write information out of an environment to a tmp-file.

Let me explain what I mean by a little example:

Inside a *.tex-file:
    .
    .
    \newwrite\outputstream
    \immediate\openout\outputstream=table.tmp
    \begin{myEnvironment}[
    Value1= 123,
    Value2= 234,
    Value3= true,
    Value4= hello,
    ]
    \end{myEnvironment}
    .
    .
    \begin{myEnvironment}[
    Value1= 678,
    Value2= 789,
    Value3= false,
    Value4= bye bye,
    ]
    \end{myEnvironment}
    \immediate\closeout\outputstream
    .
    .

Inside a *.cls-file:
    .
    .
    \def\myEnvironment@Value1{111}
    \def\myEnvironment@Value2{111}
    \def\myEnvironment@Value3{true}
    \def\myEnvironment@Value4{words}

    \define@key{myEnvironmentkey}{Value1}{\def\myEnvironment@Value1{#1}\immediate\write\outputstream{#1}}
    \define@key{myEnvironmentkey}{Value2}{\def\myEnvironment@Value2{#1}\immediate\write\outputstream{#1}}
    \define@key{myEnvironmentkey}{Value3}{\def\myEnvironment@Value3{#1}\immediate\write\outputstream{#1}}
    \define@key{myEnvironmentkey}{Value4}{\def\myEnvironment@Value4{#1}\immediate\write\outputstream{#1}}

    \newenvironment{myEnvironment}[1][mt]{\setkeys{myEnvironmentkey}{#1}
    \paragraph*{\myEnvironment@Value1 , \myEnvironment@Value3 ... }
    \noindent
    \\
    }
    .
    .

Now my real questions:

1st - How is it possible to write into an existing *.tmp-file without overwriting it?

This is the problem, when I put the I/O-stream into the definition of the new environment myEnvironment.

2nd - So, how can I move the lines with opening and closing the stream to the *.tmp-file from the *.tex to the *.cls and can I put them, as well as the concrete writing commands, inside the new environment?

The result should look like that:

table.tmp:
    123
    234
    true
    hello
    678
    789
    false
    bye bye

Thank you very much for a clue!!

-----

Btw. this solution works! I just want to move the plain commands for opening and closing I/O to the *.cls, so they are hidden from the users for style reasons. Moreover I will need several *.tmp-files and moving the writing commands inside the environment would make it clearly arranged. =)[/code]

zer0nimo
Forum-Newbie
Forum-Newbie
Beiträge: 5
Registriert: Fr 31. Jul 2009, 13:10

Beitrag von zer0nimo »

Wider erwarten hat nun doch jmd geantwortet.

Die Lösung:
You cannot open files for appending in TeX, so you have to open the file when the LaTeX run is started. Simply open it in the class file; it will be open during the whole run and will be closed automatically.

Antworten