Answer Set
Answer Set is an Anki add-on
which gives better feedback for "type in the answer" style cards if there are
multiple correct answers and improves support for Indic scripts.
To install, open Anki and go to Tools > Add-ons in the menu bar, then click
"Get Add-ons..." and enter this code: 1827331674
Multiple Answers
If you try to have multiple answers in a "type in the answer" style card in
Anki, you will run into some issues. For instance, if you had "depart, go,
leave" as the answer but typed "leave, go" instead, you would get:

This makes it difficult to see which answers you got correct, and which you
actually did get wrong. With this add-on, the "correct" answers are rearranged
before showing the difference, and so only this would be shown:

This is particularly useful for language learning, since often there will be
multiple words matching a definition or multiple definitions for the same word.
Lenient Validation
This add-on also makes it possible to mark certain words in an answer as
optional by putting them in parentheses or square brackets, or to accept any
one of a set of words within an answer by separating them with slashes.
See here for more details.
Improved Support for Indic Scripts
For some languages such as Tamil (தமிழ்), the script requires combining
characters to represent vowels. Here is an example of the diff that Anki gives
by default when typing "திரமபு" (tiramabu) instead of "திரும்பு" (tirumbu):

Separating the combining marks from the letters that they attach to make it
difficult to see what is actually wrong, so this add-on groups combining marks
before showing the difference:

Syntax
If the "correct" answer contains ;, then ; will separate the answer choices
for rearranging. Otherwise, , will be used. This means that this:
a, b, c; d, e, f
Will be parsed into a, b, c as one answer and d, e, f as another. If you
want to use different answer choice separators, you can configure them in the
Anki add-on config page.
Config
There are a few special features which can be enabled/disabled in the add-on
config in Anki:
Additionally, there is an "Equivalent Strings" config option to treat certain
words as equivalent when checking answers. For instance, you may want to treat
"I am" and "I'm" as being the same. To see all available options, open the
add-on config page in Anki.
Implementation Details
For Anki 25.03+, this add-on is implemented using the
reviewer_will_compare_answer and reviewer_will_render_compared_answer hooks.
In older versions of Anki, it is implemented using monkey patching instead since
these hooks were not implemented yet.
The diffs between "given" and "correct" answer choices are rendered using a
modified version of the Longest Common Subsequence, with a preference for
grouping error regions together. It also has been modified to support "lenient
validation", where brackets, text separated by slashes, and certain other
characters are allowed to be missing from the given answer. Combining characters
are grouped before finding the difference to improve support for non-ASCII text.
The answer rearranging algorithm uses the diff between "given" and "correct"
answer choices to determine which correct answer is closest to which given
answer for rearranging. The closest pair is grouped together first, then the
next closest, and so on until there are no more pairs.
Changelog
2025-03-18:
- Use newly-created hooks to avoid monkey patching for Anki 25.03+. (@chel-ou)
2024-10-05:
- Fix add-on to work with latest beta version of Anki.
2024-04-28:
- Use diff algorithm while matching answer choices to ensure best diff.
2024-03-18:
- Added config option to change answer choice separators.
- Improved handling of missing answer choice separators.
2024-03-17:
- Added numeric comparison config option.
2024-02-20:
- Use Unicode case folding for case-insensitive matching.
- Fixed Unicode normalization in config options.
2024-02-08:
- Added config option to treat certain strings as the same when comparing answers.
2024-01-21:
- Rewrote diff algorithm to handle lenient validation consistently.
- Added config option to ignore case when comparing answers.
2024-01-14:
- Fixed issue with finding differences for certain alternatives.
2024-01-08:
- Use new implementation for alternatives to fix issue.
2023-12-27:
- Fixed bug with alternatives in brackets next to other words.
- Allow whitespace in alternatives when inside of brackets.
2023-12-11:
- Added config option to ignore answer separators in brackets and parentheses.
2023-12-10:
- Changed choice-matching heuristic to maximize correct letters instead of minimizing wrong letters.
2023-11-29:
- Fixed issue with mixing alternatives with other lenient validation options.
2023-11-26:
- Added configuration options in Anki add-on config page.
- Comments are now disabled by default, but can be enabled in config.
- Lenient validation can now be disabled in config.
- Missing periods are now ignored by default, but this can be changed in config.
2023-11-15:
- Added support for optional text in brackets.
- Comments now must have a space immediately before them.
2023-07-13:
- Added support for alternatives separated by slashes.
2023-06-15:
- Fixed handling of HTML tags in expected answer.
Bugs
If you find a bug, please open an issue in this repository describing the issue.