Exporting Julia code as HTML or PDF

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

You can use Literate.jl to create a notebook out of it or use Weave.jl for the PDF/HTML output


The literature for weave provided this example

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?

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.

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,

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

should do the trick

See also: http://weavejl.mpastell.com/dev/publish/ for more information

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

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

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

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.

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

weave("C:/Users/brett/OneDrive/Documents/Soc323/","out_path=C:/Users/brett/OneDrive/Documents/Soc323/", doctype="md2pdf")
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

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)

1 Like

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.

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.

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.


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

I guess you can just do

julia> filename = "hello/there"

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

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


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

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

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.