Add synctex option in Toml file (#1197)
Authored by: Stéphane Kastenbaum <stephane.kastenbaum@inria.fr>
This commit is contained in:
parent
51e179f742
commit
d1ee37974a
|
@ -233,6 +233,11 @@ pub struct OutputProfile {
|
|||
/// Directory is not managed and any files created in it will not be deleted.
|
||||
///
|
||||
pub shell_escape_cwd: Option<String>,
|
||||
|
||||
/// Whether synctex should be activated for this profile.
|
||||
///
|
||||
/// Default is false.
|
||||
pub synctex: bool,
|
||||
}
|
||||
|
||||
/// The output target type of a document build.
|
||||
|
@ -325,6 +330,7 @@ pub(crate) fn default_outputs() -> HashMap<String, OutputProfile> {
|
|||
.collect(),
|
||||
shell_escape: false,
|
||||
shell_escape_cwd: None,
|
||||
synctex: false,
|
||||
},
|
||||
);
|
||||
outputs
|
||||
|
@ -370,4 +376,37 @@ mod tests {
|
|||
let doc = Document::new_from_toml(".", ".", &mut c).unwrap();
|
||||
assert!(doc.outputs.get("o").unwrap().shell_escape);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn synctex_default_false() {
|
||||
const TOML: &str = r#"
|
||||
[doc]
|
||||
name = "test"
|
||||
bundle = "na"
|
||||
|
||||
[[output]]
|
||||
name = "o"
|
||||
type = "pdf"
|
||||
"#;
|
||||
let mut c = Cursor::new(TOML.as_bytes());
|
||||
let doc = Document::new_from_toml(".", ".", &mut c).unwrap();
|
||||
assert!(!doc.outputs.get("o").unwrap().synctex);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn synctex_set_true() {
|
||||
const TOML: &str = r#"
|
||||
[doc]
|
||||
name = "test"
|
||||
bundle = "na"
|
||||
|
||||
[[output]]
|
||||
name = "o"
|
||||
type = "pdf"
|
||||
synctex = true
|
||||
"#;
|
||||
let mut c = Cursor::new(TOML.as_bytes());
|
||||
let doc = Document::new_from_toml(".", ".", &mut c).unwrap();
|
||||
assert!(doc.outputs.get("o").unwrap().synctex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ pub struct TomlOutputProfile {
|
|||
pub tex_format: Option<String>,
|
||||
pub shell_escape: Option<bool>,
|
||||
pub shell_escape_cwd: Option<String>,
|
||||
pub synctex: Option<bool>,
|
||||
|
||||
// We cannot handle these two input variants with an enum.
|
||||
// The ideal solution requires #[serde(flatten)],
|
||||
|
@ -118,6 +119,7 @@ pub struct TomlOutputProfile {
|
|||
impl From<&TomlOutputProfile> for OutputProfile {
|
||||
fn from(val: &TomlOutputProfile) -> OutputProfile {
|
||||
let shell_escape_default = val.shell_escape_cwd.is_some();
|
||||
let synctex_default = false;
|
||||
|
||||
let inputs = {
|
||||
if let Some(inputs) = &val.inputs {
|
||||
|
@ -152,6 +154,7 @@ impl From<&TomlOutputProfile> for OutputProfile {
|
|||
inputs,
|
||||
shell_escape: val.shell_escape.unwrap_or(shell_escape_default),
|
||||
shell_escape_cwd: val.shell_escape_cwd.clone(),
|
||||
synctex: val.synctex.unwrap_or(synctex_default),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +172,7 @@ impl From<&OutputProfile> for TomlOutputProfile {
|
|||
|
||||
let shell_escape = if !rt.shell_escape { None } else { Some(true) };
|
||||
let shell_escape_cwd = rt.shell_escape_cwd.clone();
|
||||
let synctex = if !rt.synctex { None } else {Some(true)};
|
||||
|
||||
TomlOutputProfile {
|
||||
name: rt.name.clone(),
|
||||
|
@ -177,6 +181,7 @@ impl From<&OutputProfile> for TomlOutputProfile {
|
|||
inputs: Some(inputs),
|
||||
shell_escape,
|
||||
shell_escape_cwd,
|
||||
synctex,
|
||||
preamble_file: None,
|
||||
index_file: None,
|
||||
postamble_file: None,
|
||||
|
|
|
@ -83,6 +83,9 @@ shell_escape = false
|
|||
# This is optional, and defaults to a temporary directory.
|
||||
shell_escape_cwd = "string"
|
||||
|
||||
# Whether the synctex files will be created. This is optional and defaults to false.
|
||||
synctex = false
|
||||
|
||||
# The input file we'll use to build this document,
|
||||
# Given as a path relative to the `./src` directory.
|
||||
#
|
||||
|
|
|
@ -153,7 +153,8 @@ impl DocumentExt for Document {
|
|||
})
|
||||
.pass(PassSetting::Default)
|
||||
.primary_input_buffer(input_buffer.as_bytes())
|
||||
.tex_input_name(output_profile);
|
||||
.tex_input_name(output_profile)
|
||||
.synctex(profile.synctex);
|
||||
|
||||
if profile.shell_escape {
|
||||
// For now, this is the only option we allow.
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
[doc]
|
||||
name = "synctex"
|
||||
bundle = "https://data1.fullyjustified.net/tlextras-2022.0r0.tar"
|
||||
|
||||
[[output]]
|
||||
name = "default"
|
||||
type = "pdf"
|
||||
synctex = true
|
||||
inputs = [
|
||||
"_preamble.tex",
|
||||
"index.tex",
|
||||
"_postamble.tex",
|
||||
]
|
|
@ -0,0 +1 @@
|
|||
\end{document}
|
|
@ -0,0 +1,3 @@
|
|||
\documentclass{article}
|
||||
\title{My Title}
|
||||
\begin{document}
|
|
@ -0,0 +1 @@
|
|||
Hello, world.
|
Loading…
Reference in New Issue