I have been searching all over and I do not understand how to reference a block of text in an external document.

I am using the memoir documentclass. I am trying to use the XR package and the \externaldocument{filename} command. To store chunks of text that will be included in various documentation. My goal is to store all of this in an external file, but include portions of it in my writing. Most of this is boilerplate info, so it doesn’t change much. I would like to reference it so that when it does change, it only has to be changed once.

I am getting very frustrated as most of the examples I found are leveraging pre-existing knowledge of LaTex. I am trying to use the \ref{} command to call the chunk of text.

  • it sounds like this would be a job for \include rather than the xr package
    – cmhughes
    Apr 5, 2012 at 20:51
  • Welcome to TeX.SE! Please consider providing a bit more information about the structure of your document(s). For instance, which document class(es) do you use? Do you use the basic \ref command or one of the more advanced commands, such as \autoref and/or \cref, that are provided by the hyperref and cleveref packages, respectively? Lastly, your question isn't clear about your objective: Are you trying to create cross-references to items (e.g., sections and equations) contained in an external document, or are you looking to include chunks of text stored in an external document?
    – Mico
    Apr 5, 2012 at 20:52
  • Perhaps you are looking for something like the catchfilebetweentags package. Search this site for that keyword, or perhaps start with \input only part of a file using catchfilebetweentags package. It would be helpful if you provided a mock up of the external file and some examples of how you want to reference/include it, so that we can more directly answer your question. Apr 5, 2012 at 21:10

1 Answer 1


I think you may be confused. Cross-referencing usually uses a \label-\ref system that references a specific object by virtue of its label. For example,

  Blah blah, nice.\label{mytheorem}
See Theorem~\ref{mytheorem}.

This cross-referencing does not return the contents of the environment. If this is what you're after, and storing it in an external file, then you should use


\input{<file>} literally puts the contents of <file> into your document at the place where you call \input. So, if the contents of <file> changes, it will change wherever you \input it.

  • Ok, is there a similar command that allow me to select portions of <file> and include paragraphs of text from it?
    – TheSavo
    Apr 5, 2012 at 20:59
  • 1
    @TheSavo: If you're talking about extracting so from line X to Y in a file, then listings might help. But not easily in general, AFAIK (I remember a question about this but I'll have to look for it). However, you can nest the inclusion. So, any boilerplate information you want to use, you can put in a separate file. Also see When should I use \input vs. \include?
    – Werner
    Apr 5, 2012 at 21:03

You must log in to answer this question.

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