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

Incorrect handling of {\L} #78

Closed
blegat opened this issue Nov 14, 2024 · 5 comments · Fixed by #82
Closed

Incorrect handling of {\L} #78

blegat opened this issue Nov 14, 2024 · 5 comments · Fixed by #82

Comments

@blegat
Copy link
Contributor

blegat commented Nov 14, 2024

Create bug.bib:

@inproceedings{vaswani2017Attention,
  title = {Attention Is {{All}} You {{Need}}},
  author = {Kaiser, {\L}ukasz},
}

and run

using DocumenterCitations
bib = CitationBibliography("bug.bib")
key = "vaswani2017Attention"
DocumenterCitations.format_bibliography_reference(bib.style, bib.entries[key])

The error is:

ERROR: ArgumentError: Premature end of tex string: BoundsError("{. Kaiser", 11)
Stacktrace:
 [1] tex_to_markdown(tex_str::String; transform_case::Function, debug::Base.CoreLogging.LogLevel)
   @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/tex_to_markdown.jl:135
 [2] tex_to_markdown
   @ ~/.julia/dev/DocumenterCitations/src/tex_to_markdown.jl:125 [inlined]
 [3] 
   @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/formatting.jl:178
 [4] format_names (repeats 2 times)
   @ ~/.julia/dev/DocumenterCitations/src/formatting.jl:93 [inlined]
 [5] format_labeled_bibliography_reference(style::Val{…}, entry::BibInternal.Entry; namesfmt::Symbol, urldate_accessed_on::String, urldate_fmt::Dates.DateFormat{…}, title_transform_case::Function, article_link_doi_in_title::Bool)
   @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/labeled_styles_utils.jl:253
 [6] format_labeled_bibliography_reference(style::Val{:numeric}, entry::BibInternal.Entry)
   @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/labeled_styles_utils.jl:244
 [7] format_bibliography_reference
   @ ~/.julia/dev/DocumenterCitations/src/styles/numeric.jl:22 [inlined]
 [8] format_bibliography_reference(style::Symbol, entry::BibInternal.Entry)
   @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/expand_bibliography.jl:107
 [9] top-level scope
   @ ~/.julia/dev/DocumenterCitations/test.jl:7

caused by: BoundsError: attempt to access 10-codeunit String at index [11]
Stacktrace:
  [1] checkbounds
    @ ./strings/basic.jl:216 [inlined]
  [2] codeunit
    @ ./strings/string.jl:138 [inlined]
  [3] getindex
    @ ./strings/string.jl:461 [inlined]
  [4] _collect_group(tex_str::String, i::Int64)
    @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/tex_to_markdown.jl:407
  [5] _process_tex(tex_str::String; transform_case::DocumenterCitations.var"#73#75", debug::Base.CoreLogging.LogLevel)
    @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/tex_to_markdown.jl:196
  [6] tex_to_markdown(tex_str::String; transform_case::Function, debug::Base.CoreLogging.LogLevel)
    @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/tex_to_markdown.jl:131
  [7] tex_to_markdown
    @ ~/.julia/dev/DocumenterCitations/src/tex_to_markdown.jl:125 [inlined]
  [8] 
    @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/formatting.jl:178
  [9] format_names (repeats 2 times)
    @ ~/.julia/dev/DocumenterCitations/src/formatting.jl:93 [inlined]
 [10] format_labeled_bibliography_reference(style::Val{…}, entry::BibInternal.Entry; namesfmt::Symbol, urldate_accessed_on::String, urldate_fmt::Dates.DateFormat{…}, title_transform_case::Function, article_link_doi_in_title::Bool)
    @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/labeled_styles_utils.jl:253
 [11] format_labeled_bibliography_reference(style::Val{:numeric}, entry::BibInternal.Entry)
    @ DocumenterCitations ~/.julia/dev/DocumenterCitations/src/labeled_styles_utils.jl:244
@goerz
Copy link
Member

goerz commented Nov 14, 2024

I'll have a look, but TeX escape codes are only partially supported. The recommended approach is to use unicode, as in

@inproceedings{vaswani2017Attention,
  title = {Attention Is All You Need},
  author = {Kaiser, Łukasz},
}

You should avoid those extra TeX groups inside the title as well. See the Syntax for the .bib file

@blegat
Copy link
Contributor Author

blegat commented Nov 14, 2024

I don't generate this manually, this is the output of Zotero's Better BibTeX extension. It's encoded with unicode in Zotero but the exporter turn them into LaTeX friendly escaped symbols.

@goerz
Copy link
Member

goerz commented Nov 14, 2024

Zotero produces broken .bib files and is absolutely not supported as a source for DocumenterCitations. As a full entry,

@inproceedings{vaswani2017Attention,
  title = {Attention Is {{All}} You {{Need}}},
  author = {Kaiser, {\L}ukasz},
}

is not valid, since it's missing the mandatory year and booktitle fields.

See also #76.

However, the handling of the Ł in this particular case is a bug in DocumenterCitations, and I'll work on a fix for that.

@blegat
Copy link
Contributor Author

blegat commented Nov 14, 2024

I actually removed fields from the output of Zotero to reduce the MWE

@goerz
Copy link
Member

goerz commented Nov 14, 2024

Sure! That's fine!

I just wanted to stress the point that DocumenterCitations is intended to be used with "hand-written" .bib files that use unicode. They should avoid TeX commands, since the strings are not actually processed by TeX.

Of course, I encourage having automatic tooling for generating suitable .bib files, but many export tools from Bibliography managers do not generate suitable output. Based on #76, Zotero seems to be particularly bad and produces files that aren't even valid in a LaTeX context. Downloaded .bib files from publisher websites are even worse (which is why I wrote myself a getbibtex script).

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 a pull request may close this issue.

2 participants