Help:Citation templates and reference anchors

From the AARoads Wiki: Read about the road before you go
Jump to navigation Jump to search

Citation templates are often used to format the citations that show in the reference list. Many of these templates can create anchors that allow links from reference templates that are placed in-text with the content to the full citation in the reference list. These links are a convenience and are not a requirement; the use of reference and citation templates is also not required.

The in-text links are formatted manually or automatically as #CITEREF normally followed by the author name(s) and the year of publication. The citation template then creates an anchor using an HTML id manually or automatically formatted as CITEREF followed by the author last name(s) and the year. For citations without an author, the anchor can be customized.

Anchor support across citation templates is not standardized, and not all templates support anchors.

This page discusses only general citation templates and does not include any of the hundreds of specific-source templates. See Category:Specific-source templates, although many of these may be in Category:Citation templates or not properly categorized. Many specific-source templates use a general citation template as a meta-template.

Types of anchors

  • Plain anchor— the anchor is the defined text
  • CITEREF anchor— the anchor consists of CITEREF plus the defined text
  • Auto anchor— the anchor is automatically built by concatenating (running together) template fields such as the author last names and the year (e.g. SmithJones1999)
  • Custom anchor— the anchor is created from text defined in a field
  • Reference- anchor— the anchor consists of Reference- plus the defined text

Anchor types can be combined. For example, a template could create a CITEREF auto anchor.

In-text reference templates that create links to anchors

These templates always create a link of the form #CITEREF plus the author last names (up to four) plus the year.

setting |Ref= will create a custom link.

When a custom link is needed, the first author field can be replaced by the desired text.

Citation templates that create anchors

These templates always create a CITEREF auto anchor; setting |ref= will create a custom plain anchor.
These citation templates create a plain custom anchor when |ref= is set or a CITEREF custom anchor when |harvid= is set.
These citation templates create a plain custom anchor when |ref= is set or a Reference- custom anchor when |id= is set.
These citation templates create a plain custom anchor when |ref= is set.
These citation templates do not support anchors.

Date and year fields

Most of the templates will attempt to extract the year from the date field. If the date consists of anything other than a full date then the year extraction will fail. Most templates include a month field that can be used in conjunction with the year field.

Custom anchors

Custom anchors must be used when the template does not support auto anchors or when there is no author. The name of the website or organization can be used in place of the author name. Custom anchors can be crafted manually or with {{SfnRef}} / {{harvid}}.

Link and anchor names

Manually created names should start with CITEREF. If you choose to not do this, then the first character must begin with a letter A-Z or a-z. All names are case sensitive. HTML ids have other name rules, but the MediaWiki software automatically encodes spaces to underlines and Unicode characters to their equivalent hexadecimal characters.

Manual links to citation anchors

To avoid the sometimes difficult-to-remember syntax for manual links to CITEREF anchors, {{citeref}} can be used to create internal wikilinks with either small superscript-style labels (like this[n]) or plain free-text labels to such anchors. It can be used inside of other citations. In addition, {{citelink}} and {{remoteref}} can also create internal wikilinks, and may also be used to create wikilinks to other pages, such as linking to a CITEREF anchor from the article Talk page (or from any page, like this[1]), or to an anchor in a foreign Wikipedia article (like this[2]) and may also be used inside another citation.

Duplicate in-text links

Multiple instances of the same in-text link may be used to link to one citation in the reference list, and the in-text links can use the same name.

Duplicate anchors

The anchor name for each citation must be unique. Multiple instances of the same anchor will create ambiguous links and will cause invalid HTML output of the page. There is no automatic error checking. The W3C Validation Service can be used to check for duplicate HTML ids.

Where the same author has multiple publications within the same year, the citation template will create a duplicate anchor. The standard solution is to add a lower case alpha character to the year.

Templates without anchors

{{Wikicite}} can be used to add an anchor for any of the templates that do not support anchors. The |ref= field is used to create the anchor and the |reference= field is set to the citation template. The |ref= field should be enclosed in quotes and can be defined with {{SfnRef}}.