racket / scribble

Other
201 stars 92 forks source link

autobib citation breaks separate compilation of sections #262

Closed wilbowma closed 4 years ago

wilbowma commented 4 years ago

Normally when writing in Scribble, I have each section in a separate file, included into the main paper with @include-section. This is handy for organization and allows me to separately build just the section I'm working on.

However, this doesn't work if the section uses autobib, because the autobib style files are included only when generate-bibliography is called, and without those style files, Autobibref etc are undefined. This can't really be called in every section.

Consider the 3-file example below. When scribble --pdf paper.scrbl is built, everything is fine, but scribble --pdf section.srcbl fails. If the citation is removed, scribble --pdf section.scrbl builds correctly.

There's a simple fix, but I'm not sure what the implications are. We simply change https://github.com/racket/scribble/blob/6a8986f7c0ba4e241a44fa71cdf453010b21400c/scribble-lib/scriblib/autobib.rkt#L145 to include autobib-style-extras in the style properties. I've done this locally, and separate compilation is restored. I'm happy to submit a patch if there are no side-effect that I'm missing.

(I'm wary because I've had trouble with using the same properties list in multiple places before, so there's some semantics I don't understand. It seems style files are loaded once per object identity. If so, as long as the same (point equality) style property is used multiple times, then the style file will not be loaded multiple times, but "the same" (structural equality) style property used multiple times will load the style file multiple times, causing issues.)

defs.rkt

#lang racket/base

(require
  scriblib/autobib)

(provide (all-defined-out))

(define-cite ~cite citet generate-bibliography)

(define plt-tr1
   (make-bib
    #:title    "Reference: Racket"
    #:author   (authors "Matthew Flatt" "PLT")
    #:date     "2010"
    #:location (techrpt-location #:institution "PLT Inc."
                                 #:number "PLT-TR-2010-1")
    #:url      "http://racket-lang.org/tr1/"))

paper.scrbl

#lang scribble/base

@(require "defs.rkt")

@include-section{section.scrbl}

@(generate-bibliography)

section.scrbl

#lang scribble/base

@(require "defs.rkt")
@title{Section}

@~cite[plt-tr1] is cool stuff.
mflatt commented 4 years ago

This sounds right to me.

I'm not sure myself how multiple additions are merged, but it looks like it's based on equal? for the path or bytes in an addition. I'll have to investigate more to document that properly, but it seems clear that autobib-style-extras is supposed to work any number of times (except zero, which is the problem here).

wilbowma commented 4 years ago

If it's supposed to be "equal?" on the path, then I might file a bug. I definitely managed to get the same CSS file show up multiple times in the output.