LATEX   27
xtrcode tex
Guest on 12th February 2023 03:19:37 AM


  1. \documentclass[11pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[dvips]{geometry}
  4. \usepackage{isolatin1,url,verbatim}
  5. \usepackage[english]{babel}
  6. \geometry{paper=a4paper,top=2cm,bottom=1.5cm,hdivide={1.5cm,*,2cm}}
  7. \jot0.3cm
  8. \frenchspacing
  9. \newenvironment{vverbatim}%
  10.   {\endgraf\verbatim}%\noindent
  11.   {\endverbatim}
  12. \title{\texttt{xtrcode} v.0.2 --- extract contents of \LaTeX\ environments from a file}
  13. \author{Thomas Ruedas\thanks{e-mail: \texttt{ruedas@geophysik.uni-frankfurt.de}}}
  14. \date{January 12, 2000}
  15. \begin{document}
  16. \section{Description}
  17. 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
  18. \texttt{xtrcode} $<$\textit{options}$>$ \textit{texfile} $<$\textit{codefile}$>$\bigskip\par\noindent
  19. Options:
  20. \begin{description}
  21. \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}
  22. \item[\texttt{-e}\textit{environment}] extract content of \textit{environment}; default is [Vv]erbatim
  23. \item[\texttt{-p}\textit{pattern}] marker pattern for environments to extract; default is \verb/%%@/. A null pattern is possible.
  24. \item[-h] show help
  25. \end{description}
  26. 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}.
  27. In the following I assume that \textit{texfile} is a program documentation.
  28. \begin{description}
  29. \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''.
  30. \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.
  31. \item[Option -e:] \texttt{xtrcode -e}\textit{environment texfile} searches for \textit{environment} instead of the default verbatim or Verbatim.
  32. \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.
  33. \end{description}
  34. If there are nested environments of the same type, the outermost is assumed to be the one to extract.
  35.  
  36. \section{Example}
  37. Consider a \LaTeX\ file \texttt{progdoc.tex} with the following description of two programs:
  38. \begin{vverbatim}
  39. In the following I describe my sophisticated program which consists of a
  40. main program and a subroutine.\par
  41. In the main part, the subroutine is called:
  42. %%@ main.f
  43. \begin{verbatim}
  44.      program main
  45.      open(10,file="dat1",status="new")
  46.      write (*,*) 'Enter number to be squared:'
  47.      read (*,*) zin
  48.      call sub1(zin,zout)
  49. \end{verbatim}
  50. Then the result is written to a file.
  51. %%@ main.f
  52. \begin{verbatim}
  53.      write (10,*) zout
  54.      close(10)
  55.      end
  56. \end{verbatim}
  57. The subroutine calculates the result by
  58. \begin{equation}
  59. y=x^2.
  60. \end{equation}
  61. \verb/x*x/ was used instead of \verb/x**2/ to increase efficiency.
  62. %%@ sub1.f
  63. \begin{verbatim}
  64.      subroutine sub1(x,y)
  65.      y=x*x
  66.      return
  67.      end
  68. \end{verbatim}
  69. A further subroutine for calculation of cubes is under development.
  70. \end{vverbatim}
  71. 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.
  72. \end{document}

Raw Paste

Login or Register to edit or fork this paste. It's free.