Added `extra_paths` document option
This commit is contained in:
parent
82484dbbfd
commit
1bce332572
|
@ -53,6 +53,10 @@ pub struct Document {
|
|||
/// Either a URL or a local path.
|
||||
pub bundle_loc: String,
|
||||
|
||||
/// Extra local search paths for this document.
|
||||
/// May be absolute or relative to src_dir.
|
||||
pub extra_paths: Vec<PathBuf>,
|
||||
|
||||
/// The different outputs that are created from the document source. These
|
||||
/// may have different formats (e.g., PDF and HTML) or the same format but
|
||||
/// different settings (e.g., PDF with A4 paper and PDF with US Letter
|
||||
|
@ -98,6 +102,7 @@ impl Document {
|
|||
build_dir: build_dir.into(),
|
||||
name: doc.doc.name,
|
||||
bundle_loc: doc.doc.bundle,
|
||||
extra_paths: doc.doc.extra_paths.unwrap_or_default(),
|
||||
metadata: doc.doc.metadata,
|
||||
outputs,
|
||||
})
|
||||
|
@ -116,10 +121,17 @@ impl Document {
|
|||
.map(syntax::TomlOutputProfile::from)
|
||||
.collect();
|
||||
|
||||
let extra_paths = if self.extra_paths.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(self.extra_paths.clone())
|
||||
};
|
||||
|
||||
let doc = syntax::TomlDocument {
|
||||
doc: syntax::TomlDocSection {
|
||||
name: self.name.clone(),
|
||||
bundle: self.bundle_loc.clone(),
|
||||
extra_paths,
|
||||
metadata: None,
|
||||
},
|
||||
outputs,
|
||||
|
@ -246,7 +258,11 @@ pub enum InputFile {
|
|||
impl Document {
|
||||
/// Create a new in-memory Document, based on the settings of a
|
||||
/// WorkspaceCreator object.
|
||||
pub(crate) fn create_for(wc: &WorkspaceCreator, bundle_loc: String) -> Result<Self> {
|
||||
pub(crate) fn create_for(
|
||||
wc: &WorkspaceCreator,
|
||||
bundle_loc: String,
|
||||
extra_paths: Vec<PathBuf>,
|
||||
) -> Result<Self> {
|
||||
let src_dir = wc.root_dir.clone();
|
||||
|
||||
let mut build_dir = src_dir.clone();
|
||||
|
@ -288,6 +304,7 @@ impl Document {
|
|||
build_dir,
|
||||
name,
|
||||
bundle_loc,
|
||||
extra_paths,
|
||||
outputs: crate::document::default_outputs(),
|
||||
metadata: None,
|
||||
})
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
//!
|
||||
//! This module is only used by [`crate::document::Document`]
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::document::{BuildTargetType, InputFile, OutputProfile};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
|
||||
|
@ -30,6 +32,7 @@ pub struct TomlDocSection {
|
|||
pub name: String,
|
||||
pub bundle: String,
|
||||
pub metadata: Option<toml::Value>,
|
||||
pub extra_paths: Option<Vec<PathBuf>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
|
@ -125,8 +125,8 @@ impl WorkspaceCreator {
|
|||
}
|
||||
|
||||
/// Consume this object and attempt to create the new workspace.
|
||||
pub fn create(self, bundle_loc: String) -> Result<Workspace> {
|
||||
let doc = Document::create_for(&self, bundle_loc)?;
|
||||
pub fn create(self, bundle_loc: String, extra_paths: Vec<PathBuf>) -> Result<Workspace> {
|
||||
let doc = Document::create_for(&self, bundle_loc, extra_paths)?;
|
||||
|
||||
let mut tex_dir = self.root_dir.clone();
|
||||
tex_dir.push("src");
|
||||
|
|
|
@ -17,6 +17,24 @@ the file are detailed below.
|
|||
name = <string> # the document name
|
||||
bundle = <url or filesystem path> # the source of the TeX bundle
|
||||
|
||||
# Extra search paths for TeX sources, images, etc.
|
||||
#
|
||||
# This is particularly useful if you have files used
|
||||
# by multiple Tectonic documents. For example:
|
||||
#
|
||||
# repo-root/
|
||||
# ├── resources/
|
||||
# │ └── classes, images, other shared resources
|
||||
# ├── doc1/
|
||||
# │ ├── src/
|
||||
# │ └── Tectonic.toml <-- Contains `extra_paths = ["../resources"]`
|
||||
# └── doc2/
|
||||
# ├── src/
|
||||
# └── Tectonic.toml <-- Contains `extra_paths = ["../resources"]`
|
||||
extra_paths = ["", ""]
|
||||
|
||||
|
||||
|
||||
# The doc.metadata table may contain arbitrary data.
|
||||
# It does not affect Tectonic in any way.
|
||||
[doc.metadata]
|
||||
|
@ -24,6 +42,7 @@ pubish = false
|
|||
arr = [1, 2, [6, 7]]
|
||||
|
||||
|
||||
|
||||
# One (of possibly many) output specifications.
|
||||
[[output]]
|
||||
|
||||
|
|
|
@ -166,12 +166,20 @@ impl DocumentExt for Document {
|
|||
let mut sess_builder =
|
||||
ProcessingSessionBuilder::new_with_security(setup_options.security.clone());
|
||||
|
||||
// Interpret all extra paths as relative to our working dir
|
||||
let extra_paths: Vec<PathBuf> = self
|
||||
.extra_paths
|
||||
.iter()
|
||||
.map(|x| self.src_dir().join(x))
|
||||
.collect();
|
||||
|
||||
sess_builder
|
||||
.output_format(output_format)
|
||||
.format_name(&profile.tex_format)
|
||||
.build_date_from_env(setup_options.deterministic_mode)
|
||||
.unstables(UnstableOptions {
|
||||
deterministic_mode: setup_options.deterministic_mode,
|
||||
extra_search_paths: extra_paths,
|
||||
..Default::default()
|
||||
})
|
||||
.pass(PassSetting::Default)
|
||||
|
@ -238,6 +246,6 @@ impl WorkspaceCreatorExt for WorkspaceCreator {
|
|||
gub.resolve_url(&unresolved_loc, status)?
|
||||
};
|
||||
|
||||
Ok(self.create(bundle_loc)?)
|
||||
Ok(self.create(bundle_loc, Vec::new())?)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue