Help with Weave.jl

I’m trying to test out Weave.jl and it works fine when converting to .html, but I can’t get it to convert to .pdf. My project directory looks like this:

WeaveTest/
-src/
--main.jl
--test.jmd

In main.jl, I am calling weave(raw"C:\Users\mthel\Julia\WeaveTest\src\test.jmd", doctype="md2pdf")

and it produces this error:

ERROR: IOError: could not spawn `xelatex -shell-escape -halt-on-error test.tex`: no such file or directory (ENOENT)
Stacktrace:
  [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Union{RawFD, Base.Libc.WindowsRawSocket, IO}})
    @ Base .\process.jl:128
  [2] #724
    @ .\process.jl:139 [inlined]
  [3] setup_stdios(f::Base.var"#724#725"{Cmd}, stdios::Vector{Union{RawFD, Base.Libc.WindowsRawSocket, IO}})
    @ Base .\process.jl:223
  [4] _spawn
    @ .\process.jl:138 [inlined]
  [5] run(::Cmd; wait::Bool)
    @ Base .\process.jl:479
  [6] run
    @ .\process.jl:477 [inlined]
  [7] write_doc(docformat::Weave.LaTeX2PDF, doc::Weave.WeaveDoc, rendered::String, out_path::String)
    @ Weave C:\Users\mthel\.julia\packages\Weave\f7Ly3\src\writer\latex.jl:10
  [8] write_doc(doc::Weave.WeaveDoc, rendered::String, out_path::String)
    @ Weave C:\Users\mthel\.julia\packages\Weave\f7Ly3\src\writer\writer.jl:2
  [9] weave(source::String; doctype::String, informat::Nothing, out_path::Symbol, args::Dict{Any, Any}, mod::Nothing, fig_path::Nothing, fig_ext::Nothing, cache_path::String, cache::Symbol, template::Nothing, css::Nothing, highlight_theme::Nothing, pandoc_options::Vector{String}, latex_cmd::Vector{String}, keep_unicode::Bool)
    @ Weave C:\Users\mthel\.julia\packages\Weave\f7Ly3\src\Weave.jl:226
 [10] top-level scope
    @ c:\Users\mthel\Julia\WeaveTest\src\main.jl:3

After calling weave, I get a test.tex file and if I open a console and manually input the command: xelatex -shell-escape -halt-on-error test.tex, it produces the .pdf as expected.

I think what you are doing should work, and this is likely a bug. I have only used Weave a handful of times, but this works for me. Maybe setting the out_path keyword argument will help xelatex find the file.

    weave(
        normpath(@__DIR__, "..", "src", "KD232_nomenclature.jl");
        doctype = "md2pdf",
        out_path = normpath(@__DIR__, "..", "KD232_nomenclature.pdf"),
    )
    rm(normpath(@__DIR__, "..", "KD232_nomenclature.aux"))
    rm(normpath(@__DIR__, "..", "KD232_nomenclature.log"))
    rm(normpath(@__DIR__, "..", "KD232_nomenclature.out"))
    rm(normpath(@__DIR__, "..", "KD232_nomenclature.tex"))

There are four intermediate files that are created between markdown and pdf, so I just delete them afterward.

1 Like

So it looks like something weird is going on and Julia can’t seem to execute the xelatex command. I can do run(weather_cli --help) (where weather_cli is a command line utility I have installed) and it successfully executes that command and I see the output in my Julia REPL, but if I do run(xelatex --help) I get the error: ERROR: IOError: could not spawn xelatex --help: no such file or directory (ENOENT). This is strange because, as I mentioned, I can open a console and run xelatex without any problems…

EDIT: If I specify the full path to the xelatex executable, it works:

run(`$(normpath("C:\\Program Files\\MiKTeX\\miktex\\bin\\x64\\xelatex.exe")) -shell-escape -halt-on-error test.tex`)

I just confirmed that I can convert to pdf with the latest version of Weave even without the out_path argument. run(xelatex --help) works as expected in my Julia REPL, so your issue is definitely related to that. I’m don’t know enough to help you further. :face_with_diagonal_mouth:

1 Like

So I just needed to restart my computer :laughing:. When all else fails, unplug it, and plug it back in!

1 Like