Skip to content

Commit 206faa7

Browse files
authored
Output raw typst markup if debugging rendering (#65)
Add an `--output` option the _render_ command (analogous to the option of the same name in the _check_ command) to output the intermediate Typst markup that will be passed to the typesetter.
2 parents 4d92454 + c81e486 commit 206faa7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/main.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use tracing_subscriber::{self, EnvFilter};
99

1010
use technique::formatting::*;
1111
use technique::formatting::{self};
12+
1213
use technique::parsing;
1314

1415
mod problem;
@@ -17,6 +18,7 @@ mod rendering;
1718
#[derive(Eq, Debug, PartialEq)]
1819
enum Output {
1920
Native,
21+
Typst,
2022
Silent,
2123
}
2224

@@ -108,6 +110,15 @@ fn main() {
108110
PDF. By default this will highlight the source of the \
109111
input file for the purposes of reviewing the raw \
110112
procedure.")
113+
.arg(
114+
Arg::new("output")
115+
.short('o')
116+
.long("output")
117+
.value_parser(["typst", "none"])
118+
.default_value("none")
119+
.action(ArgAction::Set)
120+
.help("Output format: pdf (default) or typst markup.")
121+
)
111122
.arg(
112123
Arg::new("filename")
113124
.required(true)
@@ -215,6 +226,17 @@ fn main() {
215226
print!("{}", result);
216227
}
217228
Some(("render", submatches)) => {
229+
let output = submatches
230+
.get_one::<String>("output")
231+
.unwrap();
232+
let output = match output.as_str() {
233+
"typst" => Output::Typst,
234+
"none" => Output::Silent,
235+
_ => panic!("Unrecognized --output value"),
236+
};
237+
238+
debug!(?output);
239+
218240
let filename = submatches
219241
.get_one::<String>("filename")
220242
.unwrap(); // argument are required by definition so always present
@@ -244,6 +266,18 @@ fn main() {
244266
};
245267

246268
let result = formatting::render(&Typst, &technique, 70);
269+
270+
match output {
271+
Output::Typst => {
272+
print!("{}", result);
273+
}
274+
_ => {
275+
// ignore; the default is to not output any intermediate
276+
// representations and instead proceed to invoke the
277+
// typesetter to generate the desired PDF.
278+
}
279+
}
280+
247281
rendering::via_typst(&filename, &result);
248282
}
249283
Some(_) => {

0 commit comments

Comments
 (0)