Skip to content

Commit

Permalink
Update after review.
Browse files Browse the repository at this point in the history
  • Loading branch information
GunnarFarneback committed Oct 31, 2024
1 parent 5c61c9b commit 7bb7c73
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 14 additions & 24 deletions src/Commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -575,6 +565,6 @@ function typst(parameters::AbstractVector{<:AbstractString};
nothing
end

typst(args::AbstractString) = typst(split(args))
typst() = typst(split(args))

Check warning on line 568 in src/Commands.jl

View check run for this annotation

Codecov / codecov/patch

src/Commands.jl#L568

Added line #L568 was not covered by tests

end # Commands
6 changes: 4 additions & 2 deletions test/interface/TestCommands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7bb7c73

Please sign in to comment.