Skip to main content

tectonic/engines/
bibtex.rs

1// Copyright 2017-2021 the Tectonic Project
2// Licensed under the MIT License.
3
4//! Engine for invoking `bibtex`.
5
6use tectonic_bridge_core::CoreBridgeLauncher;
7use tectonic_engine_bibtex::{BibtexEngine as RealBibtexEngine, BibtexOutcome};
8
9use super::tex::TexOutcome;
10use crate::{errors::Result, unstable_opts::UnstableOptions};
11
12/// A struct for invoking the `bibtex` engine.
13///
14/// This struct has a fairly straightforward "builder" interface: you create it,
15/// apply any settings that you wish, and eventually run the
16/// [`process()`](Self::process) method.
17#[derive(Default)]
18pub struct BibtexEngine {}
19
20impl BibtexEngine {
21    /// Create a new, default engine for running `bibtex`.
22    pub fn new() -> BibtexEngine {
23        Default::default()
24    }
25
26    /// Process a document using the current engine configuration.
27    ///
28    /// The *launcher* parameter gives overarching environmental context in
29    /// which the engine will be run.
30    ///
31    /// The *aux* parameter gives the name of the "aux" file, created by the TeX
32    /// engine, that BibTeX will process.
33    ///
34    /// The *unstables* parameter controls unstable options that may change the behavior of
35    /// `bibtex`.
36    pub fn process(
37        &mut self,
38        launcher: &mut CoreBridgeLauncher,
39        aux: &str,
40        unstables: &UnstableOptions,
41    ) -> Result<TexOutcome> {
42        let mut real_engine = RealBibtexEngine::default();
43
44        if let Some(x) = unstables.min_crossrefs {
45            real_engine.min_crossrefs(x);
46        }
47
48        let real_outcome = real_engine.process(launcher, aux)?;
49
50        match real_outcome {
51            BibtexOutcome::Spotless => Ok(TexOutcome::Spotless),
52            BibtexOutcome::Warnings => Ok(TexOutcome::Warnings),
53            BibtexOutcome::Errors => Ok(TexOutcome::Errors),
54        }
55    }
56}