diff --git a/CHANGELOG.md b/CHANGELOG.md index df8ef50e89..1e9b9ed919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## UNRELEASED +### Added + +* Suppport `texify` as a native latex backend. This is of peculiar interest for people using MiKTeX on Windows machines, where `latekmk` may not work properly. The selection of the `native` backend is automatic if `texify` or `latexmk` is installed. Otherwise specifying `texify` or `latexmk` is also possible. + ### Changed * `id` anchors may now start with a numeric digit. ([#744], [#2325]) diff --git a/docs/src/man/other-formats.md b/docs/src/man/other-formats.md index 794299d0b8..da17d2643a 100644 --- a/docs/src/man/other-formats.md +++ b/docs/src/man/other-formats.md @@ -28,7 +28,7 @@ The `makedocs` argument `authors` should also be specified, it will be used for The following is required to build the documentation: -* You need `pdflatex` and `latexmk` commands to be installed and available to Documenter. +* You need `pdflatex` and `latexmk` or `texify` commands to be installed and available to Documenter. * You need the [minted](https://ctan.org/pkg/minted) LaTeX package and its backend source highlighter [Pygments](https://pygments.org/) installed. * You need the [_DejaVu Sans_ and _DejaVu Sans Mono_](https://dejavu-fonts.github.io/) fonts installed. diff --git a/src/latex/LaTeXWriter.jl b/src/latex/LaTeXWriter.jl index 8a88411796..fdc8aa7f5d 100644 --- a/src/latex/LaTeXWriter.jl +++ b/src/latex/LaTeXWriter.jl @@ -56,7 +56,10 @@ struct LaTeX <: Documenter.Writer platform = "native", version = get(ENV, "TRAVIS_TAG", ""), tectonic = nothing) - platform ∈ ("native", "tectonic", "docker", "none") || throw(ArgumentError("unknown platform: $platform")) + if platform == "native" + platform = hastex() + end + platform ∈ ("latexmk","texify", "tectonic", "docker", "none") || throw(ArgumentError("unknown platform: $platform")) return new(platform, string(version), tectonic) end end @@ -87,7 +90,15 @@ _hash(x) = string(hash(x)) const STYLE = joinpath(dirname(@__FILE__), "..", "..", "assets", "latex", "documenter.sty") const DEFAULT_PREAMBLE_PATH = joinpath(dirname(@__FILE__), "..", "..", "assets", "latex", "preamble.tex") -hastex() = (try; success(`latexmk -version`); catch; false; end) +function hastex() + try + success(`texify --version`) && return "texify" + success(`latexmk --version`) && return "latexmk" + return "" + catch + return "" + end +end const DOCUMENT_STRUCTURE = ( "part", @@ -169,7 +180,7 @@ end const DOCKER_IMAGE_TAG = "0.1" function compile_tex(doc::Documenter.Document, settings::LaTeX, fileprefix::String) - if settings.platform == "native" + if settings.platform == "latexmk" Sys.which("latexmk") === nothing && (@error "LaTeXWriter: latexmk command not found."; return false) @info "LaTeXWriter: using latexmk to compile tex." try @@ -181,6 +192,18 @@ function compile_tex(doc::Documenter.Document, settings::LaTeX, fileprefix::Stri "Logs and partial output can be found in $(Documenter.locrepr(logs))" exception = err return false end + elseif settings.platform == "texify" + @info "LaTeXWriter: using texify to compile tex." + texify = Sys.which("texify") + isnothing(texify) && (@error "LaTeXWriter: texify command not found."; return false) + try + piperun(`$(texify) -p -b --engine=luatex --tex-option=--shell-escape $(fileprefix).tex`, clearlogs=true) + return true + catch err + logs = cp(pwd(), mktempdir(; cleanup = false); force = true) + @error "LaTeXWriter: failed to compile tex with texify. " * "Logs and partial output can be found in $(Documenter.locrepr(logs))" exception = err + return false + end elseif settings.platform == "tectonic" @info "LaTeXWriter: using tectonic to compile tex." tectonic = isnothing(settings.tectonic) ? Sys.which("tectonic") : settings.tectonic diff --git a/test/examples/make.jl b/test/examples/make.jl index c1e64d7af5..0c34a6c4f1 100644 --- a/test/examples/make.jl +++ b/test/examples/make.jl @@ -20,7 +20,7 @@ else ["html", "html-meta-custom", "html-mathjax2-custom", "html-mathjax3", "html-mathjax3-custom", "html-local", "html-draft", "html-repo-git", "html-repo-nothing", "html-repo-error", "html-sizethreshold-defaults-fail", "html-sizethreshold-success", "html-sizethreshold-ignore-success", "html-sizethreshold-override-fail", "html-sizethreshold-ignore-success", "html-sizethreshold-ignore-fail", - "latex_texonly", "latex_simple_texonly", "latex_showcase_texonly", "html-pagesonly"] + "latex_texonly", "latex_simple_texonly", "latex_showcase_texonly", "html-pagesonly"] end # Modules `Mod` and `AutoDocs` @@ -669,7 +669,7 @@ end examples_latex_simple_nondocker_doc = if "latex_simple_nondocker" in EXAMPLE_BUILDS @info("Building mock package docs: LaTeXWriter/latex_simple_nondocker") @quietly makedocs( - format = Documenter.LaTeX(version = v"1.2.3"), + format = Documenter.LaTeX(platform="native",version = v"1.2.3"), sitename = "Documenter LaTeX Simple Non-Docker", root = examples_root, build = "builds/latex_simple_nondocker", @@ -703,7 +703,6 @@ else nothing end - examples_latex_texonly_doc = if "latex_texonly" in EXAMPLE_BUILDS @info("Building mock package docs: LaTeXWriter/latex_texonly") @quietly makedocs( diff --git a/test/examples/tests_latex.jl b/test/examples/tests_latex.jl index f088a73bb6..f893a39547 100644 --- a/test/examples/tests_latex.jl +++ b/test/examples/tests_latex.jl @@ -2,9 +2,9 @@ using Test # DOCUMENTER_TEST_EXAMPLES can be used to control which builds are performed in # make.jl, and we need to set it to the relevant LaTeX builds. -ENV["DOCUMENTER_TEST_EXAMPLES"] = +ENV["DOCUMENTER_TEST_EXAMPLES"] = "latex latex_simple latex_cover_page latex_toc_style latex_simple_tectonic " * - "latex_showcase" + "latex_showcase latex_simple_nondocker" # When the file is run separately we need to include make.jl which actually builds # the docs and defines a few modules that are referred to in the docs. The make.jl @@ -27,6 +27,15 @@ else end @testset "Examples/LaTeX" begin + + @testset "PDF/LaTeX: simple nondocker" begin + doc = Main.examples_latex_simple_nondocker_doc + @test isa(doc, Documenter.Documenter.Document) + let build_dir = joinpath(examples_root, "builds", "latex_simple_nondocker") + @test joinpath(build_dir, "DocumenterLaTeXSimpleNonDocker-1.2.3.pdf") |> isfile + end + end + @testset "PDF/LaTeX: simple" begin doc = Main.examples_latex_simple_doc @test isa(doc, Documenter.Documenter.Document)