0

I have a .tex document(external.tex, for example) whose content is like this:

...
...
%*#<start>
some code
%*#<end>
...
...
%*#<start>
some other code
%*#<end>
...
...

I want to input all the parts wrapped between a pair of %*#<start ... %*#<end> of this file to my main doc. How can I do it?

\documentclass{article}
\inputmultiparts{external.tex}
\begin{document}
% using code from "external.tex"
\end{document}
lyl
  • 2,727
  • The syntax looks somewhat-similar to docstrip... – user202729 Jun 15 '22 at 03:54
  • Would be duplicate of https://tex.stackexchange.com/questions/343024/how-to-capture-a-subset-of-a-latex-document , if you don't mind changing the tag format a bit. I don't use the package myself so it might already work with the current format with some modifications – user202729 Jun 15 '22 at 04:07
  • catchfilebetweentags package can only treat(find) the first pair of dilimiter tags it finds. In my example, there maybe many such tags which all need to be input to the main document. – lyl Jun 15 '22 at 04:15
  • May be possible with some packages which provide interfaces to read in from a file line by line, in verbatim. For example, using a customed \verbatim@addtoline with verbatim package. – muzimuzhi Z Jun 15 '22 at 04:51
  • Well of course it's possible with sufficiently amount of programming. (another drawback is lost synctex ability, however.) – user202729 Jun 15 '22 at 05:11
  • Depending on your use case (does the code in external.tex change often? where does it come from? which operating system do you use? is it just for you or also for other people?) it may be easier to process the file with grep or awk or perl etc., either fully separated from the LaTeX compilation or with a system call from within your document. – Marijn Jun 15 '22 at 12:17
  • @Marijn Yes. my external.tex changes often. It collects many macros that are for me in my Windows system. – lyl Jun 16 '22 at 00:24
  • @user202729 Thank you for the solution you provided( macros - Import several parts of file at once). This solution needs to open/search/close file several times depending on to the quality of tags. It would cost a lot if there are many different tags in the file. I wonder if there is method to extract all parts between pairs of tags with same name. – lyl Jun 16 '22 at 02:10

0 Answers0