# Exporting Julia code as HTML or PDF

**URL:** https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340
**Category:** New to Julia
**Created:** [February 29, 2020, 10:02pm UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340 "2020-02-29T22:02:02Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [February 29, 2020, 10:02pm UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/1 "2020-02-29T22:02:03Z")

</div>

How do I export my .jl program as an HTML or PDF for a report?

---

<div class="post-metadata">

### Author: ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)
#### Post date: [February 29, 2020, 11:09pm UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/2 "2020-02-29T23:09:58Z")

</div>

You can use Literate.jl to create a notebook out of it or use [Weave.jl](https://github.com/JunoLab/Weave.jl) for the PDF/HTML output

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [February 29, 2020, 11:30pm UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/3 "2020-02-29T23:30:13Z")

</div>

The literature for weave provided this example

```julia
weave(joinpath(dirname(pathof(Weave)), "../examples", "FIR_design.jmd"),
    out_path=:pwd, doctype="md2pdf")

```

but I’m not sure how to read it. Is joinpath and dirname, related to where I want to save the output file?

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 1, 2020, 12:05am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/4 "2020-03-01T00:05:13Z")

</div>

```julia
weave("testWeave.jmd", out_path = :pwd, doctype = "pandoc2pdf")

```

I found this, and was able to insert the file I’m trying to convert, but I’m not sure what doctypes exist, and can be saved to. Or, how to save to a a pdf.

---

<div class="post-metadata">

### Author: ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)
#### Post date: [March 1, 2020, 12:15am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/5 "2020-03-01T00:15:04Z")

</div>

`joinpath` allows to form a path out of directory names in a way that works on different OSes. `pathof` is just to get the path to were the `Weave` package is saved but you don’t need that.

So to simplify, assuming you’re on a \*nix style system,

```julia
weave("path/to/yourscript.jmd", out_path=:pwd, doctype="md2pdf")

```

should do the trick

See also: [Publishing to HTML and PDF · Weave.jl](http://weavejl.mpastell.com/dev/publish/) for more information

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 1, 2020, 12:27am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/6 "2020-03-01T00:27:45Z")

</div>

What’s outpath? Everything seemed to work, but it saved it in some directory, that I can’t find.

Ok, I figured it out, if I enter the adress of my documents folder, it puts the pdf there

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 1, 2020, 7:23am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/7 "2020-03-01T07:23:11Z")

</div>

Everytime I do this it creates 20 some folders in my documents folder, then Atom crashes!

---

<div class="post-metadata">

### Author: ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)
#### Post date: [March 1, 2020, 7:56am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/8 "2020-03-01T07:56:46Z")

</div>

A simpler way is maybe to just use Literate to create a .ipynb notebook; open the notebook with Jupyter and click “save as”

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 1, 2020, 7:58am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/9 "2020-03-01T07:58:26Z")

</div>

It worked fine, then I tried to put the pdf in my Dropbox and everything went wrong. I reinstalled Atom, and now it’s working.

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 1, 2020, 11:08pm UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/10 "2020-03-01T23:08:22Z")

</div>

I did what I thought I did before, but now It’s not working.

```julia
weave("C:/Users/brett/OneDrive/Documents/Soc323/","out_path=C:/Users/brett/OneDrive/Documents/Soc323/", doctype="md2pdf")

```

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 12, 2020, 1:39am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/11 "2020-03-12T01:39:36Z")

</div>

> [@brett\_knoss](#):
>
> C:/Users/brett/OneDrive/Documents/Soc3

```julia
weave("C:/Users/brett/OneDrive/Documents/", out_path=C:/Users/brett/OneDrive/Documents/ECON214Assignment3.pdf, doctype="md2pdf")

```

I forget how to do this. This is what I have

---

<div class="post-metadata">

### Author: ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)
#### Post date: [March 12, 2020, 9:30am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/12 "2020-03-12T09:30:56Z")

</div>

I’m not sure whether you’re asking a question or stating something? Note that in your quote:

- your path specification seems odd, afaik on windows you need reverse `\` but I don’t use windows so I don’t know
- the second kwarg will definitely not work, you need `"..."` (quotation marks)
- are you giving the entire `Documents` folder for `weave` to process ?

Btw I think at this point it might make more sense if you open an issue directly on Weave with your problems, it might encourage them to improve the docs for windows users maybe (and/or you could suggest such improvements)

---

<div class="post-metadata">

### Author: ![magister-ludi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magister-ludi/32/4003_2.png) [@magister-ludi](https://discourse.julialang.org/u/magister-ludi)
#### Post date: [March 12, 2020, 9:41am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/13 "2020-03-12T09:41:29Z")

</div>

> [@tlienart](#):
>
> your path specification seems odd, afaik on windows you need reverse `\` but I don’t use windows so I don’t know

Although ‘\’ is the standard path separator for Windows, almost all software will accept ‘/’ as path separator. This particular point is unlikely to be the problem here.

---

<div class="post-metadata">

### Author: ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)
#### Post date: [March 12, 2020, 2:29pm UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/14 "2020-03-12T14:29:45Z")

</div>

> [@magister-ludi](#):
>
> path separator for Windows, almost all software will accept ‘/’ as path separator. This particular point is unlikely to be the problem h

I actually went in by hand and changed every one of those, the Windows way shows up red in the editor, and always gives an error message. Same in R.

---

<div class="post-metadata">

### Author: ![magister-ludi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magister-ludi/32/4003_2.png) [@magister-ludi](https://discourse.julialang.org/u/magister-ludi)
#### Post date: [March 12, 2020, 11:57pm UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/15 "2020-03-12T23:57:31Z")

</div>

Did you type ‘\\’? Don’t forget that ‘\’ is an escape character, so you need two backslashes in order for the string to be interpreted with a single backslash.

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [March 13, 2020, 4:24am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/16 "2020-03-13T04:24:39Z")

</div>

It feels like there should be some kind of function to do this automatically.

I guess you can just do

```julia
julia> filename = "hello/there"
"hello/there"

julia> replace(filename, "/" => "\\")
"hello\\there"

```

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [March 13, 2020, 7:10am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/17 "2020-03-13T07:10:56Z")

</div>

There is `raw"This\is\fine\on\Windows"` which I find convenient.

---

<div class="post-metadata">

### Author: ![magister-ludi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magister-ludi/32/4003_2.png) [@magister-ludi](https://discourse.julialang.org/u/magister-ludi)
#### Post date: [March 13, 2020, 10:02am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/18 "2020-03-13T10:02:54Z")

</div>

As I indicated above `/` is almost always correctly interpreted as a path separator in Windows programming. The only context I know where ‘\’ is required is on the DOS/PowerShell command line or in `.bat` files.

The suggestions above (using `raw"..."` or `\\`) should work, but are almost certainly irrelevant to the OP. It seems likely that some of the reputed problems are a result of syntax errors, not of the function call itself. This also applies to the replies to [Problem with Weave Code](https://discourse.julialang.org/t/problem-with-weave-code/35862), also started by @brett_knoss

It would be useful if @brett_knoss could provide not only the code used, but also the context (what is expected to happen here, what actually happens, what are the relevant input files) as well as the error messages that result.

The second and third points suggested by @tlienart are probably the relevant ones to address.

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [March 13, 2020, 10:21am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/19 "2020-03-13T10:21:12Z")

</div>

A simpler way could be to just copy/paste to one of the many online sythax highliter that support Julia…

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [March 13, 2020, 10:39am UTC](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340/20 "2020-03-13T10:39:19Z")

</div>

Should we generate a package/interface containing a Path type which can produce the correct path depending on the operating system? It could also be extended to cover different schemes(URL, Tree locations, …)  
Also joinpath and splitpath could be easier to write.

Examples:

- [Paths (Java Platform SE 7 )](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Paths.html)
- [Path Class (System.IO) | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/api/system.io.path?view=netframework-4.8)
- [pathlib — Object-oriented filesystem paths — Python 3.10.6 documentation](https://docs.python.org/3/library/pathlib.html)
- [Outdated egg! - The CHICKEN Scheme wiki](http://wiki.call-cc.org/eggref/4/filepath.html)

[Next page](https://discourse.julialang.org/t/exporting-julia-code-as-html-or-pdf/35340.md?page=2)
