plk / biblatex

biblatex is a sophisticated bibliography system for LaTeX users. It has considerably more features than traditional bibtex and supports UTF-8
508 stars 117 forks source link

Strange sorting #599

Closed simifilm closed 7 years ago

simifilm commented 7 years ago

I am currently extending my biblatex-fiwi style for archival sources. This is in the early stages yet, so don't pay too much attention to the new document type and fields. My problem is with sorting. I want to entries to sort by archive/library and the respective archive number of the document in question since archival documents can have neither author nor title nor even a publication date. For this, I created the following sorting scheme:

\DeclareSortingScheme{archiv}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{library}
  }
  \sort{
    \field{librarylocation}
    }
        \sort{
    \field{sortyear}
    \field{year}
  }

Now look at the following three entries:


@archival{Wedegartner.T:1976a,
    Author = {Wedegärtner, Thomas},
    Date = {1976-07-19},
    Library = {BArch},
    Librarylocation = {DR 1/25990},
    Title = {Charakteristik des Regisseurs Dr. Joachim Hellwig (futurum)},
    Year = {1976}}

@archival{Hellwig.J:1979a,
    Author = {Hellwig, Joachim and Wedegärtner, Thomas and Raue, Dieter and Brückner, Thekla and Steinheisser, Jürgen and Giesen, Frank},
    Library = {BArch},
    Librarylocation = {DR 117/17769},
    Title = {Untersuchung der Konzeption, Ergebnisse sowie der Wirksamkeit der Discofilme und des Internationalen Jugendmagazins \film{IN}},
    Year = {1979}}

@archival{unbekannt:2017a,
    Library = {BArch},
    Librarylocation = {DR 118/3555},
    Standort = {PDF},
    Title = {Auszug aus dem \enquote{Kulturmagazin} vom 10.12.77}}

What I want is the following sort order: Wedegartner.T:1976a – Hellwig.J:1979a – unbekannt:2017a. So "DR 1/25990" should be before "DR 117/17769". But no matter what I try, Wedegartner.T:1976a always ends up as the last entry. Somehow the slash seems to mess the sorting and "DR 1/" is sorted last, but I don't really understand the logic behind this.

plk commented 7 years ago

Hmm, can you run biber with --trace which will give the sorting objects.

simifilm commented 7 years ago

Something more fundamental seems to be broken. When I run it with --trace, I get a lot of

Use of uninitialized value in substitution iterator at /opt/local/lib/perl5/site_perl/5.26/Biber/LaTeX/Recode.pm line 307.

This is with the latest build on Perl5.26. Not sure whether biber or Perl is the problem here.

plk commented 7 years ago

Hmm, I don't see that problem but I don't think that it is relevant anyway. Perhaps you can package up a minimal broken example and I can try it?

moewew commented 7 years ago

Can you please show us a full minimal example. I just tried to reproduce your issue, but because I don't have your datamodel, things obviously didn't work out.

Only if we know that we run the exact same code can we start debugging this.

moewew commented 7 years ago

@PLK Now this is curious. With the following MWE I get

[221] Internals.pm:1071> DEBUG - Sorting object for key 'unbekannt:2017a' -> ["mm", "", "BArch", "DR 1183555", ""]
[221] Internals.pm:1071> DEBUG - Sorting object for key 'Wedegartner.T:1976a' -> ["mm", "", "BArch", "DR 125990", 1976]
[222] Internals.pm:1071> DEBUG - Sorting object for key 'Hellwig.J:1979a' -> ["mm", "", "BArch", "DR 11717769", 1979]

in the --debug output, so the slash is missing from the field.

\documentclass{article} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage{filecontents}

\begin{filecontents*}{\jobname-archival.dbx}
\DeclareDatamodelEntrytypes{archival}
\DeclareDatamodelFields[type=field,datatype=literal]{
  librarylocation,
}
\DeclareDatamodelEntryfields[archival]{
  library,
  librarylocation,
  title,
  author}
\end{filecontents*}

\usepackage[style=authoryear-icomp,datamodel=\jobname-archival]{biblatex}

\begin{filecontents*}{\jobname.bib}
@archival{unbekannt:2017a,
    Library = {BArch},
    librarylocation = {DR 118/3555},
    Standort = {PDF},
    Title = {Auszug aus dem \enquote{Kulturmagazin} vom 10.12.77}}
@archival{Wedegartner.T:1976a,
    Author = {Wedegärtner, Thomas},
    Date = {1976-07-19},
    Library = {BArch},
    librarylocation = {DR 1/25990},
    Title = {Charakteristik des Regisseurs Dr. Joachim Hellwig (futurum)},
    Year = {1976}}

@archival{Hellwig.J:1979a,
    Author = {Hellwig, Joachim and Wedegärtner, Thomas and Raue, Dieter and Brückner, Thekla and Steinheisser, Jürgen and Giesen, Frank},
    Library = {BArch},
    librarylocation = {DR 117/17769},
    Title = {Untersuchung der Konzeption, Ergebnisse sowie der Wirksamkeit der Discofilme und des Internationalen Jugendmagazins},
    Year = {1979}}
\end{filecontents*}

\addbibresource{\jobname.bib}

\DeclareSortingScheme{archiv}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{library}
  }
  \sort{
    \field{librarylocation}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
}

\ExecuteBibliographyOptions{sorting=archiv}

\begin{document}
\nocite{*}
\printbibliography
\end{document}
simifilm commented 7 years ago

I attached a folder with all relevent files, but I think @moewew is already up to something.

fiwi.zip

moewew commented 7 years ago

Consider the following MWE

\documentclass{article}
\usepackage[style=authortitle]{biblatex}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@online{elk,
  author   = {Anne Elk},
  title    = {Towards a Unified Theory on /B/r/o/n/t/o/sauruses},
  url      = {http://www.example.edu/~elk/bronto.pdf},
}
\end{filecontents*}

\addbibresource{\jobname.bib}
\begin{document}
\nocite{elk}
\printbibliography
\end{document}

Which yields https://gist.github.com/moewew/93a7fc607a589f9cbef6a459aa2534d3 in particular

[332] bibtex.pm:1436> TRACE - Buffer before decoding -> '@online{elk,
  author   = {Anne Elk},
  title    = {Towards a Unified Theory on /B/r/o/n/t/o/sauruses},
  url      = {http://www.example.edu/~elk/bronto.pdf},
}
'
[335] Recode.pm:228> TRACE - String before latex_decode() -> '@online{elk,
  author   = {Anne Elk},
  title    = {Towards a Unified Theory on /B/r/o/n/t/o/sauruses},
  url      = {4a747dc9b7c730285018df89b5f4bc65},
}
'
[336] Recode.pm:322> TRACE - String in latex_decode() now -> '@online{elk,
  author   = {Anne Elk},
  title    = {Towards a Unified Theory on /B/r/o/n/t/o/sauruses},
  url      = {http://www.example.edu/~elk/bronto.pdf},
}
'
[336] bibtex.pm:1442> TRACE - Buffer after decoding -> '@online{elk,
  author   = {Anne Elk},
  title    = {Towards a Unified Theory on /B/r/o/n/t/o/sauruses},
  url      = {http://www.example.edu/~elk/bronto.pdf},
}
'

But then

[355] Internals.pm:1071> DEBUG - Sorting object for key 'elk' -> [
  "mm",
  "",
  "Elk!Anne",
  "Towards a Unified Theory on Brontosauruses",
  "",
  0,
]
[356] Biber.pm:3454> DEBUG - Sorting is by default case-SENSITIVE
[356] Biber.pm:3460> DEBUG - Keys before sort:
[356] Biber.pm:3462> DEBUG - elk => mm,,Elk!Anne,Towards a Unified Theory on Brontosauruses,,0
                             sortdata => {
                               elk => [
                                        "mm,,Elk!Anne,Towards a Unified Theory on Brontosauruses,,0",
                                        [
                                          "mm",
                                          "",
                                          "Elk!Anne",
                                          "Towards a Unified Theory on Brontosauruses",
                                          "",
                                          0,
                                        ],
                                      ],
                             },
plk commented 7 years ago

Can you try the dev branch now? There was a subtle bug causing interesting edge-case problems.

simifilm commented 7 years ago

This seems to have fixed it. Thanks a lot.