3

This question is a follow up and based on this answer by touhami



Situation

I would like to create an excerpt from a script that I have TeX'ed as a compendium of the most important statements (theorems & definitions).

There is a main-file importing chapterfiles with content. Additionally a summary-file ought to import some important parts. This is achieved with touhamis answer. But it should allow to include some and exclude some other figures, which leads to my problem...

Question

How to import all tagged parts of a file with figures?

(while keeping the numbering)

This means some figures are important and should be included, whilst others are not and have to be excluded (see MWE).

MWE

file.tex

\documentclass{amsart}
\usepackage{lipsum}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{definition}{Definition}
\newtheorem{example}{Example}
\newenvironment{mtexclude}{}{}
\begin{document}
First bla bla
%<*tag>
\section{Foo}
\subsection{Foo bar}
I need this

\begin{mtexclude}% begin of part to skiped
    \section{Baz}
    \subsection{Baz bar}
    no need for this

    \begin{figure}[h] %this figure is the problem
        \fbox{\parbox{\textwidth}{\center some picture...}}
    \end{figure}
\end{mtexclude}%   end

\section{End}
\subsection{End bar}
and need this \dots 

\begin{figure}[h] %this figure is ok
    \fbox{\parbox{\textwidth}{\center some other picture...}}
\end{figure}

\begin{mtexclude}% begin of part to skiped
    %no problems here
    \section{Baz 2}
    \subsection{Baz bar 2}
    another part to be skiped
\end{mtexclude}%   end

The end
%</tag>
Last bla bla
\end{document}

newfile.tex

\documentclass{amsart}
\usepackage{lipsum}

\usepackage{catchfilebetweentags}
\newtoks\temptoken
\newbox\mtbox
\newenvironment{mtexclude}{\setbox\mtbox\vbox\bgroup}{\egroup}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{definition}{Definition}
\newtheorem{example}{Example}

\begin{document}
\lipsum[1]
\CatchFileBetweenTags\temptoken{file}{tag}
\the\temptoken

\end{document}
2
  • But there is no numbering for figures here?
    – touhami
    Mar 12, 2016 at 15:04
  • Well figures not necessarily need a numbering but if a solution could include those also (and keeping that one also the same) it was preferable
    – BadAtLaTeX
    Mar 12, 2016 at 15:19

1 Answer 1

2

The solution is to replace mtexclude definition

\newenvironment{mtexclude}{\setbox\mtbox\vbox\bgroup}{\egroup}

with

\makeatletter
\newenvironment{mtexclude}{%
\setbox\mtbox\vbox\bgroup%
\def\@float##1{\def\@captype{##1}}%
\let\end@float\relax%
}{\egroup}
\makeatother
3
  • Excellent! Fixed the issue. It should be noted that this code replaces merely the old ` \newenvironment{mtexclude}{\setbox\mtbox\vbox\bgroup}{\egroup}` so one needs to keep the \newtoks\temptoken \newbox\mtbox. This was not clear to me as a beginner.
    – BadAtLaTeX
    Mar 12, 2016 at 15:33
  • @hillbilly sorry for that.
    – touhami
    Mar 12, 2016 at 15:38
  • I found some other small problem that you might be the right person for. See tex.stackexchange.com/questions/354655/…
    – BadAtLaTeX
    Feb 19, 2017 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .