Skip to content

Commit

Permalink
Force IbidState:Different for prose citations (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGietl authored Jan 8, 2024
1 parent 6c2bc7c commit 5d39553
Showing 1 changed file with 44 additions and 27 deletions.
71 changes: 44 additions & 27 deletions src/csl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,35 +1197,52 @@ impl<'a> StyleContext<'a> {
ctx.set_special_form(Some(SpecialForm::VarOnly(author_var)));
do_regular(ctx);
} else {
// Render name from bibliography.
ctx.set_special_form(Some(SpecialForm::VarOnly(author_var)));
let needs_synthesis = if let Some(bibliography) = &self.csl.bibliography {
if bibliography.layout.will_render(ctx, author_var) {
ctx.writing.push_name_options(&bibliography.name_options);
bibliography.layout.render(ctx);
ctx.writing.pop_name_options();
false
} else {
true
let mut needs_bibliography = true;

// Render name from citation with ibid forced to Different.
if ctx.instance.cite_props.speculative.ibid != IbidState::Different {
let prev_ibid = ctx.instance.cite_props.speculative.ibid;
ctx.instance.cite_props.speculative.ibid = IbidState::Different;
if self.csl.citation.layout.will_render(ctx, author_var) {
ctx.set_special_form(Some(SpecialForm::VarOnly(author_var)));
do_regular(ctx);
needs_bibliography = false;
}
} else {
true
};
ctx.instance.cite_props.speculative.ibid = prev_ibid;
}

if needs_synthesis {
// We build our own name and render it with the citation's
// properties.
let layout = Layout::new(
vec![LayoutRenderingElement::Names(Names::with_variables(vec![
NameVariable::Author,
]))],
self.csl.citation.layout.to_formatting(),
None,
None,
);
ctx.writing.push_name_options(&self.csl.citation.name_options);
layout.render(ctx);
ctx.writing.pop_name_options();
if needs_bibliography {
// Render name from bibliography.
ctx.set_special_form(Some(SpecialForm::VarOnly(author_var)));
let needs_synthesis =
if let Some(bibliography) = &self.csl.bibliography {
if bibliography.layout.will_render(ctx, author_var) {
ctx.writing.push_name_options(&bibliography.name_options);
bibliography.layout.render(ctx);
ctx.writing.pop_name_options();
false
} else {
true
}
} else {
true
};

if needs_synthesis {
// We build our own name and render it with the citation's
// properties.
let layout = Layout::new(
vec![LayoutRenderingElement::Names(Names::with_variables(
vec![NameVariable::Author],
))],
self.csl.citation.layout.to_formatting(),
None,
None,
);
ctx.writing.push_name_options(&self.csl.citation.name_options);
layout.render(ctx);
ctx.writing.pop_name_options();
}
}
}
ctx.set_special_form(None);
Expand Down

0 comments on commit 5d39553

Please sign in to comment.