Skip to content

Is there a way to write the pdf to a specific place ? #11

@jonathanBieler

Description

@jonathanBieler

It doesn't seem to be the case, opening it is nice but when you run a script you rather want to write the pdf somewhere silently. I would do something like that:

function makepdf(latex)
    dirname = "$(tempname()).d"
    mkdir(dirname)
    texname = joinpath(dirname, "document.tex")
    pdfname = joinpath(dirname,"document.pdf")
    open(texname, "w") do file
        write(file, latex)
    end
    cd(dirname) do
        for i in 1:2
            output = readall(`pdflatex -shell-escape -halt-on-error $texname`)
            contains("Error:", output) && println(output)
        end
    end
    pdfname
end

function writepdf(latex,filename)
    pdfname = makepdf(latex)
    cp(pdfname,filename,remove_destination=true)
    nothing
end


function openpdf(latex)
    pdfname = makepdf(latex)

    if OS_NAME == :Windows
        command = "cmd /K start \"\" $pdfname"
        CreateProcess(command)
    else
        spawn(`open $pdfname`)
    end
    pdfname
end

I can do a PR if you want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions