Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new platform to compile only to latex #1339

Merged
merged 6 commits into from
Jun 21, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

* ![Enhancement][badge-enhancement] You can now optionally choose to push pull request preview builds to a different branch and/or different repository than the main docs builds, by setting the optional `branch_previews` and/or `repo_previews` keyword arguments to the `deploydocs` function. Also, you can now optionally choose to use a different SSH key for preview builds, by setting the optional `DOCUMENTER_KEY_PREVIEWS` environment variable; if the `DOCUMENTER_KEY_PREVIEWS` environment variable is not set, then the regular `DOCUMENTER_KEY` environment variable will be used. ([#1307][github-1307], [#1310][github-1310], [#1315][github-1315])

* ![Enhancement][badge-enhancement] The LaTeX/PDF backend now supports the `platform="none"` keyword, which outputs only the TeX source files, rather than a compiled PDF. ([#1338][github-1338], [#1339][github-1339])

* ![Bugfix][badge-bugfix] `Deps.pip` is again a closure and gets executed during the `deploydocs` call, not before it. ([#1240][github-1240])

* ![Bugfix][badge-bugfix] Custom assets (CSS, JS etc.) for the HTML build are now again included as the very last elements in the `<head>` tag so that it would be possible to override default the default assets. ([#1328][github-1328])
Expand Down Expand Up @@ -580,6 +582,8 @@
[github-1315]: https://github.com/JuliaDocs/Documenter.jl/pull/1315
[github-1323]: https://github.com/JuliaDocs/Documenter.jl/pull/1323
[github-1328]: https://github.com/JuliaDocs/Documenter.jl/pull/1328
[github-1338]: https://github.com/JuliaDocs/Documenter.jl/issues/1338
[github-1339]: https://github.com/JuliaDocs/Documenter.jl/pull/1339

[documenterlatex]: https://github.com/JuliaDocs/DocumenterLaTeX.jl
[documentermarkdown]: https://github.com/JuliaDocs/DocumenterMarkdown.jl
Expand Down
13 changes: 13 additions & 0 deletions docs/src/man/other-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,16 @@ services:
```

to your `.travis.yml` file.

### Compiling to LaTeX only

There's a possibility to save only the `.tex` file and skip the PDF compilation.
For this purpose use the `platform="none"` keyword:

```
using DocumenterLaTeX
makedocs(
format = LaTeX(platform = "none"),
...
)
```
17 changes: 12 additions & 5 deletions src/Writers/LaTeXWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ The `makedocs` argument `authors` should also be specified, it will be used for

# Keyword arguments

**`platform`** sets the platform where the tex-file is compiled, either `"native"` (default) or `"docker"`.
**`platform`** sets the platform where the tex-file is compiled, either `"native"` (default), `"docker"`,
or "none" which doesn't compile the tex.
cserteGT3 marked this conversation as resolved.
Show resolved Hide resolved

See [Other Output Formats](@ref) for more information.
"""
struct LaTeX <: Documenter.Writer
platform::String
function LaTeX(; platform = "native")
platform ∈ ("native", "docker") || throw(ArgumentError("unknown platform: $platform"))
platform ∈ ("native", "docker", "none") || throw(ArgumentError("unknown platform: $platform"))
return new(platform)
end
end
Expand Down Expand Up @@ -94,7 +96,7 @@ function mktempdir(args...; kwargs...)
end

function render(doc::Documents.Document, settings::LaTeX=LaTeX())
@info "LaTeXWriter: rendering PDF."
@info "LaTeXWriter: creating the LaTeX file."
Base.mktempdir() do path
cp(joinpath(doc.user.root, doc.user.build), joinpath(path, "build"))
cd(joinpath(path, "build")) do
Expand Down Expand Up @@ -146,9 +148,11 @@ function render(doc::Documents.Document, settings::LaTeX=LaTeX())
@info "LaTeX sources copied for debugging to $(sources)"
end

# If the build was successful, copy of the PDF to the .build directory
if status
# If the build was successful, copy the PDF or the LaTeX source to the .build directory
if status && (settings.platform != "none")
cp(pdffile, joinpath(doc.user.root, doc.user.build, pdffile); force = true)
elseif status && (settings.platform == "none")
cp(pwd(), joinpath(doc.user.root, doc.user.build); force = true)
else
error("Compiling the .tex file failed. See logs for more information.")
end
Expand Down Expand Up @@ -193,6 +197,9 @@ function compile_tex(doc::Documents.Document, settings::LaTeX, texfile::String)
finally
try; piperun(`docker stop latex-container`); catch; end
end
elseif settings.platform == "none"
@info "Skipping compiling tex file."
return true
end
end

Expand Down
43 changes: 43 additions & 0 deletions test/examples/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,46 @@ else
@info "Skipping build: LaTeXWriter/latex_simple_nondocker" 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(
format = Documenter.Writers.LaTeXWriter.LaTeX(platform = "none"),
sitename = "Documenter LaTeX",
root = examples_root,
build = "builds/latex_texonly",
pages = htmlbuild_pages = Any[
"General" => [
"index.md",
"latex.md",
"unicode.md",
hide("hidden.md"),
],
# SVG images nor code blocks in footnotes are allowed in LaTeX
# "Manual" => [
# "man/tutorial.md",
# "man/style.md",
# ],
hide("Hidden Pages" => "hidden/index.md", Any[
"Page X" => "hidden/x.md",
"hidden/y.md",
"hidden/z.md",
]),
"Library" => [
"lib/functions.md",
"lib/autodocs.md",
"lib/editurl.md",
],
"Expandorder" => [
"expandorder/00.md",
"expandorder/01.md",
"expandorder/AA.md",
],
],
doctest = false,
debug = true,
)
else
@info "Skipping build: LaTeXWriter/latex_texonly" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing)
nothing
end
11 changes: 10 additions & 1 deletion test/examples/tests_latex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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"] = "latex latex_simple"
ENV["DOCUMENTER_TEST_EXAMPLES"] = "latex latex_simple latex_texonly"

# 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 Down Expand Up @@ -40,4 +40,13 @@ end
@test joinpath(build_dir, "DocumenterLaTeX$(tagsuffix).pdf") |> isfile
end
end

@testset "PDF/LaTeX: TeX only" begin
doc = Main.examples_latex_texonly_doc
@test isa(doc, Documenter.Documents.Document)
let build_dir = joinpath(examples_root, "builds", "latex_texonly")
@test joinpath(build_dir, "DocumenterLaTeX$(tagsuffix).tex") |> isfile
@test joinpath(build_dir, "documenter.sty") |> isfile
end
end
end