How to print out Latex document as pdf?

I have this code and is working fine for my desired output as you can see below.

using Latexify, ParameterizedFunctions, Weave

f = @ode_def positiveFeedback begin
    dx = v*y^n/(k^n+y^n) - x
    dy = x/(k_2+x) - y
end v n k k_2

a = latexify(f)

render(a)

output:

I want to get this output as pdf. I think Weave.jl can be used but I’m not sure how it can be done.

Thank you in advance :slight_smile:

The Weave code goes in a separate file that operates on some other file.
In the other file, comments that start with #' separate chunks and can be used to write markdown text. XeLaTeX must be installed on your computer separately before PDF generation with Weave will work. (You can render to HTML without it though.)

using Weave
set_chunk_defaults!(:echo => false)  # prevents code rendering
weave(
    "input/file/path.jl";
    doctype = "md2pdf",
    out_path = "output/file/path.pdf",
)
using Latexify, ParameterizedFunctions

#' **Some Equations:**
f = @ode_def positiveFeedback begin
    dx = v*y^n/(k^n+y^n) - x
    dy = x/(k_2+x) - y
end v n k k_2

a = latexify(f)

#' Here are some *comments* about the equations.

image

2 Likes

Unless you need your equations to be stored as a separate .jl file though, I recommend writing your code directly in a notebook like Pluto.jl or Quarto. Notebooks will render the LaTeX math natively in HTML, then you can export the whole notebook as a PDF.

3 Likes

I am getting this error while running this code

ERROR: IOError: could not spawn `xelatex -shell-escape -halt-on-error firstlatex.tex`: no such file or directory (ENOENT)
Stacktrace:
  [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Union{RawFD, IO}})
    @ Base ./process.jl:128
  [2] #760
    @ ./process.jl:139 [inlined]
  [3] setup_stdios(f::Base.var"#760#761"{Cmd}, stdios::Vector{Union{RawFD, 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 ~/.julia/packages/Weave/f7Ly3/src/writer/latex.jl:10
  [8] write_doc(doc::Weave.WeaveDoc, rendered::String, out_path::String)
    @ Weave ~/.julia/packages/Weave/f7Ly3/src/writer/writer.jl:2
  [9] weave(source::String; doctype::String, informat::Nothing, out_path::String, 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 ~/.julia/packages/Weave/f7Ly3/src/Weave.jl:226
 [10] top-level scope
    @ Untitled-1:3

I think it did not find your file. The path needs to be either an absolute path (starting from your file system root directory) or a relative path starting from the present working directory of the current Julia process (output of the pwd() command). You can try something like filepath = joinpath(@__DIR__, "firstlatex.jl") if both files are in the same folder.

I tried, still getting same error.

I’m not really sure then. Did Weave create any files? It should create a .tex and some other files before running the xelatex command that gave you the error.

yes, it did

I have this Latex program:

I tried downloading XeLaTeX but it directed me to this page specific for Mac I guess.

Well, you can try running this command in your terminal manually then:

xelatex -shell-escape -halt-on-error firstlatex.tex

I’m not sure why it isn’t working for you automatically. You may need to update to the latest package versions or change your file system permissions. :man_shrugging:t2:

Upon running xelatex -shell-escape -halt-on-error firstlatex.tex :smiling_face_with_tear:

image

Well there’s your problem lol. You will need to troubleshoot your LaTeX installation first and get that command working before Weave will work with it. I think MacTeX is the correct program to download, but I don’t know enough to help you further. My Google search found this which may help.

(Just use Pluto.jl though. It will be easier.)

1 Like

Thank you for link. It helped now I can access XeLaTeX from terminal. I can now produce pdf manually. But it still doesn’t work from VS Code directly. :sweat_smile:

Thank you for all help :slight_smile: