Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Custom start for arabic cross reference numbering scheme #11038

Open
maptv opened this issue Oct 11, 2024 · 3 comments
Open
Labels
crossref enhancement New feature or request

Comments

@maptv
Copy link

maptv commented Oct 11, 2024

It would be great to add the ability to set the starting point for the arabic cross reference numbering scheme: https://quarto.org/docs/authoring/cross-reference-options.html#numbering

This is already possible for all of the other cross reference numbering schemes.

The two use cases for this would be to start a new document with zero-based numbering and to continue the numbers from an existing document in a subsequent document:

---
title: "New document with zero-based numbering"
crossref:
  labels: arabic 0
---
---
title: " Continuation to a document with X figures, Y tables, and Z code listings"
crossref:
  fig-labels: arabic X
  tbl-labels: arabic Y
  lst-labels: arabic Z
---

I can volunteer to work on a pull request if someone could direct me to the place where the cross reference numbering logic lives.

@cscheid
Copy link
Collaborator

cscheid commented Oct 11, 2024

@maptv Thanks for the offer, but you should be aware that this is a big project. The crossref system is pretty complicated, because it needs to work across a variety of formats. At the very least, we need to be able to support

  • html
  • latex
  • typst
  • docx

Each of these is a different system, and although you might only need one of those formats, we don't want to add features that only work on a single format. I'm saying this so that your expectations are calibrated. We also need you to be willing to sign a contributor agreement, as described here.

@cderv cderv added the enhancement New feature or request label Oct 11, 2024
@maptv
Copy link
Author

maptv commented Oct 11, 2024

@cscheid, Thanks for the quick response. I sent the contributor agreement to JJ.

I think it makes sense to start with html and then work down the checklist:

  • html
  • latex
  • typst
  • docx

I see files like crossref.ts and list.ts. Where would I start working on this?

@cscheid cscheid transferred this issue from quarto-dev/quarto Oct 11, 2024
@cscheid
Copy link
Collaborator

cscheid commented Oct 11, 2024

(@maptv I moved this discussion to the relevant repo.)

You should start by installing the dev version of Quarto. The HTML crossref system is at least partly implemented in Lua in the Pandoc filters. Look at

function formatNumberOption(type, order, default)
-- alias num and section (set section to nil if we aren't using chapters)
local num = order.order
local section = order.section
if not crossrefOption("chapters", false) then
section = nil
elseif section ~= nil and section[1] == 0 then
section = nil
elseif crossref.maxHeading ~= 1 then
section = nil
end
-- return a pandoc.Str w/ chapter prefix (if any)
local function resolve(num)
if section then
local sectionIndex = section[1]
if crossrefOption("chapters-alpha", false) then
sectionIndex = string.char(64 + sectionIndex)
elseif crossref.startAppendix ~= nil and sectionIndex >= crossref.startAppendix then
sectionIndex = string.char(64 + sectionIndex - crossref.startAppendix + 1)
else
sectionIndex = tostring(sectionIndex)
end
num = sectionIndex .. "." .. num
end
return pandoc.Inlines({ pandoc.Str(num) })
end
-- Compute option name and default value
local opt = type .. "-labels"
if default == nil then
default = stringToInlines("arabic")
end
-- See if there a global label option, if so, use that
-- if the type specific label isn't specified
local labelOpt = crossrefOption("labels", default);
-- determine the style
local styleRaw = crossrefOption(opt, labelOpt)
local numberStyle = pandoc.utils.stringify(styleRaw)
-- process the style
if (numberStyle == "arabic") then
return resolve(tostring(num))
elseif (string.match(numberStyle, "^alpha ")) then
-- permits the user to include the character that they'd like
-- to start the numbering with (e.g. alpha a vs. alpha A)
local s = split(numberStyle, " ")
local startIndexChar = s[2]
if (startIndexChar == nil or startIndexChar == " ") then
startIndexChar = "a"
end
-- local startIndexChar = string.sub(numberStyle, -1)
-- if (startIndexChar == " ") then
-- startIndexChar = "a"
-- end
-- print(numberStyle)
local startIndex = utf8.codepoint(startIndexChar)
return resolve(utf8.char(startIndex + num - 1))
elseif (string.match(numberStyle, "^roman")) then
-- permits the user to express `roman` or `roman i` or `roman I` to
-- use lower / uppper case roman numerals
local lower = false
if (string.sub(numberStyle, -#"i") == "i") then
lower = true
end
return resolve(toRoman(num, lower))
else
-- otherwise treat the value as a list of values to use
-- to display the numbers
local entryCount = #styleRaw
-- select an index based upon the num, wrapping it around
local entryIndex = (num - 1) % entryCount + 1
local option = styleRaw[entryIndex]:clone()
if section then
tprepend(option, { pandoc.Str(tostring(section[1]) .. ".") })
end
return pandoc.Inlines({ option })
end
end

That should get you a toehold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crossref enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants