The GMT.jl documentation uses a custom Quarto shortcode system for creating cross-references throughout the documentation. This system is implemented via the gmtref shortcode, which provides a unified, maintainable way to link to modules, utilities, GMT types, and general documentation pages.
The cross-reference system is implemented as a Lua-based Quarto extension located at:
_extensions/gmtref/gmtref.lua
This extension processes {{< gmtref >}} shortcodes during the Quarto rendering process and converts them into properly formatted HTML links.
The general syntax for using the gmtref shortcode is:
{{< gmtref NAME type=TYPE >}}Where:
NAMEis the name of the item you want to referencetype=TYPEis optional and specifies the type of reference
Syntax:
{{< gmtref plot >}}
{{< gmtref grdimage >}}
{{< gmtref coast >}}Output:
- Creates a link to
/documentation/modules/MODULE_NAME.html - Display text: The module name (e.g., "plot", "grdimage")
- Example:
plot(clickable link)
When to use:
- Referencing any GMT module (e.g., plot, coast, grdimage, basemap, etc.)
- This is the default type, so you don't need to specify
type=module
Syntax:
{{< gmtref mat2grid >}}
{{< gmtref gmtread >}}
{{< gmtref extrude type=util >}}Output:
- Creates a link to
/documentation/utilities/UTILITY_NAME.html - Display text: The utility name
- Example:
mat2grid(clickable link)
When to use:
- Referencing GMT.jl utility functions
- The extension auto-detects common utilities, so
type=utilis optional for known utilities - Known utilities include: mat2grid, mat2img, mat2ds, gmtread, gmtwrite, extrude, imshow, etc.
Auto-detected utilities: The extension maintains a list of ~140 known utility names and will automatically classify them correctly even without type=util.
Syntax:
{{< gmtref GMTgrid type=gmttype >}}
{{< gmtref GMTimage type=gmttype >}}
{{< gmtref GMTdataset type=gmttype >}}
{{< gmtref GMTcpt type=gmttype >}}
{{< gmtref GMTps type=gmttype >}}
{{< gmtref GMTfv type=gmttype >}}Output:
- Creates a link to
/documentation/general/types.html#ANCHOR - Display text: The type name formatted as code (e.g.,
GMTgrid) - Example:
GMTgrid(clickable, monospaced code text)
Anchors used:
- GMTgrid →
#grid-type - GMTimage →
#image-type - GMTdataset →
#dataset-type - GMTcpt →
#cpt-type - GMTps →
#postscript-type - GMTfv →
#face-vertices-type
When to use:
- Referencing GMT.jl data types in documentation
- MUST include
type=gmttypeparameter - Use whenever mentioning these types in prose (not in code blocks or function signatures)
Important: GMT types are rendered as code-formatted text (with backticks in HTML: <code>GMTgrid</code>), which distinguishes them visually from regular text.
Syntax:
{{< gmtref introduction type=general >}}
{{< gmtref quick_learn type=general >}}
{{< gmtref modules type=general >}}
{{< gmtref monolithic type=general >}}
{{< gmtref types type=general >}}Output:
- Creates a link to
/documentation/general/PAGE_NAME.html - Display text: Capitalized, formatted name (e.g., "Introduction", "Quick learn")
- Example:
Introduction(clickable link)
Supported general pages:
introduction→ Introductionquick_learn→ Quick learnmodules→ Modulesmonolithic→ Monolithic (also accepts alternate spelling "monolitic")types→ Types
When to use:
- Linking to general documentation sections
- MUST include
type=generalparameter
The extension generates absolute paths from the site root (starting with /). Quarto automatically converts these to relative paths based on the document's location during rendering.
For example:
- Source:
{{< gmtref GMTgrid type=gmttype >}} - Extension generates:
/documentation/general/types.html#grid-type - Quarto converts to:
../general/types.html#grid-type(if in a module doc) - Or:
../../documentation/general/types.html#grid-type(if in an example)
The extension includes auto-detection for utilities:
- When you use
{{< gmtref NAME >}}without a type parameter - It checks if NAME matches the list of known utilities
- If found, it automatically treats it as
type=util - Otherwise, it defaults to
type=module
This means both of these work identically:
{{< gmtref mat2grid >}}
{{< gmtref mat2grid type=util >}}Different reference types format their display text differently:
| Type | Display Format | HTML Element |
|---|---|---|
| Module | Plain text | <a>name</a> |
| Utility | Plain text | <a>name</a> |
| GMT Type | Code formatted | <a><code>GMTtype</code></a> |
| General | Capitalized | <a>Capitalized name</a> |
The code formatting for GMT types uses Pandoc's pandoc.Code() function to ensure proper rendering.
DO use gmtref for:
- ✓ All references to GMT modules
- ✓ All references to GMT.jl utilities
- ✓ All references to GMT data types (GMTgrid, GMTimage, etc.)
- ✓ All references to general documentation pages
- ✓ Cross-references within documentation text
DO NOT use gmtref for:
- ✗ Code blocks or function signatures
- ✗ Julia type annotations (e.g.,
Vector{GMTdataset}) - ✗ External links
- ✗ Section headers (use Quarto's native
{#sec-id}instead)
GMT modules know how to manipulate data stored in {{< gmtref GMTgrid type=gmttype >}},
{{< gmtref GMTimage type=gmttype >}}, {{< gmtref GMTdataset type=gmttype >}},
{{< gmtref GMTcpt type=gmttype >}} and {{< gmtref GMTps type=gmttype >}} objects.The helper functions {{< gmtref mat2grid >}}, {{< gmtref mat2img >}} and
{{< gmtref mat2ds >}} exist to create GMT data structures. You can then pass
these to modules like {{< gmtref grdimage >}} or {{< gmtref plot >}}.For more details, see the {{< gmtref introduction type=general >}} and
{{< gmtref quick_learn type=general >}} pages.Use {{< gmtref gmtread >}} to read a file and return a {{< gmtref GMTdataset type=gmttype >}},
then pass it to {{< gmtref plot >}} for visualization.- If file locations change, you only update the Lua extension
- All references automatically update site-wide
- No need to hunt for broken links
- Uniform link formatting across all documentation
- GMT types always render as code
- Predictable, standardized syntax
- The extension validates reference types
- Known utilities are auto-detected
- Invalid references are easier to spot during rendering
- Adding new reference types is simple (just extend the Lua script)
- Works with Quarto's build system
- Compatible with both local and deployed documentation
Issue: Link shows as plain text instead of rendering
{{< gmtref plot >}} <!-- Renders as literal text -->Solution: Check for typos in the shortcode syntax. Ensure proper spacing and closing >}}.
Issue: GMT type not rendering as code
{{< gmtref GMTgrid >}} <!-- Missing type parameter -->Solution: Always include type=gmttype for GMT data types:
{{< gmtref GMTgrid type=gmttype >}}Issue: Link points to wrong location
Solution: Verify the reference type. Use type=util for utilities, type=general for general docs, etc.
Issue: "File not found" errors when clicking links Solution:
- Ensure the target file exists and is included in
_quarto.ymlrender list - Check spelling of the reference name
- Verify the file is being rendered (check
_sitedirectory)
When updating old documentation, replace these patterns:
Old Format → New Format:
# Old manual links
[`GMTgrid`](types.html#grid-type)
→ {{< gmtref GMTgrid type=gmttype >}}
[Grid type](types.html#grid-type)
→ {{< gmtref GMTgrid type=gmttype >}}
[Introduction](introduction.html)
→ {{< gmtref introduction type=general >}}
\apilink{mat2grid}
→ {{< gmtref mat2grid >}}Scripts have been created to help migrate old references:
replace_gmttype_refs.py- Replaces manual GMT type linksreplace_gmttype_refs2.py- Replaces plain text GMT type referencesfix_type_references.py- Fixes broken [Type name] references
The gmtref.lua extension is structured as follows:
return {
['gmtref'] = function(args, kwargs)
-- 1. Extract the reference name from args[1]
local name = pandoc.utils.stringify(args[1])
-- 2. Determine the reference type
local ref_type = "module" -- default
if kwargs["type"] then
ref_type = pandoc.utils.stringify(kwargs["type"])
end
-- 3. Auto-detect utilities
-- (check against known utility list)
-- 4. Build the path based on ref_type
-- - util: /documentation/utilities/NAME.html
-- - gmttype: /documentation/general/types.html#ANCHOR
-- - general: /documentation/general/NAME.html
-- - module: /documentation/modules/NAME.html
-- 5. Format the link content
-- - gmttype uses pandoc.Code(name)
-- - general capitalizes and formats the name
-- - others use plain name
-- 6. Return pandoc.Link(link_content, path)
end
}The {{< gmtref >}} shortcode system provides a robust, maintainable way to create cross-references in GMT.jl documentation:
- Modules:
{{< gmtref plot >}} - Utilities:
{{< gmtref mat2grid >}}or{{< gmtref mat2grid type=util >}} - GMT Types:
{{< gmtref GMTgrid type=gmttype >}}(renders as code) - General Docs:
{{< gmtref introduction type=general >}}
Always use this system instead of manual HTML or Markdown links to ensure consistency and maintainability across the documentation.