Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

write to file from latex document

6 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Kjetil Halvorsen

ungelesen,
27.05.2003, 22:12:2727.05.03
an
Hola!

I want to have an environment like
\begin{verbatim}

\end{verbatim}


which in addition to typeset the content writes (appends)
the content to a file, so that I can have all my code examples
from my document in a separate text file.

I should also have a related environment which only appends to the
file, without typesetting the content.

Anybody knows how to do this?

Kjetil Halvorsen

ijl...@csie.nctu.edu.tw

ungelesen,
27.05.2003, 22:46:0527.05.03
an
Kjetil Halvorsen <kje...@entelnet.bo> wrote:
> which in addition to typeset the content writes (appends)
> the content to a file, so that I can have all my code examples
> from my document in a separate text file.
> I should also have a related environment which only appends to the
> file, without typesetting the content.

\usepackage{verbatim}

\verbatiminput{filename}
--
The sooner you start to code, the longer the program will take.
--- Roy Carlson

Scott Pakin

ungelesen,
28.05.2003, 15:12:1928.05.03
an
ijl...@csie.nctu.edu.tw wrote:
> Kjetil Halvorsen <kje...@entelnet.bo> wrote:
>
>>which in addition to typeset the content writes (appends)
>>the content to a file, so that I can have all my code examples
>>from my document in a separate text file.
>>I should also have a related environment which only appends to the
>>file, without typesetting the content.
>
>
> \usepackage{verbatim}
>
> \verbatiminput{filename}

You can use filecontents to create a file and \verbatiminput to read it
back in. I don't believe TeX has intrinsic support for appending to
an existing file, however. You'd need to either open a file and leave
it open for the duration of the session or create one file per code
example and concatenate them outside of LaTeX. (I'd recommend the
latter.)

-- Scott

Dan Luecking

ungelesen,
28.05.2003, 16:39:4428.05.03
an
On 27 May 2003 19:12:27 -0700, kje...@entelnet.bo (Kjetil Halvorsen)
wrote:

>Hola!
>
>I want to have an environment like
>\begin{verbatim}
>
>\end{verbatim}
>
>
>which in addition to typeset the content writes (appends)
>the content to a file, so that I can have all my code examples
>from my document in a separate text file.
>
>I should also have a related environment which only appends to the
>file, without typesetting the content.

The verbatim package (in the tools bundle) is accompanied by a
file verbtest.tex that contains the following environment:

\newenvironment{verbatimwrite}[1]%
{\@bsphack
\immediate\openout \verbatim@out #1
\let\do\@makeother\dospecials\catcode`\^^M\active
\def\verbatim@processline{%
\immediate\write\verbatim@out{\the\verbatim@line}}%
\verbatim@start}%
{\immediate\closeout\verbatim@out\@esphack}

Note that it opens and closes a file specified as the
argument. If you want to append only, you should allocate
an output stream:
\newwrite\myoutfile
then open the file
\immediate\openout\myoutfile=myfile.tmp
then modify the above code to:

\newenvironment{myverbatimwrite}%
{\@bsphack
\let\do\@makeother\dospecials\catcode`\^^M\active
\def\verbatim@processline{%
\immediate\write\myoutfile{\the\verbatim@line}}%
\verbatim@start}%
{\@esphack}

Usually LaTeX can be relied upon to close the file at the end, but
in certain circumstances you may want to read it back in. If so,
close it when you are done with it, using
\immediate\closeout\myoutfile.

(Note: opening a preexisting file for output destroys what was in
it before.)

The above will only write to a file. To make it also print the material
in verbatim mode, modify the above replacing the definition of
\verbatim@processline with:
\def\verbatim@processline{%
\immediate\write\myoutfile{\the\verbatim@line}%
\the\verbatim@line\par}%

(Caveat: All code is modulo typing errors, none has been tested.)


Dan

--
Dan Luecking Department of Mathematical Sciences
University of Arkansas Fayetteville, Arkansas 72701

0 neue Nachrichten