Help:Transclusion

Transclusion displays the contents found on another page without having to copy-paste nor synchronize any later changes. It is most commonly used to group text into logical and reasonably sized chunks—most frequently as chapters or sections. Examine the transcluded text at The Wind in the Willows (1913)/Chapter 1 and compare with some of the source text found at Page:Wind in the Willows (1913).djvu/19. As the individual pages from Index:Wind in the Willows (1913).djvu were saved in the "Page:" namespace, they populated into the chapters of the book through transclusion. Creating readable sections from scanned pages is the most common use of transclusion on Wikisource.

This help page first examines the most common methods of transclusion, this should be enough to help you manage your first texts. Next the page discusses more advanced and uncommon uses for transclusion which can stretch the digital text beyond familiar boundaries. And finally, it examines the full functionality of the two tranclusion methods. If you still have unanswered questions or any problems using transclusion, please post at the Scriptorium or at Scriptorium (Help). Someone there will do their best to help you!

How to transclude full pages
You will most often be transcluding many pages together from the Page: namespace into the main presentation space of the wiki—as you saw at The Wind in the Willows (1913)/Chapter 1. There are three methods which can perform full-page transclusion. The  function is preferred, while the Page template and the direct transclusion of a page from the page namespace also work but are discouraged. Most of the time, the tag will be the best method of transcluding, but you may still run across the older template method when editing existing texts.

Where the pages to be transcluded would be placed inside another tag such as a  pair, then the Magic word   should be used instead, with the relevant parameters translated accordingly.

The syntax for  is as follows:


 * "file name.djvu" is replaced with the exact name of the Index you are working with (do not include the "Index:" prefix).
 * The number after the slash (/) following the file name of the first page you wish to transclude is "x".
 * The number after the slash (/) following the file name of the final page you wish to transclude is "y".

How to transclude a portion of a page
Sometimes you will not want transclude a full page all together, examine Page:Popular Science Monthly Volume 25.djvu/169. When two chapters or logical sections appear on the same page, instead of the entire page you need a way to transclude only the relevant parts of the page into the main presentation space. The example page from above presents as Popular Science Monthly/Volume 25/June 1884/Modes of Reproduction in Plants. This is accomplished using Labeled Section Transclusion (LST). The section breaks are marked with anchors in the Page: namespace. Then only the relevant part of the page, rather than the entire page, is called for during transclusion.

Adding section labels
To mark sections in the scan (Page: namespace), insert the following syntax into the typed proofreading text at the start of every new section :

Alternatively you can use start  and end   labels at the respective places in the text.

Note:
 * Section tags are recommended to be wrapped in quotes  to avoid ambiguity.
 * These are just free text labels, however, making labels contextual to the page can have advantages.
 * Use of letters and numbers is usually a recommendation, and other extended characters may cause some issues when transcluding.
 * Labels need to be unique on a page if they are referred to in a  tag, otherwise it can't be determined which of the identically-named sections should be used.
 * If you are using  markers, please make sure to open and close them inside the sections, or else section transcluding will not work properly.

Transcluding to main namespace (file-based indexes)
The following applies to "file-based" indexes (ones that use DJVU or PDF files)

When the section ends part-way through a page
An extra parameter,, is required in to end the transclusion at the anchor. The syntax is as follows:


 * is replaced with the exact name of the file you are working with. Do not include the "Index:" prefix.
 * The number after the slash (/) following the file name of the first page you wish to transclude is
 * The number after the slash (/) following the file name of the final page you wish to transclude is.
 * is replaced with the name of the anchor you inserted.

Handling spaces and punctuation in attribute values (the bit after the equals signs) is as usual for HTML:
 * If the value of any attribute contains a space, wrap the whole value in straight quotes (either single or double).
 * If the value contains a double quote, wrap the whole thing in single quotes:
 * If the value contains a single quote, wrap in double quotes:
 * If the value contains both single and double quotes, wrap in double quotes and escape the double quotes in the value with, like this:

When the section begins part-way through a page
To begin the first page of a chapter or section at the anchor, a  parameter is needed. Follow this pattern:

When the section begins and ends part-way through a page
If a section begins part way through one page and finishes part way through another, then both and  parameters may need to be used at once:

Note, the "from" and "to" section names do not have to be the same. It is common for them to be the same, but not required.

When the section begins and ends on the same page
To transclude only a single section on a single page, you can use the and  parameters:

Transcluding every other page
To transclude every other page (e.g. for a document with single-sided leaves), you can use the parameter:

Transcluding irregular sets of pages
The  parameter can take a comma-separated list of page numbers, as well as page ranges in the format.

and  also work with  : they apply, as normal, to the first and last pages.

Transcluding to main namespace (image-based indexes)
For "image-based" indexes (i.e. ones constructed from a list of individual pages), only  and   are accepted by the   tag:   and   cannot be used (because filenames can include   and  ). and  also work.

Also, the pages are referred to by their title, and not by their position in the index.

Transcluding sections without the page tag
Use of the  tag as above is the preferred way to transclude sections of pages. However, this tag does not work on other Page: pages or in the Index namespace. On these pages, you can use Labeled Section Transclusion (LST) directly to transclude a section:

In this case, the following format can be used:
 * is replaced with page you wish to transclude from (including the  namespace and   numeric suffix as necessary)
 * is the section you wish to transclude.
 * is the section you wish to transclude.

Deprecated method using Page Another, deprecated, method is to use the page template, You may see this in some older works, but generally this template should no longer be used.

Use the Page template as follows, replacing  with the scan file name and   with the page number:

How to place images with transcluded text
The preferred means of placing a picture or other image in the main pagespace is to upload the cropped image to Wikimedia Commons as a separate picture, for example as a png or jpeg file.

The page image could also be displayed in the book's Wikisource mainspace like at Personal Recollections of Joan of Arc/Book I/Chapter 2, using:

Advanced usage
Transclusion can also be used to produce alternative displays of text without having to repeat the proofreading and validation. Celtic Fairy Tales/Guleesh presents the story of Guleesh as published in Celtic Fairy Tales. It shows the preceding and following stories from that publication and also has a link to the foreword and commentary by the editor. Alternatively Guleesh presents the same text as a stand-alone work. Presenting suitable titles outside of the editions they may have been collected is not a necessary task any more than it is necessary to present a famous essay as a subpage of the magazine it happened to be printed in. However, both are possible by transcluding the same validated text. The consensus has been to allow individual editors to use whichever style they like inclusively.

Using the function
Most of the time, the  tag will be the best method of transcluding. There is only one required parameter, which is index=. This field must always be supplied or nothing happens. The exact pattern to use is as follows:  where the name file name.djvu is just a placeholder for whatever file you have used when proofreading.

Where the pages to be transcluded would need to be placed inside another a tag such as a  pair, then the Magic word   should be used instead, with the relevant parameters translated accordingly. The parameters themselves have the same values and effects.

Try it out with a real file name: Copy "" into here and save. There is one other way to type this and have the same result. Try out. This works just the same. The important thing to know is that  will not work. If you use any spaces in the field, then you must also surround the field with quotation marks ("), or it will not work.

While you always must supply the index= field, if you do not add any other parameters this syntax will only transclude the index of the file. Whenever you also supply some of the optional parameters, the index will be superseded by your other commands. Some of these optional parameters must be paired together in order to work. The numbers used in these fields are the titular number after the / in the Page: namespace. The optional parameters are as follows:


 * from= (paired with to=) to supply the number of the first page to be transcluded
 * to= (paired with from=) to supply the number of the last page to be transcluded
 * fromsection= (paired with from=/to= or include= or exclude= ) to supply the initial anchor on the first page of the section.
 * The named section and any subsequent sections on the first page will be transcluded, all sections will be transcluded from the other pages
 * tosection= (paired with from=/to= or include= or exclude=) to supply the final anchor on the last page of the section
 * The named section and any previous sections on the last page will be transcluded, all sections will be transcluded from the other pages
 * onlysection= (paired with from=/to= or include= or exclude=) to supply the anchor used to mark off a section for transclusion
 * Only the named section will be transcluded, from all pages
 * step= (paired with from=/to= or include= or exclude=) to supply a incremental number where every x page will be transcluded.
 * Transclude every other page by increments of n. By example :  show the 1st, 3rd, 5th, 7th and 9th pages.
 * include provides a list of one or more pages
 * This allows a more flexible list. For example :  show the 2nd, 3rd, 4th, 5th and 9th pages.
 * This is often used to transclude a single page, or a single section of a single page along with
 * exclude removes pages that would otherwise be included
 * For example :  show the 1st, 6th, 7th, 8th and 10th pages.
 * header=1
 * Generates and inserts a header at the top of the page, using the information from the Index page. See mw:Help:Extension:ProofreadPage/2013_draft for more details. This is an alternative to adding a manual header.

You can use all the attributes on the same tag. For example  will show 1st, 5th, 7th, 9th and 31st pages.

Note: Good practice says that attributes within the &lt;pages> tag should be quoted. It is important to have unquoted empty attributes within tags, so please either quote empty attributes, or remove the unneeded optional attributes.

Considerations for Transcluded content
Certain mark-up (like table Syntax) must be entirely balanced across the Body sections of the pages transcluded. This either means that the markup or (rarer raw HTML used) must either be contained entirely within a single body or the approaches recommended at Help:Page breaks utilised.

Layout
See Help:Layout.

A Working, though deprecated Alternative
This is an alternative method, but should not be used unless there is a very good reason for not using the  tag.

The syntax for Page is as follows:


 * "file name.djvu" is replaced with the exact name of the file you are working with.
 * The number after the slash (/) following the file name of the page you wish to transclude is "x".
 * The original corresponding page number from the scanned volume is "z".
 * Note this can only transclude a single page at a time