From 83172bf19c535feed8d2bbaa46f30ee27f6a2cfa Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:11:06 +0100 Subject: [PATCH 01/10] Generalize `hastex` to include `texify` --- src/latex/LaTeXWriter.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/latex/LaTeXWriter.jl b/src/latex/LaTeXWriter.jl index 8a88411796..570bede0a3 100644 --- a/src/latex/LaTeXWriter.jl +++ b/src/latex/LaTeXWriter.jl @@ -87,7 +87,14 @@ _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) +hastex() = ( + try + success(`latexmk -version`) && return "latexmk" + success(`texify --version`) && return "texify" + catch + return "" + end +) const DOCUMENT_STRUCTURE = ( "part", From 116a4ed692ad5d4158d629a6ef4e21b083a31db7 Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:11:46 +0100 Subject: [PATCH 02/10] Allow `texify` and `latexmk` as platforms --- src/latex/LaTeXWriter.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/latex/LaTeXWriter.jl b/src/latex/LaTeXWriter.jl index 570bede0a3..c5a13369ba 100644 --- a/src/latex/LaTeXWriter.jl +++ b/src/latex/LaTeXWriter.jl @@ -56,7 +56,7 @@ struct LaTeX <: Documenter.Writer platform = "native", version = get(ENV, "TRAVIS_TAG", ""), tectonic = nothing) - platform ∈ ("native", "tectonic", "docker", "none") || throw(ArgumentError("unknown platform: $platform")) + platform ∈ ("native", "latexmk","texify", "tectonic", "docker", "none") || throw(ArgumentError("unknown platform: $platform")) return new(platform, string(version), tectonic) end end From 9664cc635d437362319e7c7eefc4008dcf2d7f5a Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:12:12 +0100 Subject: [PATCH 03/10] Make `LaTeX` mutable with only `platform` actually mutable --- src/latex/LaTeXWriter.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/latex/LaTeXWriter.jl b/src/latex/LaTeXWriter.jl index c5a13369ba..0b3fa41715 100644 --- a/src/latex/LaTeXWriter.jl +++ b/src/latex/LaTeXWriter.jl @@ -48,10 +48,10 @@ considered to be deprecated), or to an empty string if `TRAVIS_TAG` is unset. See [Other Output Formats](@ref) for more information. """ -struct LaTeX <: Documenter.Writer +mutable struct LaTeX <: Documenter.Writer platform::String - version::String - tectonic::Union{Cmd,String,Nothing} + const version::String + const tectonic::Union{Cmd,String,Nothing} function LaTeX(; platform = "native", version = get(ENV, "TRAVIS_TAG", ""), From 9dea010c40cbfa440f174c6c4fa5c2a7fc384e6a Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:12:41 +0100 Subject: [PATCH 04/10] Make `platform = "native"` handle selecting the proper platform --- src/latex/LaTeXWriter.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/latex/LaTeXWriter.jl b/src/latex/LaTeXWriter.jl index 0b3fa41715..361a3efc9b 100644 --- a/src/latex/LaTeXWriter.jl +++ b/src/latex/LaTeXWriter.jl @@ -177,6 +177,17 @@ const DOCKER_IMAGE_TAG = "0.1" function compile_tex(doc::Documenter.Document, settings::LaTeX, fileprefix::String) if settings.platform == "native" + @info "LaTeXWriter: attempting to find native platform." + native_platform = hastex() + if !isempty(native_platform) + @info "LaTeXWriter: found native platform $native_platform." + settings.platform = native_platform + return compile_tex(doc,settings,fileprefix) + else + @error "LaTeXWriter: no native platform found." + return false + end + elseif settings.platform == "latexmk" Sys.which("latexmk") === nothing && (@error "LaTeXWriter: latexmk command not found."; return false) @info "LaTeXWriter: using latexmk to compile tex." try @@ -188,6 +199,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 From 6ed0362c8418ef6d9674f971b2417cad1bfab242 Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:12:48 +0100 Subject: [PATCH 05/10] Add tests --- test/examples/make.jl | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/test/examples/make.jl b/test/examples/make.jl index c1e64d7af5..b52e202da5 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_simple_native", "latex_simple_latexmk", "latex_simple_texify", "latex_showcase_texonly", "html-pagesonly"] end # Modules `Mod` and `AutoDocs` @@ -703,6 +703,59 @@ else nothing end +examples_latex_simple_native_doc = if "latex_simple_native" in EXAMPLE_BUILDS + @info("Building mock package docs: LaTeXWriter/latex_simple_native") + @quietly makedocs( + format=Documenter.LaTeX(platform="native", version=v"1.2.3"), + sitename="Documenter LaTeX Simple Native", + root=examples_root, + build="builds/latex_simple_native", + source="src.latex_simple", + pages=["Main section" => ["index.md"]], + doctest=false, + debug=true, + ) +else + @info "Skipping build: LaTeXWriter/latex_simple_native" + @debug "Controlling variables:" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing) + nothing +end + +examples_latex_simple_texify_doc = if "latex_simple_latexmk" in EXAMPLE_BUILDS + @info("Building mock package docs: LaTeXWriter/latex_simple_latexmk") + @quietly makedocs( + format=Documenter.LaTeX(platform="latexmk", version=v"1.2.3"), + sitename="Documenter LaTeX Simple LaTeXMk", + root=examples_root, + build="builds/latex_simple_latexmk", + source="src.latex_simple", + pages=["Main section" => ["index.md"]], + doctest=false, + debug=true, + ) +else + @info "Skipping build: LaTeXWriter/latex_simple_latekmk" + @debug "Controlling variables:" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing) + nothing +end + +examples_latex_simple_texify_doc = if "latex_simple_texify" in EXAMPLE_BUILDS + @info("Building mock package docs: LaTeXWriter/latex_simple_texify") + @quietly makedocs( + format = Documenter.LaTeX(platform="texify", version = v"1.2.3"), + sitename = "Documenter LaTeX Simple Texify", + root = examples_root, + build = "builds/latex_simple_texify", + source = "src.latex_simple", + pages = ["Main section" => ["index.md"]], + doctest = false, + debug = true, + ) +else + @info "Skipping build: LaTeXWriter/latex_simple_texify" + @debug "Controlling variables:" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing) + nothing +end examples_latex_texonly_doc = if "latex_texonly" in EXAMPLE_BUILDS @info("Building mock package docs: LaTeXWriter/latex_texonly") From 31a8a6dae82643303b9db96083e149119479889b Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:48:50 +0100 Subject: [PATCH 06/10] Update src/latex/LaTeXWriter.jl Co-authored-by: Morten Piibeleht --- src/latex/LaTeXWriter.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/latex/LaTeXWriter.jl b/src/latex/LaTeXWriter.jl index 361a3efc9b..8f1acb5c91 100644 --- a/src/latex/LaTeXWriter.jl +++ b/src/latex/LaTeXWriter.jl @@ -87,14 +87,14 @@ _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() = ( +function hastex() try success(`latexmk -version`) && return "latexmk" success(`texify --version`) && return "texify" catch return "" end -) +end const DOCUMENT_STRUCTURE = ( "part", From b3fad8ed76194642f09462fd6d89f1704bfb4091 Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:56:34 +0100 Subject: [PATCH 07/10] Improve native latex option handling --- src/latex/LaTeXWriter.jl | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/latex/LaTeXWriter.jl b/src/latex/LaTeXWriter.jl index 8f1acb5c91..fdc8aa7f5d 100644 --- a/src/latex/LaTeXWriter.jl +++ b/src/latex/LaTeXWriter.jl @@ -48,15 +48,18 @@ considered to be deprecated), or to an empty string if `TRAVIS_TAG` is unset. See [Other Output Formats](@ref) for more information. """ -mutable struct LaTeX <: Documenter.Writer +struct LaTeX <: Documenter.Writer platform::String - const version::String - const tectonic::Union{Cmd,String,Nothing} + version::String + tectonic::Union{Cmd,String,Nothing} function LaTeX(; platform = "native", version = get(ENV, "TRAVIS_TAG", ""), tectonic = nothing) - platform ∈ ("native", "latexmk","texify", "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 @@ -89,8 +92,9 @@ const DEFAULT_PREAMBLE_PATH = joinpath(dirname(@__FILE__), "..", "..", "assets", function hastex() try - success(`latexmk -version`) && return "latexmk" success(`texify --version`) && return "texify" + success(`latexmk --version`) && return "latexmk" + return "" catch return "" end @@ -176,18 +180,7 @@ end const DOCKER_IMAGE_TAG = "0.1" function compile_tex(doc::Documenter.Document, settings::LaTeX, fileprefix::String) - if settings.platform == "native" - @info "LaTeXWriter: attempting to find native platform." - native_platform = hastex() - if !isempty(native_platform) - @info "LaTeXWriter: found native platform $native_platform." - settings.platform = native_platform - return compile_tex(doc,settings,fileprefix) - else - @error "LaTeXWriter: no native platform found." - return false - end - elseif settings.platform == "latexmk" + if settings.platform == "latexmk" Sys.which("latexmk") === nothing && (@error "LaTeXWriter: latexmk command not found."; return false) @info "LaTeXWriter: using latexmk to compile tex." try From 731a587fbeac2c2fbc40e8c08ab6590965b91a75 Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:57:39 +0100 Subject: [PATCH 08/10] Update latex examples list --- test/examples/make.jl | 58 ++---------------------------------- test/examples/tests_latex.jl | 13 ++++++-- 2 files changed, 13 insertions(+), 58 deletions(-) diff --git a/test/examples/make.jl b/test/examples/make.jl index b52e202da5..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_simple_native", "latex_simple_latexmk", "latex_simple_texify", "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,60 +703,6 @@ else nothing end -examples_latex_simple_native_doc = if "latex_simple_native" in EXAMPLE_BUILDS - @info("Building mock package docs: LaTeXWriter/latex_simple_native") - @quietly makedocs( - format=Documenter.LaTeX(platform="native", version=v"1.2.3"), - sitename="Documenter LaTeX Simple Native", - root=examples_root, - build="builds/latex_simple_native", - source="src.latex_simple", - pages=["Main section" => ["index.md"]], - doctest=false, - debug=true, - ) -else - @info "Skipping build: LaTeXWriter/latex_simple_native" - @debug "Controlling variables:" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing) - nothing -end - -examples_latex_simple_texify_doc = if "latex_simple_latexmk" in EXAMPLE_BUILDS - @info("Building mock package docs: LaTeXWriter/latex_simple_latexmk") - @quietly makedocs( - format=Documenter.LaTeX(platform="latexmk", version=v"1.2.3"), - sitename="Documenter LaTeX Simple LaTeXMk", - root=examples_root, - build="builds/latex_simple_latexmk", - source="src.latex_simple", - pages=["Main section" => ["index.md"]], - doctest=false, - debug=true, - ) -else - @info "Skipping build: LaTeXWriter/latex_simple_latekmk" - @debug "Controlling variables:" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing) - nothing -end - -examples_latex_simple_texify_doc = if "latex_simple_texify" in EXAMPLE_BUILDS - @info("Building mock package docs: LaTeXWriter/latex_simple_texify") - @quietly makedocs( - format = Documenter.LaTeX(platform="texify", version = v"1.2.3"), - sitename = "Documenter LaTeX Simple Texify", - root = examples_root, - build = "builds/latex_simple_texify", - source = "src.latex_simple", - pages = ["Main section" => ["index.md"]], - doctest = false, - debug = true, - ) -else - @info "Skipping build: LaTeXWriter/latex_simple_texify" - @debug "Controlling variables:" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing) - 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) From 7784b5c644facdfecf1899355f5cad60b3ff60b7 Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Sun, 1 Dec 2024 21:37:11 +0100 Subject: [PATCH 09/10] Added changelog entry (probably outdated by far) --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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]) From cb3613aefc30e2a1a7186f628a97d26c46929202 Mon Sep 17 00:00:00 2001 From: BambOoxX <42067365+BambOoxX@users.noreply.github.com> Date: Sun, 1 Dec 2024 21:37:29 +0100 Subject: [PATCH 10/10] Modified docs to mention `texify` --- docs/src/man/other-formats.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.