is there a way to embed an text in several environments (or structures, \chapter, \section etc.) in one file and "copy"/insert the content of single environment items in other files? i've noticed the clipboard and extract packages and had the thought about \def and \newcommand. but those aren't satisfying, mostly because it seems unaesthetic to me; I just want ordinary environments.

The extract package just places the content into a new file, which is what I seek to avoid. Consider an huge collection of aphorisms, quotes or equations (and others, so the solution should be abstract enough to handle different content, I guess environments would fit well). I just don't want a file for each single item, it would be far too many.

So something like "I want to use the environment x, this x shall be named x1, that x2 the other x3", as I would do with the extract package would be pleasant, just I need now access to these x1, x2 and x3 instead of a file. Something like "here I want to place a copy of x1, there of x2, here of x1 again, there of x3".

So as example I want something like:


\begin{myquote} % any environment
\contentName{quote1} % define some kind of identifier 
                     % for this environments content
This is a quote

lorem ipsum dolor sit amet

foo bar baz foobar foobaz

and in otherfile.tex: \include{quotesFile}

\placeContent{quote2} % I want something as simple 
                      % as this to insert the content 
                      % of the environment, here with 
                      % the identifier "quote2"


so the output should be:
lorem ipsum dolor sit amet

foo bar baz foobar foobaz

I do not want something like

\newcommand{\quote1}[]{This is a quote}

for several reasons. Well, it kinda would solve the problem but it just doesn't seem aesthetical to me (blame me). I prefer to keep things clear and tidy and all the brackets and commands which are actually just simple text don't seem tidy to me but rather confusing. According to my opinion and understanding commands/macros shall serve to avoid repetition of code but aren't to be used for ordinary text content.

  • 1
    I think that you need to add more details, and preferably give an example, so that it is clearer what you want. I don't, for example, understand why simply defining \x1, \x2, ... (with different names/codes) and then using these macros (which might expand into environments) doesn't solve your problem. – Andrew Jul 27 '14 at 4:24
  • You need to provide more information about what you desire, but I suspect you want this tex.stackexchange.com/questions/4889/input-only-part-of-a-file , yes? You can put content in between tags in one file and use that refer that content to be input into other files too. – Guido Jorg Jul 27 '14 at 5:09
  • @GuidoJorg thank you, the catchfilebetweentags package, as mentioned in the question you linked, solves the problem quite well, actually better than what I was looking for. Thank you a lot! – Mike Jul 27 '14 at 6:02
  • I guess I'll put that up as the answer below in case other people search for this too. – Guido Jorg Jul 27 '14 at 7:00

The package to use in this case is:

http://www.ctan.org/tex-archive/macros/latex/contrib/catchfilebetweentags/ gives the clearest code for this type of system of documents, each one citing perhaps parts of other.

Basically, a system of organization based on placing tags with some kind indexing convention (in between which a particular environment with a often reused piece of code or text goes) in documents allows using pieces of each as necessary where these may be littered and reused across many documents.

If the indexing convention is clever (use different prime numbers multiplied together to uniquely mark across documents as often done in software, as suggested by the only scientist recognized by posterity for his efforts with a brand of biscuits named after him?) or straightforward, say [Lichtenberg]{B-25},for the 25th aphorism of Lichtenberg's journal B, found in a larger document (a quotes file Lichtenberg, itself broken into sections A, B, C, according to the journals that sources of the quote in this case.


With a slightly different input, the following works just as well:

enter image description here

This is a quote

lorem ipsum dolor sit amet

foo bar baz foobar foobaz

  \renewcommand{\myquotearg}{#1}% Store myquote environment argument
  \ifx\myquotearg\contentName% Match argument with content name
    \BODY% Print myquote environment body
  \renewcommand{\contentName}{#1}% Store content name
  \input{myquotes}}% Read input file




The change is to supply an argument to your myquote environment which is then used to check against the argument of \placeContent. environ is the key here, which allows to swallow the entire contents of the environment into \BODY. We just condition on printing it based on whether the argument matches \contentName.

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.