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

Smart Quotation Marks in Formattable Strings. #99

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Drodt
Copy link
Contributor

@Drodt Drodt commented Dec 5, 2023

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 new ChunkKind.
  • 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.

@reknih
Copy link
Member

reknih commented Dec 11, 2023

Should this also work for single quotes? The ChunkKind could track the "doubleness" with a boolean.

@DerDrodt
Copy link
Contributor

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.

  1. When rendering, hayagriva automatically checks whether it should use inner or outer quotation marks.
  2. 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.

@reknih
Copy link
Member

reknih commented Jan 8, 2024

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.

@Drodt
Copy link
Contributor Author

Drodt commented Jan 9, 2024

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?

@Drodt
Copy link
Contributor Author

Drodt commented Jan 9, 2024

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?

@reknih
Copy link
Member

reknih commented Jan 9, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Smart Quotation Marks in Title
3 participants