Skip to content

Commit

Permalink
Include typst docstring in commands.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobjpeters committed Oct 31, 2024
1 parent a59bf8c commit 49a3814
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 50 deletions.
8 changes: 4 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

import Dates, Documenter, LaTeXStrings, Markdown
using Base: get_extension
using Dates: Dates
using Documenter: Documenter, Docs, DocMeta, deploydocs, makedocs
using Documenter: Docs, DocMeta, deploydocs, makedocs
using .Docs: HTML, Text
using .DocMeta: setdocmeta!
using LaTeXStrings: LaTeXStrings, LaTeXString
using LaTeXStrings: LaTeXString
using Luxor: Drawing, finish, julia_blue, julia_green, julia_purple, julia_red, rect, sethue
using Markdown: Markdown, MD
using Markdown: MD
using Typstry: Strings, preamble
using .Strings: examples, _show_typst, enclose, join_with, typst_mime
using Typstry
Expand Down
1 change: 1 addition & 0 deletions docs/source/references/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ julia_mono
preamble
render
set_preamble
typst
```

## `Base`
Expand Down
66 changes: 31 additions & 35 deletions src/Commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,37 @@ function set_preamble(ts::TypstString = default_preamble)
ts
end

"""
typst(::AbstractString; catch_interrupt = true, ignorestatus = true)
Convenience function intended for interactive use, emulating the typst
command line interface. Be aware, however, that it strictly splits
on spaces and does not provide any shell-style escape
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.
# Examples
```jldoctest
julia> typst("compile input.typ output.pdf")
```
"""
function typst(args::AbstractString; catch_interrupt = true, ignorestatus = true)
tc = addenv(TypstCommand(TypstCommand(split(args));
ignorestatus), "TYPST_FONT_PATHS" => julia_mono)
if catch_interrupt
try run(tc)
catch e e isa InterruptException || rethrow()
end
else run(tc)
end
nothing
end

# `Base`

"""
Expand Down Expand Up @@ -532,39 +563,4 @@ TypstError: failed to `run` a `TypstCommand(String[])`
showerror(io::IO, te::TypstError) = print(io,
"TypstError: failed to `run` a `", TypstCommand, "(", te.command.parameters, ")`")

"""
typst(args::AbstractString; catch_interrupt = true, ignorestatus = true)
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 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 document.typ")
typst("watch input.typ output.pdf")
"""
function typst(args::AbstractString;
catch_interrupt = true, ignorestatus = true)
tc = addenv(TypstCommand(TypstCommand(split(args)); ignorestatus),
"TYPST_FONT_PATHS" => julia_mono)
if catch_interrupt
try run(tc)
catch e e isa InterruptException || rethrow()
end
else run(tc)
end
nothing
end

typst() = typst(split(args))

end # Commands
1 change: 0 additions & 1 deletion test/extensions/TestLaTeXStringsExtension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module TestLaTeXStringsExtension

using ..TestTypstry: test_modes, test_strings
using LaTeXStrings: @L_str
using Typstry

const latex = L"a"

Expand Down
1 change: 0 additions & 1 deletion test/extensions/TestMarkdownExtension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module TestMarkdownExtension

using ..TestTypstry: test_modes, test_strings
using Markdown: @md_str
using Typstry

const markdown = md"""a\
b"""
Expand Down
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ using Typstry

module TestTypstry

import LaTeXStrings, Markdown, Typstry
using Base: get_extension
using LaTeXStrings: LaTeXStrings
using Markdown: Markdown
using Test: @test, @testset
using Typstry: Typstry, Mode, TypstString
using Typstry: Mode, TypstString

const names = [:LaTeXStrings, :Markdown]
const modules = map(name -> get_extension(Typstry, Symbol(name, :Extension)), names)
Expand Down
2 changes: 1 addition & 1 deletion test/utilities/TestAqua.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

module TestAqua

import Typstry
using Aqua: test_all, test_deps_compat
using Typstry: Typstry

# TODO: test package extensions
redirect_stdout(devnull) do
Expand Down
3 changes: 1 addition & 2 deletions test/utilities/TestDocumenter.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

module TestDocumenter

import Dates, Typstry
using Base: get_extension, disable_logging
using Dates: Dates
using Documenter: DocMeta.setdocmeta!, doctest
using Logging: Debug, Warn, disable_logging
using ..TestTypstry: names, modules
using Typstry: Typstry

function test(_module, x)
setdocmeta!(_module, :DocTestSetup, :(using Typstry; using $x: $x); recursive = true)
Expand Down
6 changes: 3 additions & 3 deletions test/utilities/TestExplicitImports.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

module TestExplicitImports

import Typstry
using ExplicitImports:
check_all_explicit_imports_are_public,
check_all_explicit_imports_via_owners,
Expand All @@ -10,10 +11,9 @@ using ExplicitImports:
check_no_self_qualified_accesses,
check_no_stale_explicit_imports
using Test: @test
using Typstry: Typstry

@test isnothing(check_all_explicit_imports_are_public(Typstry; ignore = (
:MD, :Stateful, :compile_workload, :parse)))
@test isnothing(check_all_explicit_imports_are_public(Typstry;
ignore = (:MD, :Stateful, :compile_workload, :parse)))

for check in [
check_all_explicit_imports_via_owners,
Expand Down

0 comments on commit 49a3814

Please sign in to comment.