hayagriva
hayagriva copied to clipboard
Smart Quotation Marks in Formattable Strings.
Close #70.
I implemented a couple of changes to enable hayagriva to better render quotation marks in titles or other formattable strings.
The changes are
- Adds a new
ChunkKind
for quotes. - Quotation marks, i.e.,
"
, are used as delimiters for this newChunkKind
. - Render these chunks with surrounding quotation marks.
~An alternative solution would be to allow some Typst functions in Hayagriva, e.g., quote
and smallcaps
.~
Todo:
- [ ] Better parsing of quotation marks (following typst's heuristics);
- [ ] Handling quotation commands (
\enquote
,\mkbibquote
) in from bib(la)tex.
Should this also work for single quotes? The ChunkKind
could track the "doubleness" with a boolean.
Should this also work for single quotes? The
ChunkKind
could track the "doubleness" with a boolean.
There is no need for that, and it might even produce problems.
- When rendering, hayagriva automatically checks whether it should use inner or outer quotation marks.
- Single quotes are more ambiguous in titles; think of
Dijkstra's algorithm
and the like.
So long as double quotes are part of the spec, I think it should be fine.
If I'm reading your code correctly, BibTeX' normal chunks will continue to yield regular quotes. I think that we should parse BibTeX normal chunks to also emit the quote chunk so that both formats behave more similarly.
If I'm reading your code correctly, BibTeX' normal chunks will continue to yield regular quotes. I think that we should parse BibTeX normal chunks to also emit the quote chunk so that both formats behave more similarly.
That would be good but how do we want this to work? In Bib(la)TeX, you don't use "
to make quotation marks but \enquote
. So we would need to handle this command in biblatex
. But there we cannot just add some unicode symbols like for other commands.
The best way I see to do this is to make another ChunkKind
in biblatex
that handles the quotation commands. Is that fine by you?
Another thing: I do think we will run into issues at some point by just parsing everything between "
as a quote. (At some point someone will open an issue about weird behavior because they have two measurements in inches in their title.)
I think we should add support for simple typst commands like quote
, smallcaps
, etc. Thoughts?
Ultimately, smart quotes are a heuristic. Typst implements it here: https://github.com/typst/typst/blob/c20b6ec6e157b753e90aa60ccd5b50f6f31cb7f6/crates/typst/src/text/smartquote.rs#L91. This handles something like quotes between numbers (e.g. for measurements in inches). It could be worthwhile to extract this into a crate and use the same code here and there. Additionally, I would propose to tokenize only the quote inside a chunk instead of the complete citation it wraps and approach this as purely string replacement instead of semantic.
Adding a non-standard chunk to biblatex
is not very appealing to me. Maybe the Normal chunks could have a method that parses the appropriate commands and returns a vector with an enum?