From d1ee37974a508c9fc093c408f109c85f9f287e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Kastenbaum?= Date: Tue, 15 Oct 2024 06:28:19 +0200 Subject: [PATCH] Add synctex option in Toml file (#1197) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored by: Stéphane Kastenbaum --- crates/docmodel/src/document.rs | 39 ++++++++++++++++++++++++++++++++ crates/docmodel/src/syntax.rs | 5 ++++ docs/src/ref/tectonic-toml.md | 5 +++- src/docmodel.rs | 3 ++- tests/synctex/Tectonic.toml | 13 +++++++++++ tests/synctex/src/_postamble.tex | 1 + tests/synctex/src/_preamble.tex | 3 +++ tests/synctex/src/index.tex | 1 + 8 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/synctex/Tectonic.toml create mode 100644 tests/synctex/src/_postamble.tex create mode 100644 tests/synctex/src/_preamble.tex create mode 100644 tests/synctex/src/index.tex diff --git a/crates/docmodel/src/document.rs b/crates/docmodel/src/document.rs index 6e3c3720..0bb8a81f 100644 --- a/crates/docmodel/src/document.rs +++ b/crates/docmodel/src/document.rs @@ -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, + + /// 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 { .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); + } } diff --git a/crates/docmodel/src/syntax.rs b/crates/docmodel/src/syntax.rs index e603375f..ff461641 100644 --- a/crates/docmodel/src/syntax.rs +++ b/crates/docmodel/src/syntax.rs @@ -98,6 +98,7 @@ pub struct TomlOutputProfile { pub tex_format: Option, pub shell_escape: Option, pub shell_escape_cwd: Option, + pub synctex: Option, // 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, diff --git a/docs/src/ref/tectonic-toml.md b/docs/src/ref/tectonic-toml.md index 266ce750..4828dbd2 100644 --- a/docs/src/ref/tectonic-toml.md +++ b/docs/src/ref/tectonic-toml.md @@ -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. # @@ -113,4 +116,4 @@ inputs = "main.tex" preamble = "_preamble.tex" # the preamble file to use (within `src`) index = "index.tex" # the index file to use (within `src`) postamble = "_postamble.tex" # the postamble file to use (within `src`) -``` \ No newline at end of file +``` diff --git a/src/docmodel.rs b/src/docmodel.rs index bbcd6ac1..d8c5dbc3 100644 --- a/src/docmodel.rs +++ b/src/docmodel.rs @@ -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. diff --git a/tests/synctex/Tectonic.toml b/tests/synctex/Tectonic.toml new file mode 100644 index 00000000..749afc85 --- /dev/null +++ b/tests/synctex/Tectonic.toml @@ -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", +] diff --git a/tests/synctex/src/_postamble.tex b/tests/synctex/src/_postamble.tex new file mode 100644 index 00000000..6b47932f --- /dev/null +++ b/tests/synctex/src/_postamble.tex @@ -0,0 +1 @@ +\end{document} diff --git a/tests/synctex/src/_preamble.tex b/tests/synctex/src/_preamble.tex new file mode 100644 index 00000000..43e9b9a0 --- /dev/null +++ b/tests/synctex/src/_preamble.tex @@ -0,0 +1,3 @@ +\documentclass{article} +\title{My Title} +\begin{document} diff --git a/tests/synctex/src/index.tex b/tests/synctex/src/index.tex new file mode 100644 index 00000000..f75ba05f --- /dev/null +++ b/tests/synctex/src/index.tex @@ -0,0 +1 @@ +Hello, world.