Skip to content

Commit

Permalink
Merge pull request #7627 from quarto-dev/bugfix/7625
Browse files Browse the repository at this point in the history
support caption-location in custom crossrefs, use it correctly
  • Loading branch information
cscheid authored Nov 17, 2023
2 parents 3529a5e + 33cda7b commit 02d6695
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 48 deletions.
30 changes: 18 additions & 12 deletions src/resources/editor/tools/vs-code.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12251,6 +12251,15 @@ var require_yaml_intelligence_resources = __commonJS({
string: {
description: 'The description of the crossreferenceable object to be used in the title of the "list of" command. If unspecified, the field `name` is used.'
}
},
"caption-location": {
enum: [
"top",
"bottom",
"margin"
],
default: "bottom",
description: "The location of the caption relative to the crossreferenceable content."
}
}
}
Expand Down Expand Up @@ -20605,6 +20614,7 @@ var require_yaml_intelligence_resources = __commonJS({
"In LaTeX output, the name of the custom environment to be used.",
"In LaTeX output, the extension of the auxiliary file used by LaTeX to\ncollect names to be used in the custom \u201Clist of\u201D command. If omitted, a\nstring with prefix <code>lo</code> and suffix with the value of\n<code>ref-type</code> is used.",
"The description of the crossreferenceable object to be used in the\ntitle of the \u201Clist of\u201D command. If unspecified, the field\n<code>name</code> is used.",
"The location of the caption relative to the crossreferenceable\ncontent.",
"Use top level sections (H1) in this document as chapters.",
"The delimiter used between the prefix and the caption.",
"The title prefix used for figure captions.",
Expand Down Expand Up @@ -20807,6 +20817,10 @@ var require_yaml_intelligence_resources = __commonJS({
short: "The math font options for use with <code>xelatex</code> or\n<code>lualatex</code>.",
long: 'The math font options for use with <code>xelatex</code> or\n<code>lualatex</code> allowing any options available through <a href="https://ctan.org/pkg/fontspec"><code>fontspec</code></a>.'
},
{
short: "Adds additional directories to search for fonts when compiling with\nTypst.",
long: "Locally, Typst uses installed system fonts. In addition, some custom\npath can be specified to add directories that should be scanned for\nfonts. Setting this configuration will take precedence over any path set\nin TYPST_FONT_PATHS environment variable."
},
{
short: "The CJK font options for use with <code>xelatex</code> or\n<code>lualatex</code>.",
long: 'The CJK font options for use with <code>xelatex</code> or\n<code>lualatex</code> allowing any options available through <a href="https://ctan.org/pkg/fontspec"><code>fontspec</code></a>.'
Expand Down Expand Up @@ -21290,10 +21304,6 @@ var require_yaml_intelligence_resources = __commonJS({
short: "The mode to use when previewing this document.",
long: "The mode to use when previewing this document. To disable any special\npreviewing features, pass <code>raw</code> as the preview-mode."
},
{
short: "Adds additional directories to search for fonts when compiling with\nTypst.",
long: "Locally, Typst uses installed system fonts. In addition, some custom\npath can be specified to add directories that should be scanned for\nfonts. Setting this configuration will take precedence over any path set\nin TYPST_FONT_PATHS environment variable."
},
{
short: "Adds the necessary setup to the document preamble to generate PDF/A\nof the type specified.",
long: 'Adds the necessary setup to the document preamble to generate PDF/A\nof the type specified.\nIf the value is set to <code>true</code>, <code>1b:2005</code> will\nbe used as default.\nTo successfully generate PDF/A the required ICC color profiles have\nto be available and the content and all included files (such as images)\nhave to be standard conforming. The ICC profiles and output intent may\nbe specified using the variables <code>pdfaiccprofile</code> and\n<code>pdfaintent</code>. See also <a href="https://wiki.contextgarden.net/PDF/A">ConTeXt PDFA</a> for more\ndetails.'
Expand Down Expand Up @@ -22245,11 +22255,7 @@ var require_yaml_intelligence_resources = __commonJS({
},
"Disambiguating year suffix in author-date styles (e.g.&nbsp;\u201Ca\u201D in \u201CDoe,\n1999a\u201D).",
"Manuscript configuration",
"internal-schema-hack",
{
short: "Adds additional directories to search for fonts when compiling with\nTypst.",
long: "Locally, Typst uses installed system fonts. In addition, some custom\npath can be specified to add directories that should be scanned for\nfonts. Setting this configuration will take precedence over any path set\nin TYPST_FONT_PATHS environment variable."
}
"internal-schema-hack"
],
"schema/external-schemas.yml": [
{
Expand Down Expand Up @@ -22473,12 +22479,12 @@ var require_yaml_intelligence_resources = __commonJS({
mermaid: "%%"
},
"handlers/mermaid/schema.yml": {
_internalId: 178550,
_internalId: 178763,
type: "object",
description: "be an object",
properties: {
"mermaid-format": {
_internalId: 178542,
_internalId: 178755,
type: "enum",
enum: [
"png",
Expand All @@ -22494,7 +22500,7 @@ var require_yaml_intelligence_resources = __commonJS({
exhaustiveCompletions: true
},
theme: {
_internalId: 178549,
_internalId: 178762,
type: "anyOf",
anyOf: [
{
Expand Down
30 changes: 18 additions & 12 deletions src/resources/editor/tools/yaml/web-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 18 additions & 12 deletions src/resources/editor/tools/yaml/yaml-intelligence-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -5223,6 +5223,15 @@
"string": {
"description": "The description of the crossreferenceable object to be used in the title of the \"list of\" command. If unspecified, the field `name` is used."
}
},
"caption-location": {
"enum": [
"top",
"bottom",
"margin"
],
"default": "bottom",
"description": "The location of the caption relative to the crossreferenceable content."
}
}
}
Expand Down Expand Up @@ -13577,6 +13586,7 @@
"In LaTeX output, the name of the custom environment to be used.",
"In LaTeX output, the extension of the auxiliary file used by LaTeX to\ncollect names to be used in the custom “list of” command. If omitted, a\nstring with prefix <code>lo</code> and suffix with the value of\n<code>ref-type</code> is used.",
"The description of the crossreferenceable object to be used in the\ntitle of the “list of” command. If unspecified, the field\n<code>name</code> is used.",
"The location of the caption relative to the crossreferenceable\ncontent.",
"Use top level sections (H1) in this document as chapters.",
"The delimiter used between the prefix and the caption.",
"The title prefix used for figure captions.",
Expand Down Expand Up @@ -13779,6 +13789,10 @@
"short": "The math font options for use with <code>xelatex</code> or\n<code>lualatex</code>.",
"long": "The math font options for use with <code>xelatex</code> or\n<code>lualatex</code> allowing any options available through <a href=\"https://ctan.org/pkg/fontspec\"><code>fontspec</code></a>."
},
{
"short": "Adds additional directories to search for fonts when compiling with\nTypst.",
"long": "Locally, Typst uses installed system fonts. In addition, some custom\npath can be specified to add directories that should be scanned for\nfonts. Setting this configuration will take precedence over any path set\nin TYPST_FONT_PATHS environment variable."
},
{
"short": "The CJK font options for use with <code>xelatex</code> or\n<code>lualatex</code>.",
"long": "The CJK font options for use with <code>xelatex</code> or\n<code>lualatex</code> allowing any options available through <a href=\"https://ctan.org/pkg/fontspec\"><code>fontspec</code></a>."
Expand Down Expand Up @@ -14262,10 +14276,6 @@
"short": "The mode to use when previewing this document.",
"long": "The mode to use when previewing this document. To disable any special\npreviewing features, pass <code>raw</code> as the preview-mode."
},
{
"short": "Adds additional directories to search for fonts when compiling with\nTypst.",
"long": "Locally, Typst uses installed system fonts. In addition, some custom\npath can be specified to add directories that should be scanned for\nfonts. Setting this configuration will take precedence over any path set\nin TYPST_FONT_PATHS environment variable."
},
{
"short": "Adds the necessary setup to the document preamble to generate PDF/A\nof the type specified.",
"long": "Adds the necessary setup to the document preamble to generate PDF/A\nof the type specified.\nIf the value is set to <code>true</code>, <code>1b:2005</code> will\nbe used as default.\nTo successfully generate PDF/A the required ICC color profiles have\nto be available and the content and all included files (such as images)\nhave to be standard conforming. The ICC profiles and output intent may\nbe specified using the variables <code>pdfaiccprofile</code> and\n<code>pdfaintent</code>. See also <a href=\"https://wiki.contextgarden.net/PDF/A\">ConTeXt PDFA</a> for more\ndetails."
Expand Down Expand Up @@ -15217,11 +15227,7 @@
},
"Disambiguating year suffix in author-date styles (e.g.&nbsp;“a” in “Doe,\n1999a”).",
"Manuscript configuration",
"internal-schema-hack",
{
"short": "Adds additional directories to search for fonts when compiling with\nTypst.",
"long": "Locally, Typst uses installed system fonts. In addition, some custom\npath can be specified to add directories that should be scanned for\nfonts. Setting this configuration will take precedence over any path set\nin TYPST_FONT_PATHS environment variable."
}
"internal-schema-hack"
],
"schema/external-schemas.yml": [
{
Expand Down Expand Up @@ -15445,12 +15451,12 @@
"mermaid": "%%"
},
"handlers/mermaid/schema.yml": {
"_internalId": 178550,
"_internalId": 178763,
"type": "object",
"description": "be an object",
"properties": {
"mermaid-format": {
"_internalId": 178542,
"_internalId": 178755,
"type": "enum",
"enum": [
"png",
Expand All @@ -15466,7 +15472,7 @@
"exhaustiveCompletions": true
},
"theme": {
"_internalId": 178549,
"_internalId": 178762,
"type": "anyOf",
"anyOf": [
{
Expand Down
16 changes: 9 additions & 7 deletions src/resources/filters/crossref/custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function initialize_custom_crossref_categories(meta)
-- luacov: enable
end
local keys = {
["default-caption-location"] = function(v) return pandoc.utils.stringify(v) end,
["caption-location"] = function(v) return pandoc.utils.stringify(v) end,
["kind"] = function(v) return pandoc.utils.stringify(v) end,
["name"] = function(v) return pandoc.utils.stringify(v) end,
["prefix"] = function(v) return pandoc.utils.stringify(v) end,
Expand All @@ -30,7 +30,7 @@ function initialize_custom_crossref_categories(meta)
["space-before-numbering"] = function(v) return v end,
}
local obj_mapping = {
["default-caption-location"] = "default_caption_location",
["caption-location"] = "caption_location",
["latex-env"] = "latex_env",
["latex-list-of-file-extension"] = "latex_list_of_file_extension",
["latex-list-of-description"] = "latex_list_of_description",
Expand All @@ -44,8 +44,8 @@ function initialize_custom_crossref_categories(meta)
entry[key] = xform(v[key])
end
end
if entry["default-caption-location"] == nil then
entry["default-caption-location"] = "bottom"
if entry["caption-location"] == nil then
entry["caption-location"] = "bottom"
end
-- slightly inefficient because we recompute the indices at
-- every call, but should be totally ok for the number of categories
Expand All @@ -71,13 +71,11 @@ function initialize_custom_crossref_categories(meta)
local ref_type = entry["ref-type"]
local list_of_name = entry["latex-list-of-file-extension"] or ("lo" .. ref_type)
local list_of_description = entry["latex-list-of-description"] or name
local cap_location = entry["caption-location"] or "bottom"
local space_before_numbering = entry["space-before-numbering"]
if space_before_numbering == nil then
space_before_numbering = true
end

-- FIXME do we need different "lop" extensions for each category?
-- we should be able to test this by creating a document with listings and diagrams

inject(
usePackage("float") .. "\n" ..
Expand All @@ -86,6 +84,10 @@ function initialize_custom_crossref_categories(meta)
"\\floatname{".. env_name .. "}{" .. as_latex(title(ref_type, env_prefix)) .. "}\n"
)

if cap_location == "top" then
inject("\\floatstyle{plaintop}\n\\restylefloat{" .. env_name .. "}\n")
end

-- FIXME this is a bit of hack for the case of custom categories with
-- space-before-numbering: false
--
Expand Down
2 changes: 1 addition & 1 deletion src/resources/filters/customnodes/floatreftarget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function cap_location(float_or_layout)
float_or_layout.attributes['cap-location'] or
option_as_string(qualified_key) or
option_as_string('cap-location') or
crossref.categories.by_ref_type[ref].default_caption_location)
crossref.categories.by_ref_type[ref].caption_location)

if result ~= "margin" and result ~= "top" and result ~= "bottom" then
-- luacov: disable
Expand Down
2 changes: 1 addition & 1 deletion src/resources/filters/layout/pandoc3_figure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function render_pandoc3_figure()
content = figure.content[1],
caption = figure.caption.long[1],
kind = "quarto-float-fig",
caption_location = crossref.categories.by_ref_type["fig"].default_caption_location,
caption_location = crossref.categories.by_ref_type["fig"].caption_location,
supplement = "Figure",
})
end
Expand Down
Loading

0 comments on commit 02d6695

Please sign in to comment.