3

I would like to use a verbatim environment inside an ExecuteMetaData call from the catchfilebetweentags package.

The use case is that my econometric software creates a fixed-width table that I don't want to convert to a proper table, yet. I can wrap this fixed-width table in tags and send it to a log file. I would like to also wrap the table in verbatim so that the table is more legible, but when I add the verbatim environment I get a Runaway argument? error. I would like to use the catchfilebetweentags package so that I can avoid manually trimming the header and footer from each table (or counting line numbers).

Can I somehow combine fixed-width type with the catchfilebetweentags package?

Here's my MWE.

\documentclass{article}
\usepackage{catchfilebetweentags}

\begin{document}
\ExecuteMetaData[inner]{table}
\end{document}

Where inner.tex is as follows.

%<*table>
\begin{verbatim}
col1    col2
1   2
3   4
\end{verbatim}
%</table>
  • 1
    You can put \ttfamily before the \ExecuteMetaData command, which will give the output in fixed width font. But unless the table data ends each line in '\\', it won't do the carriage return – Steven B. Segletes Jun 20 '13 at 20:01
  • @StevenB.Segletes - Thanks. This might be my ultimate solution if verbatim won't work inside tags. I can't append `\` to each line inside my econometrics suite, but that should be easy enough to script. – Richard Herron Jun 21 '13 at 13:42
4

Instead of using the catchfilebetweentags package, I adapted my readarray package to do the trick, even using the tags that would otherwise be sought by catchfilebetweentags. It is able to handle multiple tables per input file, interspersed with whatever text (I think).

To handle the search for the % in the tag, I temporarily make $ the comment character. I don't think this screws things up, but it may if $ appears in your tabular data. In that case, you may wish to select a different replacement.

EDITED (12/2016) to remove reliance on the defunct internal readarray package command \record<romannumeral record index>.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{readarray}[2016-11-07]
\newcounter{row}\global\newcounter{column}\newcounter{rcrd}
%\usepackage{catchfilebetweentags}
\usepackage{ifthen}
\parindent 0in

\def\switchcodes{%
  \edef\tmp{\matchcode}%
  \edef\matchcode{\altmatchcode}%
  \edef\altmatchcode{\tmp}%
  \if T\printit\def\printit{F}\else\def\printit{T}\fi%
}
\def\printit{F}

\catcode`\%=12 
\catcode`\$=14 
\newcommand\extracttables[1]{\bgroup\ttfamily$
\catcode`\%=12
\def\matchcode{%<*table>}
\def\altmatchcode{%</table>}
\readrecordarray{#1}\MyArray
\catcode`\$=14
\setcounter{rcrd}{0}$
\whiledo{\value{rcrd} < \nrecords}{$
  \stepcounter{rcrd}$
  \ifthenelse{\equal{\MyArray[\arabic{rcrd}]}{\matchcode}}{$
  \switchcodes\rule{10ex}{.2ex}\\$
  }{\if T\printit\MyArray[\arabic{rcrd}]~\\\fi}$
  }$
\catcode`\%=14$
\catcode`\$=3$
\egroup\vspace{-\baselineskip}$
}
\catcode`\%=14 
\catcode`\$=3 %

\begin{document}
%\ExecuteMetaData[inner]{table}

Testing...

\extracttables{inner.tex}

Back to normal text
\end{document}

And here is what I used for inner.tex. Note that it contains more than one table. When extracting the table, I place rules above and below it to set it off from the rest of the document.

this is
my document prior to
%<*table>
col1    col2
1   2
3   4
%</table>
and my 
document after
the table
%<*table>
col3    col4
1   8
3   47
%</table>
and $ then some more
then
some more

enter image description here

p.s It doesn't actually do verbatim, but just \ttfamily. If doing verbatim is essential, let me know, and I think I might be able to extend the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.