diff --git a/text-crossrefs/README.md b/text-crossrefs/README.md index 4a3bf7c..f4d120e 100644 --- a/text-crossrefs/README.md +++ b/text-crossrefs/README.md @@ -209,7 +209,7 @@ and should be collapsed by the macro when it is desirable: ### Common options {#common-opts} -The following metadata fields can be set as strings: +The following metadata fields can be set: * `tcrf-references-enum-separator`: * the string between two references in an enumeration in a reference span; @@ -219,17 +219,18 @@ The following metadata fields can be set as strings: * defaults to `>`. * `tcrf-only-explicit-labels`: * set it to `true` if you want _crossrefenum_ to refer to spans with class `label` only; - * defaults to `false`. + * defaults to `false`, can be set to `true` or `yes` (without quotes). * `tcrf-default-prefixref`: * default value for the `prefixref` attribute; - * defaults to `yes`. + * defaults to `yes`, can be set to `no` or `false` (without quotes). * `tcrf-default-reftype`: * default value for the `reftype` attribute; * defaults to `page`. -### Options specific to DOCX and ODT/Opendocument +### Options specific to DOCX, ODT/Opendocument and (by default) Typst {#docx-odt-options} -Here are some metadata fields for the `docx`, `odt` and `opendocument` formats only +Here are some metadata fields for the `docx`, `odt` and `opendocument` formats. +They are also used for `typst` unless [`tcrf-typst-crossrefenum` is set to `true`](#typst-options) (see [above](#prefixes-tex) why they are ignored in ConTeXt and LaTeX output): * `tcrf-page-prefix`: @@ -256,7 +257,7 @@ Here are some metadata fields for the `docx`, `odt` and `opendocument` formats o * defines if the prefixes of the type printed first in a reference to page and note should be repeated (like in “p. 6, n. 1 and p. 9, n. 3”) or set globally at the beginning of the enumeration (like in “pp. 6, n. 1 and 9, n. 3”); - * defaults to `no`, can be set to `yes`. + * defaults to `no`, can be set to `yes` or `true` (without quotes). * `tcrf-pagenote-first-type`: * the type of the reference number that is printed first in references to page and note; * defaults to `page`, can be set to `note`. @@ -321,3 +322,9 @@ not that: [@Jones1973, p. 5-70[]{#ref-to-jones}; @Doe2004] ``` + +# Breaking changes + +Until December 2025, `yes`, `no`, `true` and `false` as metadata values +had to be put within double quotes. Now, they must not be quoted at all, +which is a more standard way to handle boolean values in YAML. diff --git a/text-crossrefs/text-crossrefs.lua b/text-crossrefs/text-crossrefs.lua index 9d74255..bedd7b1 100644 --- a/text-crossrefs/text-crossrefs.lua +++ b/text-crossrefs/text-crossrefs.lua @@ -87,17 +87,18 @@ local config = { pagenote_first_type = 'page', pagenote_separator = ', ', pagenote_at_end = '', - pagenote_factorize_first_prefix_in_enum = 'no', + pagenote_factorize_first_prefix_in_enum = false, multiple_delimiter = ', ', multiple_before_last = ' and ', references_range_separator = '>', range_separator = '–', references_enum_separator = ', ', - only_explicit_labels = 'false', + only_explicit_labels = false, default_reftype = 'page', - default_prefixref = 'yes', + default_prefixref = true, filelabel_ref_separator = '::', range_delim_crossrefenum = ' to ', + typst_crossrefenum = false, additional_types = {} } @@ -133,8 +134,13 @@ local function set_configuration_item_from_metadata(item, metamap) table.insert(config[item], value_metalist[1].text) end else - -- The metadata value is a single Str in a MetaInlines. - config[item] = metamap[metakey][1].text + local value = metamap[metakey] + if type(value) == 'boolean' then + config[item] = value + else + -- The metadata value is a single Str in a MetaInlines. + config[item] = value[1].text + end end end end @@ -246,7 +252,7 @@ local labels_in_current_note = {} local collect_note_labels = { Span = function(span) if span.identifier ~= '' - and (config.only_explicit_labels == 'false' or span.classes:includes('label')) + and ((not config.only_explicit_labels) or span.classes:includes('label')) then table.insert(labels_in_current_note, span.identifier) end @@ -386,13 +392,19 @@ local function get_ref_type(span) end local function if_prefixed(span) - local prefixed_attr_value = span.attributes[PREFIXED_ATTR] or config.default_prefixref - if prefixed_attr_value ~= 'yes' and prefixed_attr_value ~= 'no' then - error_on_attr(PREFIXED_ATTR, prefixed_attr_value, span.content) - prefixed_attr_value = config.default_prefixref - end + -- yes, true, no and false in the metadata header are parsed as booleans, + -- but they are parsed as strings in the value of a span attribute. local is_prefixed = true - if prefixed_attr_value == 'no' then is_prefixed = false end + local prefixed_attr_value = span.attributes[PREFIXED_ATTR] + if prefixed_attr_value then + if prefixed_attr_value ~= 'yes' and prefixed_attr_value ~= 'no' then + error_on_attr(PREFIXED_ATTR, prefixed_attr_value, span.content) + prefixed_attr_value = config.default_prefixref + end + if prefixed_attr_value == 'no' then is_prefixed = false end + else + is_prefixed = config.default_prefixref + end return is_prefixed end @@ -410,7 +422,7 @@ local function make_crossrefenum_first_arg(ref_type) end local function make_crossrefenum_second_arg(is_prefixed) - local is_prefixed_is_explicit = is_prefixed ~= (config.default_prefixref == 'yes') + local is_prefixed_is_explicit = is_prefixed ~= config.default_prefixref local crossrefenum_second_arg = '' local is_prefixed_string = '' if is_prefixed_is_explicit then @@ -585,8 +597,7 @@ local function make_raw_content_xml(refs, ref_type, is_prefixed) local is_enumeration = #refs > 1 local global_prefix = '' if is_enumeration and is_prefixed - and (ref_type ~= 'pagenote' - or pagenote_factorize_first_prefix_in_enum == 'yes') + and ((ref_type ~= 'pagenote') or config.pagenote_factorize_first_prefix_in_enum) then global_prefix = make_global_prefix_xml(ref_type) is_prefixed = false