trh@ukc.UUCP (T.R.Hopkins) (01/08/86)
I would like to be able to produce figures which contain segments of Fortran code possibly going over more than one page. In order that the most uptodate versions of the code get inserted I don't want to embed the code in the text or edit the files before they get inserted. If I could get the file expansion in the following would do what I want \begin{figure} \begin{verbatim} \input{fortran file contents here} \end{verbatim} \caption{} \label{} \end{figure} Can somebody please tell me how to get such an effect? Tim Hopkins, Computing Laboratory, University of Kent, Canterbury CT2 7NF Kent U.K. { trh@ukc.UUCP trh%ukc@ucl-cs.ARPA na.hopkins@su-score.ARPA }
rusty@sdcarl.UUCP (rusty c. wright) (01/13/86)
as is usually the case, the ``easiest'' way to get a desired effect with latex is to re-write a particular macro. in your case i would try making up a new environment called ``inputverbatim''. study the verbatim macro and, perhaps, after a while you will begin to understand how it works; or at least (like me) you will understand enough to be able to modify it. i don't really know if this is really possible but just offer it as a suggestion. -- rusty c. wright {ucbvax,ihnp4,akgua,hplabs,sdcsvax}!sdcarl!rusty
pallas@Navajo.ARPA (01/13/86)
This little bit of trickiness shoud do the desired file inclusion, although the way it's called is a little weird. You have to say \verbatimfile{filename} \end{verbatim} I tried to make the \end{verbatim} implicit, but I couldn't manage to do it. Can someone more TeXnical than I tell me why (or better yet, how to do it right)? I know it has to do with the way TeX scans arguments, and the way \verbatim is defined. Anyway, here's the magic: \newcommand{\beginverb}{\begin{verbatim}} \newcommand{\inputfile}[1]{\input{#1}} \newcommand{\verbatimfile}[1]{\expandafter\beginverb\inputfile{#1}} Here's the explanation: \expandafter is a TeX primitive that causes the second following macro to be expanded before the first (that is, \expandafter\a\b means expand \a after expanding \b). Since \a has to be a single token, we define a single-token alias for \begin{verbatim}. The alias for \input{filename} is required because \input is funny about it's arguments, so \expandafter doesn't do the right thing. So, the end result is that \input{filename} is expanded before \begin{verbatim} is expanded, so the file's contents are inserted inside the verbatim environment. joe