From 7bb7c734b7ff3c57b74d5bd16ce1ceb982dc2820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gunnar=20Farneb=C3=A4ck?= Date: Thu, 31 Oct 2024 23:06:07 +0100 Subject: [PATCH] Update after review. --- NEWS.md | 1 + README.md | 3 --- src/Commands.jl | 38 +++++++++++++--------------------- test/interface/TestCommands.jl | 6 ++++-- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7f82073..d691405 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ - Throw a `ContextError` for context values of an incorrect type - The `preamble` used in `render` and some `show` methods can now be specified using `set_preamble` - `render` now supports the `ignorestatus = true` keyword parameter +- Emulation of Typst command line interface. `typst("compile input.typ output.pdf")` ### Bug Fixes diff --git a/README.md b/README.md index 409bb81..0cfd519 100644 --- a/README.md +++ b/README.md @@ -83,9 +83,6 @@ julia> render(1:4); - Render documents using the Typst compiler - Display in IJulia.jl, Pluto.jl, and QuartoRunner.jl notebooks - Use the [JuliaMono](https://github.com/cormullion/juliamono) typeface -- Emulation of Typst command line interface. - - `typst("w input.typ output.pdf")` - - `typst(["compile", infile, outfile]) ### Planned diff --git a/src/Commands.jl b/src/Commands.jl index 78cd04d..08dc861 100644 --- a/src/Commands.jl +++ b/src/Commands.jl @@ -533,38 +533,28 @@ showerror(io::IO, te::TypstError) = print(io, "TypstError: failed to `run` a `", TypstCommand, "(", te.command.parameters, ")`") """ - typst(parameters::AbstractVector{<:AbstractString}; catch_interrupt = true, ignorestatus = true) + typst(args::AbstractString; catch_interrupt = true, ignorestatus = true) -Run `typst` with the provided `parameters`. When `catch_interrupt` is true, -CTRL-C quietly quits the command. When `ignorestatus` is true, a typst -failure will not imply a julia error. - -Use `TypstCommand` if you need to capture output. - -# Examples - - typst(["compile", "my document.typ"]) - typst(["watch", "input.typ", "output.pdf"]) - typst(["--version"]) - ---- - - typst(args::AbstractString) - -Convenience method intended for interactive use, emulating the typst +Convenience function intended for interactive use, emulating the typst command line interface. Be aware, however, that it strictly splits `args` on spaces and does not provide any shell-style escape -mechanism, so if you have filenames with spaces you should use the -previous method. +mechanism, so it will not work if there are, e.g., filenames with +spaces. + +When `catch_interrupt` is true, CTRL-C quietly quits the +command. When `ignorestatus` is true, a typst failure will not imply a +julia error. + +Use `TypstCommand` if you need to capture output. # Examples - typst("c my_document.typ") + typst("c document.typ") typst("watch input.typ output.pdf") """ -function typst(parameters::AbstractVector{<:AbstractString}; +function typst(args::AbstractString; catch_interrupt = true, ignorestatus = true) - tc = addenv(TypstCommand(TypstCommand([parameters...]); ignorestatus), + tc = addenv(TypstCommand(TypstCommand(split(args)); ignorestatus), "TYPST_FONT_PATHS" => julia_mono) if catch_interrupt try run(tc) @@ -575,6 +565,6 @@ function typst(parameters::AbstractVector{<:AbstractString}; nothing end -typst(args::AbstractString) = typst(split(args)) +typst() = typst(split(args)) end # Commands diff --git a/test/interface/TestCommands.jl b/test/interface/TestCommands.jl index e8d0574..0e663ad 100644 --- a/test/interface/TestCommands.jl +++ b/test/interface/TestCommands.jl @@ -25,9 +25,11 @@ const tc_ignorestatus = ignorestatus(tc_error) outfile1 = joinpath(tmpdir, "test.pdf") outfile2 = joinpath(tmpdir, "out.pdf") write(infile, "= Test Document\n") - typst(["compile", infile]) + cd(tmpdir) do + typst("compile test.typ") + typst("c test.typ out.pdf") + end @test isfile(outfile1) - typst(["c", infile, outfile2]) @test isfile(outfile2) # Only check that it runs without error. redirect_stdout(devnull) do