rchaput / acronyms

Adds support for Acronyms, and List of Acronyms, to Quarto documents.
GNU General Public License v3.0
20 stars 2 forks source link

option to sort alphabetically and ignore letter case #4

Closed agdamsbo closed 1 year ago

agdamsbo commented 1 year ago

Hi. This is a great extension!

I am using the extension as part of a report. I want to sort acronyms/glossaries and ignore if the start letter is capital or not. Is this possible?

Below is a try at illustrating the case:

---
title: Alphabetical glossary
format: pdf
editor: source
filters:
  - acronyms
acronyms:
  sorting: "alphabetical"
  keys:
    - shortname: Qt
      longname: Quarto
    - shortname: iQt
      longname: inside-Quarto
    - shortname: aA
      longname: alphabetically
    - shortname: H
      longname: handle
---

This \acr{Qt} extension adds the ability to automatically \acr{handle} 
 \acr{iQt} acronyms.
Would love to be able to sort \acr{aA}, independent of letter size.

The desired output would be to have to loa order like this: aA H iQt Qt

but the current sorting order is the following: H Qt aA iQt

Makes sense? Presume it's something with the lua sorting, that I don't get?

agdamsbo commented 1 year ago

So apparently, I was only one additional search away. Here is the solution from StackOverflow

By adding the following option to _extention/acronyms/sorting_acronyms.lua, I get the desired behavior:

-- Sort acronyms by their shortname, in case insensitive alphabetical order.
sorting_strategies["alphabetical_case"] = function(acronym1, acronym2)
    -- TODO: check that this works with UTF-8 characters
    return acronym1.shortname:upper() < acronym2.shortname:upper()
end
rchaput commented 1 year ago

Hello,

Thank you for using acronyms!

This would be indeed a fine addition. I do not currently have time to implement the corresponding tests and write the documentation, but your solution should work as-is. I will add this feature to the master branch in a few days.

agdamsbo commented 1 year ago

Hello,

Thank you for using acronyms!

This would be indeed a fine addition. I do not currently have time to implement the corresponding tests and write the documentation, but your solution should work as-is. I will add this feature to the master branch in a few days.

Yeah, I would have liked to create a PR when writing the last comment, but ran out og time.

agdamsbo commented 1 year ago

Ok, so I had a go at the PR as #5 . Documentation is missing though, but the bigger issue may be a good naming for this sorting option. My suggestion is a little lengthy.

rchaput commented 1 year ago

Many thanks for the PR! You made my job a lot easier. I took the liberty of changing a bit your commits (renaming the option, fixing the test case, adding description to a commit). Unfortunately, I could not push these new commits back to the PR, so I created a new branch instead (case-insensitive). Everything seems to work, so I think I will just close your PR, merge the branch back to master, and release a new version.

Thank you again for both the idea, and the implementation/test case!

agdamsbo commented 1 year ago

Cool. Thank you for the work.