Skip to content

Commit

Permalink
WIP WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Dec 2, 2018
1 parent 11407f5 commit 6ad6ee6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterLaTeX = "cd674d7a-5f81-5cf3-af33-235ef1834b99"
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Documenter, DocumenterTools
using Documenter, DocumenterTools, DocumenterLaTeX

makedocs(
modules = [Documenter, DocumenterTools],
format = Documenter.Writers.LaTeXWriter.LaTeX(),
clean = false,
assets = ["assets/favicon.ico"],
sitename = "Documenter.jl",
Expand Down
7 changes: 4 additions & 3 deletions src/Documents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ struct User
root :: String # An absolute path to the root directory of the document.
source :: String # Parent directory is `.root`. Where files are read from.
build :: String # Parent directory is also `.root`. Where files are written to.
format :: Vector{Symbol} # What format to render the final document with?
format :: Vector{Any} # What format to render the final document with?
clean :: Bool # Empty the `build` directory before starting a new build?
doctest :: Union{Bool,Symbol} # Run doctests?
linkcheck::Bool # Check external links..
Expand Down Expand Up @@ -262,8 +262,9 @@ function Document(plugins;
)
Utilities.check_kwargs(others)

fmt = Formats.fmt(format)
@assert !isempty(fmt) "No formats provided."
# fmt = Formats.fmt(format)
# @assert !isempty(fmt) "No formats provided."
fmt = [format]

if version == "git-commit"
version = "git:$(Utilities.get_commit_short(root))"
Expand Down
16 changes: 12 additions & 4 deletions src/Writers/LaTeXWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ navigation menu. It goes into the `\\title` LaTeX command.
"""
module LaTeXWriter

struct LaTeX
info::Dict{String,Any}
end
function LaTeX()
return LaTeX(Dict{String,Any}("engine" => "latexmk"))
end

import ...Documenter:
Anchors,
Builder,
Expand Down Expand Up @@ -53,7 +60,7 @@ const DOCUMENT_STRUCTURE = (
"subparagraph",
)

function render(doc::Documents.Document)
function render(doc::Documents.Document, fmt::LaTeX)
mktempdir() do path
cp(joinpath(doc.user.root, doc.user.build), joinpath(path, "build"))
cd(joinpath(path, "build")) do
Expand Down Expand Up @@ -86,16 +93,17 @@ function render(doc::Documents.Document)
cp(STYLE, "documenter.sty")

# compile .tex and copy over the .pdf file if compile_tex return true
status = compile_tex(texfile)
status = compile_tex(doc, fmt, texfile)
status && cp(pdffile, joinpath(doc.user.root, doc.user.build, pdffile); force = true)
end
end
end

const DOCKER_IMAGE_TAG = "0.1"

function compile_tex(texfile)
engine = get(ENV, "DOCUMENTER_LATEX_ENGINE", "latexmk") # TODO: make this configurable from makedocs
function compile_tex(doc, fmt, texfile)
# engine = get(ENV, "DOCUMENTER_LATEX_ENGINE", "docker") # TODO: make this configurable from makedocs
engine = get(fmt.info, "engine", "docker")
if engine == "latexmk"
Sys.which("latexmk") === nothing && (@error "LaTeXWriter: latexmk command not found."; return false)
@info "LaTeXWriter: using latexmk to compile tex."
Expand Down
4 changes: 2 additions & 2 deletions src/Writers/Writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Selectors.order(::Type{LaTeXFormat}) = 2.0
Selectors.order(::Type{HTMLFormat}) = 3.0

Selectors.matcher(::Type{MarkdownFormat}, fmt, _) = fmt === :markdown
Selectors.matcher(::Type{LaTeXFormat}, fmt, _) = fmt === :latex
Selectors.matcher(::Type{LaTeXFormat}, fmt, _) = fmt === :latex || isa(fmt, LaTeXWriter.LaTeX)
Selectors.matcher(::Type{HTMLFormat}, fmt, _) = fmt === :html

Selectors.runner(::Type{MarkdownFormat}, _, doc) = MarkdownWriter.render(doc)
Selectors.runner(::Type{LaTeXFormat}, _, doc) = LaTeXWriter.render(doc)
Selectors.runner(::Type{LaTeXFormat}, fmt, doc) = LaTeXWriter.render(doc, fmt)
Selectors.runner(::Type{HTMLFormat}, _, doc) = HTMLWriter.render(doc)

"""
Expand Down

0 comments on commit 6ad6ee6

Please sign in to comment.