-
Notifications
You must be signed in to change notification settings - Fork 95
/
LaTeXWriter.jl
54 lines (50 loc) · 2.66 KB
/
LaTeXWriter.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using DocumenterLaTeX, Markdown
import Documenter: Documents, Documenter, Writers, Utilities
import Documenter.Writers.LaTeXWriter: piperun, _print
const LaTeX_CC="xelatex"
const DOCKER_IMAGE = "tianjun2018/documenter-latex:latest"
function Documenter.Writers.LaTeXWriter.latexinline(io, math::Markdown.LaTeX)
# Handle MathJax and TeX inconsistency since the first wants `\LaTeX` wrapped
# in math delims, whereas actual TeX fails when that is done.
math.formula == "\\LaTeX" ? _print(io, " ", math.formula, " ") : _print(io, " \\(", math.formula, "\\) ")
end
function Documenter.Writers.LaTeXWriter.compile_tex(doc::Documents.Document, settings::LaTeX, texfile::String)
if settings.platform == "native"
Sys.which("latexmk") === nothing && (@error "LaTeXWriter: latexmk command not found."; return false)
@info "LaTeXWriter: using latexmk to compile tex."
piperun(`latexmk -f -interaction=nonstopmode -view=none -$(LaTeX_CC) -shell-escape $texfile`)
return true
# NOTE: 中文排版依然有问题,我们暂时不管他们。输出的pdf大部分情况下依然可以使用。
# try
# piperun(`latexmk -f -interaction=nonstopmode -view=none -$(LaTeX_CC) -shell-escape $texfile`)
# return true
# catch err
# logs = cp(pwd(), mktempdir(); force=true)
# @error "LaTeXWriter: failed to compile tex with latexmk. " *
# "Logs and partial output can be found in $(Utilities.locrepr(logs))." exception = err
# return false
# end
elseif settings.platform == "docker"
Sys.which("docker") === nothing && (@error "LaTeXWriter: docker command not found."; return false)
@info "LaTeXWriter: using docker to compile tex."
script = """
mkdir /home/zeptodoctor/build
cd /home/zeptodoctor/build
cp -r /mnt/. .
latexmk -f -interaction=nonstopmode -view=none -$(LaTeX_CC) -shell-escape $texfile
"""
try
piperun(`docker run -itd -u zeptodoctor --name latex-container -v $(pwd()):/mnt/ --rm $(DOCKER_IMAGE)`)
piperun(`docker exec -u zeptodoctor latex-container bash -c $(script)`)
piperun(`docker cp latex-container:/home/zeptodoctor/build/. .`)
return true
catch err
logs = cp(pwd(), mktempdir(); force=true)
@error "LaTeXWriter: failed to compile tex with docker. " *
"Logs and partial output can be found in $(Utilities.locrepr(logs))." exception = err
return false
finally
try; piperun(`docker stop latex-container`); catch; end
end
end
end