General\newwrite inside a self-defined environment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
zer0nimo
Posts: 12
Joined: Wed Jul 29, 2009 3:20 am

\newwrite inside a self-defined environment

Post by zer0nimo »

Hi Folks!

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:

Code: Select all

.
.
\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:

Code: Select all

.
.
\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:

Code: Select all

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. =)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: \newwrite inside a self-defined environment

Post by phi »

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.
zer0nimo
Posts: 12
Joined: Wed Jul 29, 2009 3:20 am

Re: \newwrite inside a self-defined environment

Post by zer0nimo »

Yeah! It works!!

And it's that simpel :)

I thought of putting an environment around the environment or looping through the lines in the *.tmp-file ... but your solution is much better ;)

Thank You!
Post Reply