Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
tectonic_jll = "d7dd28d6-a5e6-559c-9131-7eb760cdacc5"

[extensions]
DataFramesExt = "DataFrames"
SymEngineExt = "SymEngine"
SparseArraysExt = "SparseArrays"
TectonicExt = "tectonic_jll"

[compat]
DataFrames = "1"
Expand All @@ -33,13 +35,15 @@ Requires = "0.5, 1"
SymEngine = "0.11, 0.12"
julia = "1.6"
SparseArrays="1.6"
tectonic_jll="0.15"

[extras]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
tectonic_jll = "d7dd28d6-a5e6-559c-9131-7eb760cdacc5"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["DataFrames", "OffsetArrays", "SymEngine", "SparseArrays", "Test"]
test = ["DataFrames", "OffsetArrays", "SymEngine", "SparseArrays", "tectonic_jll", "Test"]
6 changes: 6 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ using ImageInTerminal, Latexify
latexify(:(iħ * (∂Ψ(𝐫, t) / ∂t) = -ħ^2 / 2m * ΔΨ(𝐫, t) + V * Ψ(𝐫, t))) |> s -> render(s, dpi=200)
```

### Tectonic

The `tectonic_jll` package can be used as a lightweight compiler for CI and similar setups.
An extension to `Latexify` makes `render` (to pdf) automatically use `tectonic_jll` if both packages are loaded.
To still render using the default compiler, use `render(...; use_tectonic=false)`.

## Legacy support

Latexify.jl has stopped supporting Julia versions older than 0.7. This does not mean that you cannot use Latexify with earlier versions, just that these will not get new features. Latexify.jl's release v0.4.1 was the last which supported Julia 0.6. Choose that release in the dropdown menu if you want to see that documentation.
11 changes: 11 additions & 0 deletions ext/TectonicExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module TectonicExt
import LaTeXStrings.LaTeXString
import Latexify.render, Latexify._compile
isdefined(Base, :get_extension) ? (using tectonic_jll) : (using ..tectonic_jll)
__precompile__(false)

function render(s::LaTeXString, ::MIME"application/pdf"; use_tectonic=true, kw...)
use_tectonic && return _compile(s, `$(tectonic()) --keep-logs main.tex`, "pdf"; kw...)
return _compile(s, `lualatex --interaction=batchmode main.tex`, "pdf"; kw...)
end
end
3 changes: 3 additions & 0 deletions src/Latexify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function __init__()
@require SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" begin
include("../ext/SparseArraysExt.jl")
end
@require tectonic_jll = "d7dd28d6-a5e6-559c-9131-7eb760cdacc5" begin
include("../ext/TectonicExt.jl")
end
end
end

Expand Down
5 changes: 4 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ function _compile(s::LaTeXString, cmd::Cmd, ext::String;
debug=false,
name=tempname(),
open=true,
use_tectonic=false,
kw...
)
use_tectonic && throw(ArgumentError("`use_tectonic` requires the `tectonic_jll` package"))
name = abspath(name)
mktempdir() do source_dir
cd(source_dir) do
Expand All @@ -49,6 +51,7 @@ function _compile(s::LaTeXString, cmd::Cmd, ext::String;
run(cmd)
catch err
isa(err, ProcessFailedException) || rethrow(err)
isfile("$source_dir/main.log") || rethrow(LatexifyRenderError(""))
mv("$source_dir/main.log", "$name.log"; force=true)
rethrow(LatexifyRenderError("$name.log"))
end
Expand All @@ -58,7 +61,7 @@ function _compile(s::LaTeXString, cmd::Cmd, ext::String;
if open
_openfile(name; ext=ext)
end
return nothing
return "$name.$ext"
end


Expand Down
8 changes: 4 additions & 4 deletions test/cdot_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Markdown.md"| $x \cdot \left( y - 1 \right)$ |

# Deprecation of cdot = ... in favor of mult_symbol = ...
# (cdot takes precedence over mult_symbol)
@test_deprecated latexify(:(x * y); cdot=false)
@test_deprecated latexify(:(x * y); cdot=true)
@test latexify(:(x * y); mult_symbol="garbage", cdot=false) == latexify(:(x * y); mult_symbol="")
@test latexify(:(x * y); mult_symbol="garbage", cdot=true) == latexify(:(x * y); mult_symbol="\\cdot")
output = @test_deprecated latexify(:(x * y); mult_symbol="garbage", cdot=false)
@test output == latexify(:(x * y); mult_symbol="")
output = @test_deprecated latexify(:(x * y); mult_symbol="garbage", cdot=true)
@test output == latexify(:(x * y); mult_symbol="\\cdot")
5 changes: 5 additions & 0 deletions test/utils_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@ an error occured while rendering LaTeX: \n\tDouble superscript.
\tl.8 \$x^2^
Check the log file at $logfile for more information"""

@test_throws ArgumentError render(L"x^2"; use_tectonic=true)
using tectonic_jll
pdf_file = render(L"x^2"; open=false) # should now not throw
@test isfile(pdf_file)
@test_throws Latexify.LatexifyRenderError render(L"x^2^3"; open=false)
Loading