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
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.
\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 returnverbatim
won't work inside tags. I can't append `\` to each line inside my econometrics suite, but that should be easy enough to script.