Skip to content
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion docs/src/man/other-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 26 additions & 3 deletions src/latex/LaTeXWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions test/examples/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 11 additions & 2 deletions test/examples/tests_latex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down