Literate.jl announcement

Seems like all of this would be solved if you could execute the code without Documenter.

2 Likes

I feel ill-Literate.jl as a Literate beginner but I have been trying to replace my

function export_code_segments(fname)
    run(`jupyter nbconvert --to script $(fname).ipynb`);

    open(fname*".jl") do file_in
        file_content   = read(file_in, String)
        split_contents = split(file_content,"###EXPORT CODE")

        for code_segment in split_contents 
            code_listing = split(code_segment,"FROM HERE ###")
            if (code_listing[1][1:9] == " TO FILE ")
                segment_name = strip(code_listing[1][9:end]);
                segment_content = code_listing[2];
                open(segment_name, "w") do file_out
                    write(file_out, strip(segment_content));
                end
            end
        end
    end
end;

###EXPORT CODE TO FILE example_extraction.jl FROM HERE ### 

a=1;
for t=1:10
    a = a + t;
end

###EXPORT CODE UNTIL HERE ###  

export_code_segments("Export_Code")
open("example_extraction.jl") do file
    println("Listing file <example_extraction.jl>")
    for i in enumerate(eachline(file)) #for ln in eachline(ss)
        println("$(i[1]): $(i[2])")
    end
end

I am pretty sure it can be done with Literate better. How?

I use Literate.jl to transform my julia files to markup and markup-to-pdf to generate a pdf file. The only additional feature I could use is to properly process multi-line comments with #= / =# pairs and have the comments stay within the julia script after translation to Markdown. Otherwise, great!

There is an issue about that: Multi-line comments · Issue #26 · fredrikekre/Literate.jl · GitHub but personally I don’t like or use multiline comments so I am unlikely to implement it myself.

This should already work though, but in order to signal that it is indeed comments and not markdown you have to use ##, see 2. File format · Literate.jl

3 Likes

By the way, if you use a single comment, but do not leave a space between the “#” and the comment itself, the comment will be considered as a line in Julia. Under those conditions, ## is not required.

If you use ##comment (no space between the # and the comment), I believe that the markdown will contain two “#” symbols. You might want to check this behavior.

Gordon

Executing markdown output and capturing the result (which @baggepinnen, @piever and @Wenjie among others requested above) is available in Literate version 2.4.0.

8 Likes

Got 404 in all example links in the original post.

Looks like I can’t edit such old posts so here are the updated links:
Docs: https://fredrikekre.github.io/Literate.jl/
JuAFEM example: source, markdown/html, notebook, script.

3 Likes