3

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).

The question \input only part of a file has an answer by Will Robertson that supposes the usage of catchfilebetweentags. I did that and it is working just fine, but ...

How do you keep the original numbering?

The above mentioned method using the catchfilebetweentags package allows me to make corrections of errors in the main file and the summary at the same time. For the sake of comparability, I would prefer to have the same numbering also. Though the numbering is reset.


Note: I could imagine a solution by putting a \setcounter{counter}{value} in front of each statement but inside the tags. However, this is a very inconvenient way as it is inelegant and involves much more work.


Edit (MWE):

Taken from this site (by Giacomo Drago)

File that contains tags which should be included

% Equations dictionary
\documentclass[11pt]{article}
\usepackage{amssymb,amsmath}

% Begin document
\begin{document}

%<*eq001>
\begin{equation}
F\left (x_1,\dots,x_n,\frac{\partial u}{\partial x_1},\dots,\frac{\partial u}{\partial x_n},\frac{\partial^2 u}{\partial x_1\partial x_1},\dots,\frac{\partial^2 u}{\partial x_n\partial x_n},\dots
\right)
\end{equation}
%</eq001>

\begin{equation}
    a = b + c
\end{equation}

%<*eq002>
\begin{equation}
u_x=\frac{\partial u}{\partial x}, \quad\quad\quad
u_{xy}=\frac{\partial^2 u}{\partial y \partial x}=\frac{\partial u}{\partial y}\left( \frac{\partial u}{\partial x} \right).
\end{equation}
%</eq002>
% A bunch of other equations...
\end{document}

File that includes

% http://yatb.giacomodrago.com/en/post/3/latex-loading-equations-from-an-external-file.html
\documentclass[a4, 11pt, twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}

\usepackage{catchfilebetweentags}
\usepackage{blindtext}

\newcommand{\loadeq}[1]{%
   \ExecuteMetaData[equ.tex]{eq#1}%
}


\begin{document}
    \blindtext
    \loadeq{001}
    \blindtext
    \loadeq{002}
    \blindtext
\end{document}
BadAtLaTeX
  • 1,139
  • can you make it more clear by adding examples of two files? and is write18 an option? – touhami Feb 28 '16 at 19:19
  • Fpr the counter values see the package xassoccnt package and it's \BackupCounterValues and \RestoreCounterValue features please, as I have shown in my answer to this question: http://tex.stackexchange.com/questions/245680/how-to-use-several-sectioning-trees-chapter-section-in-parallel-and-in-th -- please download the bugfixed version (v.0.5a) of xassoccnt from my website. –  Feb 29 '16 at 04:43
  • @touhami, added MWE (note that my question aims at a theorem counter - in case that changes something). Concerning \write18: I am not familiar with that option, though on first sight it seems like quite some work to set up. I would prefer some out of the box solution with some package. – BadAtLaTeX Feb 29 '16 at 15:34
  • @ChristianHupfer , I had a look at your answer there and it looks quite promising. As far as I understood, it is used to insert a complete text with independent numbering. Would that allow to include just a single section or theorem whilst maintaining the numbering ? To make it more clear: I do not want any consecutive numbering, but the numbers that each part had in the original file/pdf. (Even if that means it goes like 1.03, 1.06, 1.07, 1.13, 2.13, 2.01, ...) – BadAtLaTeX Feb 29 '16 at 15:43
  • the problem here is that you will have (let say) eq1, <eq 2> and eq2 or how do you plan equation a+b=c will be numbered? – touhami Feb 29 '16 at 16:01
  • @hillbilly: No, that's a completely different approach then, unless you explicitly set the counter values to have those 'weird' values like 1.03 etc. but you could use the set counter approach directly then –  Feb 29 '16 at 16:17
  • @touhami , as mentioned before (see my comment directed to Christian) it would mean that some equation was skipped (e.g. eq1, eq2, eq4). – BadAtLaTeX Feb 29 '16 at 16:36
  • @ChristianHupfer could one achieve that behaviour by saving the counter in the import-file and restoring with each import ? I don't know how the imported file is processed, but if it was just one extra command, then the amount of extra work was reasonably low enough. – BadAtLaTeX Feb 29 '16 at 16:43
  • @hillbilly: You mean \BackupCounterValues within your imported file? That should be possible –  Feb 29 '16 at 19:57

1 Answers1

3

Here is a solution. The idea is to capture almost every thing but display only needed parts

first file (with tags)

\documentclass{amsart}
\usepackage{lipsum}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{definition}{Definition}
\newtheorem{example}{Example}
\begin{document}
%<*tag>
\lipsum[1]
Here we go
%</tag>
%<*atag> 
\begin{definition}
some bla bla
\end{definition}
\begin{theorem}
more bla bla
\end{theorem}
\begin{definition}
some bla bla
\end{definition}
%</atag>
%<*btag>
\begin{definition}
some bla bla
\end{definition}
\begin{theorem}
more bla bla
\end{theorem}
%</btag>
%<*ctag>
\lipsum[1-2]
%</ctag>
%<*dtag>
\begin{lemma}
more bla bla
\end{lemma}
\begin{theorem}
more bla bla
\end{theorem}
%</dtag>
%<*etag>
\lipsum[1-2]
\begin{example}
some bla bla
\end{example}
%</etag>
\begin{theorem}
more bla bla
\end{theorem}
\end{document}

final file

\documentclass{amsart}
\usepackage{lipsum}

\usepackage{catchfilebetweentags}
\newtoks\temptoken

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{definition}{Definition}
\newtheorem{example}{Example}
\begin{document}
\lipsum[1]
\CatchFileBetweenTags\temptoken{file}{tag}% capture part1
\setbox0=\vbox{\the\temptoken}%  skip part1
\CatchFileBetweenTags\temptoken{file}{atag}% capture part2
\the\temptoken % display part2

\CatchFileBetweenTags\temptoken{file}{btag}% capture part3
\setbox0=\vbox{\the\temptoken}%  skip part3
\CatchFileBetweenTags\temptoken{file}{ctag}% capture part4
\setbox0=\vbox{\the\temptoken}%  skip part4

\CatchFileBetweenTags\temptoken{file}{dtag}% capture part5
\the\temptoken%  display part5
\end{document}

enter image description here

touhami
  • 19,520
  • I've tried your solution with a slight adjustment, that was having all statements use the theorem counter. It seems to work :), really nice. Could you maybe elaborate on how this works ? Especially the difference between \ExecuteMetaData[file]{tag} and your \CatchFileBetweenTags\temptoken{file}{dtag} and the \setbox as well as \temptoken (your comments say it shoul display part 2 only). – BadAtLaTeX Feb 29 '16 at 17:40
  • @hillbilly ok i will try – touhami Feb 29 '16 at 17:48
  • catchfilebetweentags package define 3 commands (6 if starred version) \CatchFileBetweenTags to be used as above \CatchFileBetweenTags\temptoken{file}{dtag} where \temptoken is toks register or a macro command where the content is saved in case of toks register (as above) we need \the\toksrigstername to display the content. – touhami Mar 01 '16 at 17:12
  • \ExecuteMetaData[file]{tag} is equivalent to \CatchFileBetweenTags\temptoken{file}{tag}\the\temptoken i.e. it capture the content and display it immediatly. – touhami Mar 01 '16 at 17:24
  • the command \CatchFileBetweenDelims is similar (with slight difference) to \CatchFileBetweenTags please see documentation. – touhami Mar 01 '16 at 17:26
  • In my answer i used \CatchFileBetweenTags\temptoken{file}{dtag} this save part between dtag into toks \temptoken. If we need this part we just need to display it with \the\temptoken if we don't need it (but we need to skip it) we display it into a save box \setbox0=\vbox{\the\temptoken}. – touhami Mar 01 '16 at 17:31
  • Nice! I think that explains it well enough. If I am not mistaken, then your % skip part5 should be % display part5 as it is not printing into a \setbox0 , right? - Why not add this information to the answer itself ? – BadAtLaTeX Mar 01 '16 at 20:26
  • yes you're right thanks. 2) I will try.
  • – touhami Mar 01 '16 at 21:34
  • I created another question based on your answer! http://tex.stackexchange.com/questions/297389/import-several-parts-of-file-at-once – BadAtLaTeX Mar 05 '16 at 01:40
  • @hillbilly i will see :-) – touhami Mar 05 '16 at 07:38
  • Is it possible, to make this compatible with SyncTeX? (I already posted a separate extended question \input only part of file, but preserve synctex? about this.) – kdb Jun 26 '18 at 14:57
  • @kdb I don't know how synctex works so I have no idea. – touhami Jun 26 '18 at 15:29