<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[dvips]{geometry}
\usepackage{isolatin1,url,verbatim}
\usepackage[english]{babel}
\geometry{paper=a4paper,top=2cm,bottom=1.5cm,hdivide={1.5cm,*,2cm}}
\jot0.3cm
\frenchspacing
\newenvironment{vverbatim}%
  {\endgraf\verbatim}%\noindent
  {\endverbatim}
\title{\texttt{xtrcode} v.0.2 --- extract contents of \LaTeX\ environments from a file}
\author{Thomas Ruedas\thanks{e-mail: \texttt{ruedas@geophysik.uni-frankfurt.de}}}
\date{January 12, 2000}
\begin{document}
\maketitle
\section{Description}
This is a small Perl program I originally made when I was writing a program documentation for a large program consisting of several files; I wanted to extract the code out of the \LaTeX\ verbatim environments containing the whole code portionwise and have it put into a file which could then be compiled directly. This is how it works:\bigskip\par\noindent
\texttt{xtrcode} $&lt;$\textit{options}$&gt;$ \textit{texfile} $&lt;$\textit{codefile}$&gt;$\bigskip\par\noindent
Options:
\begin{description}
\item[\texttt{-a}] extract all code; this is for code which is supposed to be distributed over different target files, so do not use it together with \textit{codefile}
\item[\texttt{-e}\textit{environment}] extract content of \textit{environment}; default is [Vv]erbatim
\item[\texttt{-p}\textit{pattern}] marker pattern for environments to extract; default is \verb/%%@/. A null pattern is possible.
\item[-h] show help
\end{description}
You can download it together with a short documentation as a tar.gz file from \url{http://www.geophysik.uni-frankfurt.de/~ruedas/download/xtrcode.tar.gz}.
In the following I assume that \textit{texfile} is a program documentation.
\begin{description}
\item[\textit{codefile}:] \texttt{xtrcode} \textit{texfile} \textit{codefile} searches for a marker pattern followed by a blank and \textit{codefile} and copies the content of the following environment into the target file \textit{codefile}. This can be used to extract only the contents corresponding to a certain part of the program instead of the whole lot.---If no \textit{codefile} is given, the default output file is ``xtrcode.out''.
\item[Option -a:] \texttt{xtrcode -a} \textit{texfile} extracts all contents of an environment from \textit{texfile} and writes it into the output file which is expected to be specified by the use of the marker pattern. This is useful if you have program code which is intended to come into separate files; when documenting it you will use a kind of extra pattern line, e.g. \verb/%%@ code1.f/ preceding each verbatim environment containing parts of \texttt{code1.f}, and similarly with the other files. With the \texttt{-a} option, \texttt{xtrcode} will interpret \texttt{code1.f} as the name of the file which shall contain the content of the following environment, and will copy the contents of all environments of the selected type into the respective target files.---The use of a marker pattern is necessary here, and no \textit{codefile} should be specified.
\item[Option -e:] \texttt{xtrcode -e}\textit{environment texfile} searches for \textit{environment} instead of the default verbatim or Verbatim.
\item[Option -p:] \texttt{xtrcode -p}\textit{pattern texfile} uses \textit{pattern} instead of the default \verb/%%@/ as a marker. If \texttt{-p} is used without a pattern, no marker patterns are taken into account.
\end{description}
If there are nested environments of the same type, the outermost is assumed to be the one to extract.

\section{Example}
Consider a \LaTeX\ file \texttt{progdoc.tex} with the following description of two programs:
\begin{vverbatim}
In the following I describe my sophisticated program which consists of a
main program and a subroutine.\par
In the main part, the subroutine is called:
%%@ main.f
\begin{verbatim}
      program main
      open(10,file="dat1",status="new")
      write (*,*) 'Enter number to be squared:'
      read (*,*) zin
      call sub1(zin,zout)
\end{verbatim}
Then the result is written to a file.
%%@ main.f
\begin{verbatim}
      write (10,*) zout
      close(10)
      end
\end{verbatim}
The subroutine calculates the result by
\begin{equation}
y=x^2.
\end{equation}
\verb/x*x/ was used instead of \verb/x**2/ to increase efficiency.
%%@ sub1.f
\begin{verbatim}
      subroutine sub1(x,y)
      y=x*x
      return
      end
\end{verbatim}
A further subroutine for calculation of cubes is under development.
\end{vverbatim}
With \texttt{xtrcode -a progdoc.tex}, all the code in the verbatim environments will be extracted, copying everything marked with \verb/%%@ main.f/ into a file \texttt{main.f} and everything marked with \verb/%%@ sub1.f/ into a file \texttt{sub1.f}. With \texttt{xtrcode progdoc.tex sub1.f} you can extract everything marked with \verb/%%@ sub1.f/; with \texttt{xtrcode -eequation -p progdoc.tex} you can extract all lines of all equation environments.
\end{document}

</pre></body></html>