retorquere / zotero-better-bibtex

Make Zotero effective for us LaTeX holdouts
https://retorque.re/zotero-better-bibtex/
MIT License
5.31k stars 285 forks source link

\DeclarePrefChars not supported in biber 1.9 #599

Closed martinpub closed 7 years ago

martinpub commented 7 years ago

Hi,

Since a while ago, I'm having problems with a LaTeX error:

! Undefined control sequence. \abx@preamble ->\DeclarePrefChars {-} l.35 \begin{document}

I managed to narrow it down to the line

'@preamble{ "\DeclarePrefChars{-} " }'

added by zotero-better-bibtex to the bib file upon automatic Zotero biblatex export. This causes an undesired leading page with a "-" in the resulting pdf.

When I delete that line manually from the bib file, the error message goes away. And when I manually export a test subcollection from Zotero, the line is not added, so I suspect it has something to do with the references in the automatic export. I saw this was recently added to zotero-better-bibtex, and I think my problem might be related.

Do you have any ideas about this, if it is a bug, or how I can troubleshoot to narrow it down even more?

I will be happy to provide more details if needed.

Best, Martin Persson

retorquere commented 7 years ago

@nickbart1980 ?

retorquere commented 7 years ago

What biblatex processor do you use, and which version of it?

martinpub commented 7 years ago

biber version: 1.9

retorquere commented 7 years ago

(fingers crossed DeclarePrefChars is not processor-dependent) @nickbart1980 will know what to do. I'm out of my depth on this issue.

martinpub commented 7 years ago

Thanks for investigating @retorquere!

retorquere commented 7 years ago

Oh and it's for sure related to the references you have -- declareprefchars is populated depending on whether a certain kind of name-particle is found, so you have that right. The question is not so much on why it happens, but what can be best done about it.

edit: and you did indeed identify the right issue where the functionality was added.

martinpub commented 7 years ago

I see. I'm looking forward to a solution. And not all references in my library are 100% accurate when it comes to details, so if I know what to look for I might be able to solve it with a bit of clean-up.

retorquere commented 7 years ago

This one is squarely on BBT. Plus they'll be hard to spot for you -- in your case it will be a reference with a last name like ['s-Gravesande][Goverdus], [Sadat][Anwar el-] or [al-Hakim][Tawfiq] -- in the corresponding BibLaTeX you can probably find them faster by searching for - (dash-space). But this is not something you should have to fix.

njbart commented 7 years ago

@martinpub: Could you provide an MWE? In particular, which biblatex style are you using? (I'm not seeing this with either vanilla biblatex or biblatex-chicago).

@retorquere: With the BBT "Use biblatex extended name format" option checked, the @preamble{ "\DeclarePrefChars{-} " } string is NOT exported to a .bib file – but it is actually required for either of the two name formats.

njbart commented 7 years ago

@martinpub: Ah, you said biber 1.9 – that's a long-outdated biber version, and probably an equally outdated biblatex (current production versions are biber 2.6 and biblatex 3.5). \DeclarePrefChars was introduced in biblatex 3.2.

You should update your TeX installation.

njbart commented 7 years ago

@retorquere: When I think about it, I'm beginning to suspect that feeding only those characters to the \DeclarePrefChars command that have actually been found in a collection might lead to unexpected results:

Imagine two collections exported to two different bib files. The first contains “d’Alembert”, and the second “al-Hakim”. The bib files will contain \DeclarePrefChars{’} and \DeclarePrefChars{-}, respectively – but the second command will override the first, and “d’Alembert” will be incorrectly formatted as “d’ Alembert”.

I guess all biblatex files exported by BBT should contain what I feel is the only sensible default, i.e., \DeclarePrefChars{'’-}.

retorquere commented 7 years ago

That's what happens now. BBT collects them and only outputs a single \DeclarePrefChars with them if it finds any.

retorquere commented 7 years ago

See e.g. the test file for this.

retorquere commented 7 years ago

@martinpub is it possible for you to upgrade?

retorquere commented 7 years ago

@nickbart1980 or do you mean if you have an article using multiple bib files? I don't see how I could make that work, short of getting support in biblatex for something like \AddToDeclaredPrefCharsor somesuch (which I wouldn't half mind).

njbart commented 7 years ago

… or do you mean if you have an article using multiple bib files?

Yes. And that's why I'd say including @preamble{ "\DeclarePrefChars{'’-} " } in all biblatex files is a better solution.

After all, this is just redefining the biblatex default of \DeclarePrefChars{'} to something more sensible.

retorquere commented 7 years ago

You mean just a fixed \DeclarePrefChars, regardless of what was found? Is there no risk of ill side effects? (and if not, why doesn't BibLaTeX do this by default?)

njbart commented 7 years ago

why doesn't BibLaTeX do this by default?

Not sure. I was about to suggest this for biblatex but thought, why bother if BBT can do it.

retorquere commented 7 years ago

Well, if there's no ill side effects... but I'd prefer to see this added to BibLaTeX. They'd be better equipped to deal with any side effects.

njbart commented 7 years ago

Is there no risk of ill side effects?

I can't think of any. The dumb apostrophe is the default anyway, this just adds the smart version and the hyphen. I'm not aware of any name at all that would have to be formatted with a “hyphen-space” between prefix and family name.

retorquere commented 7 years ago

And the chances of the default being expanded in biblatex?

njbart commented 7 years ago

Let's see: https://github.com/plk/biblatex/issues/506

martinpub commented 7 years ago

@retorquere Thanks for pointing me in the right direction, I will check my references.

@nickbart1980: Well, I'm using the version that's in Debian stable ... Their release cycle is quite long, but perhaps I should consider apt pinning on the TeX stuff.

As for a MWE, I composed this bib file from Zotero export:

@book{foo_test_2016,
  title = {Test Book},
  timestamp = {2016-11-02T12:04:08Z},
  author = {Foo, Bar and el- Sadat, Anwar},
  date = {2016}
}
@preamble{ "\DeclarePrefChars{-} " }

I used the following LaTeX MWE to replicate the error:


\documentclass[a4paper,11pt]{article}
\usepackage[english, american]{babel}
\usepackage[style=authoryear,backend=biber,isbn=false]{biblatex}
\bibliography{bibliography/test}
\begin{document}

According to \autocite{foo_test_2016}, bla bla bla

\printbibliography
\end{document}

Unfortunately, now biber segfaults on this when I keep "el- Sadat":

FATAL - Caught signal: SEGV Likely your .bib has a very bad entry which causes libbtparse to crash: Inappropriate ioctl for device Segmentation fault

However, if I remove the space I get the same error as I have reported here (no errors in biber run, but when i run pdflatex).

I hope this clarifies the issue.

njbart commented 7 years ago

I can’t reproduce this with biber 2.6 and biblatex 3.5 (obtained via a regularly updated TeX Live installation on a Mac).

I don’t have a clue about Debian, but if installing TeX Live is an option for you at all, maybe https://www.tug.org/texlive/debian.html is helpful.

FWIW, the error you are describing has been discussed on https://github.com/plk/biber/issues/19 and https://github.com/plk/biber/issues/52, without any clear solutions though, except for checking for malformed entries (which yours isn't), and upgrading biber.

retorquere commented 7 years ago

Debian is notoriously conservative when it comes to updating versions (some might say it seems to take pride in being a few years behind the curve). I understand @martinpub wanting to stay with the packaged version... and biber 1.9 is the current version in stable Debian.

This puts me in sort of a bind. I don't necessarily only target hot-of-the-press bib(la)tex versions, mainly those versions that are in wide circulation. On the one hand, Debian Jessie could qualify as widely circulated. On the other hand, biber 1.9 is over two years old.

njbart commented 7 years ago

BBT could use @preamble{ "\ifdefined\DeclarePrefChars\DeclarePrefChars{'’-}\else\fi" } instead – checking whether the \DeclarePrefChars command exists before actually using it. This would prevent the originally reported ! Undefined control sequence. error with obsolete biblatex versions, but spaces between d’ or al- and Last would of course not be removed either. I’m afraid there’s not much more BBT can do here.

retorquere commented 7 years ago

That would take care of the error, but how would the references look?

Frickin' Debian though... two-year periods between stable releases, and apparently no bugfix backports, or their biber 1.9 wouldn't exhibit this issue.

retorquere commented 7 years ago

@martinpub can you try https://github.com/retorquere/zotero-better-bibtex/releases/download/builds/zotero-better-bibtex-1.6.81-circle-3272.xpi in combination with this postscript:

if (Translator.BetterBibLaTeX) {
  if (this.has.author) {
    this.has.author.bibtex = this.has.author.bibtex.replace(/(['’-]) /g, function(str, chr) {
      return chr;
    });
  }
  if (this.has.editor) {
    this.has.editor.bibtex = this.has.editor.bibtex.replace(/(['’-]) /g, function(str, chr) {
      return chr;
    });
  }
}

The postscript ought to remove the extra space after the punctuation where \DeclarePrefChar otherwise would.

retorquere commented 7 years ago

@martinpub I really need to know whether this solves your problem. I don't want to add code that solves no problem.

martinpub commented 7 years ago

Sure, I will try it in a few days, have been busy. Thanks for helping out!

On November 5, 2016 8:18:27 PM GMT+01:00, retorquere notifications@github.com wrote:

@martinpub I really need to know whether this solves your problem. I don't want to add code that solves no problem.

You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/retorquere/zotero-better-bibtex/issues/599#issuecomment-258634581

martinpub commented 7 years ago

@retorquere I can now confirm that this solves my problem. The LaTeX preamble string in the bib file is not messing up upon running pdflatex/biber. Thanks!

retorquere commented 7 years ago

Thanks for the confirmation, I'll close the issue when the test run goes green.

retorquere commented 7 years ago

New release is out.

retorquere commented 7 years ago

You may still need the postscript to remove the space though.

martinpub commented 7 years ago

Thanks!

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.