# How to print out Latex document as pdf?

**URL:** <https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786>\
**Category:** New to Julia\
**Tags:** question, latex, weave, pdf-format\
**Created:** [February 26, 2024, 3:11pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786 "2024-02-26T15:11:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [February 26, 2024, 3:11pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/1 "2024-02-26T15:11:48Z")

</div>

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

```julia
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:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/a/4a466e0d367a5b8a0249d2e921dcfc957d6a7680.png)

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 🙂

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [February 26, 2024, 4:58pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/2 "2024-02-26T16:58:10Z")

</div>

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.)

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

```

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/2/b/2b54594d3e77048bc2dfd0911cc2bba78a5a2f21.png)

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [February 26, 2024, 5:13pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/3 "2024-02-26T17:13:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [February 27, 2024, 8:53am UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/4 "2024-02-27T08:53:50Z")

</div>

> [@Nathan\_Boyer](#):
>
> ```julia
> using Weave
> set_chunk_defaults!(:echo => false) # prevents code rendering
> weave(
> "input/file/path.jl";
> doctype = "md2pdf",
> out_path = "output/file/path.pdf",
> )
> 
> ```

I am getting this error while running this code

```julia
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

```

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [February 27, 2024, 2:01pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/5 "2024-02-27T14:01:33Z")

</div>

> [@Sahil\_Khan](#):
>
> “`no such file or directory`”

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.

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [February 27, 2024, 2:12pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/6 "2024-02-27T14:12:02Z")

</div>

I tried, still getting same error.

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [February 27, 2024, 2:17pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/7 "2024-02-27T14:17:56Z")

</div>

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.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/c/8c6ee68087cb1958458d6ee5824d3e1eaae9a0bc.png)

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [February 27, 2024, 2:22pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/8 "2024-02-27T14:22:01Z")

</div>

yes, it did

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/b/2bd6c678f8180a90fbdf64cac64a8daa0f7e8f87.png)

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [February 27, 2024, 2:26pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/9 "2024-02-27T14:26:42Z")

</div>

I have this Latex program:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/a/ea515520966ea6e7c23094f69fc7c55ee59f37e7.png)

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

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [February 27, 2024, 2:26pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/10 "2024-02-27T14:26:44Z")

</div>

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

```julia
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. 🤷🏻‍♂️

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [February 27, 2024, 2:44pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/11 "2024-02-27T14:44:34Z")

</div>

Upon running `xelatex -shell-escape -halt-on-error firstlatex.tex` 🥲

![image](https://global.discourse-cdn.com/julialang/original/3X/b/7/b7d3c15036cda1f2ed8564a227c54c852e54cc3b.png)

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [February 27, 2024, 2:51pm UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/12 "2024-02-27T14:51:54Z")

</div>

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](https://tex.stackexchange.com/questions/274179/mactex-error-xelatex-command-not-found) which may help.

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

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [February 28, 2024, 8:43am UTC](https://discourse.julialang.org/t/how-to-print-out-latex-document-as-pdf/110786/13 "2024-02-28T08:43:24Z")

</div>

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. 😅

Thank you for all help 🙂
