James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using docker for building documents

lippertmarkus opened this issue · comments

No issue here. I just wanted to share my solution for using a docker container for building (maybe also an alternative to #119 ). This is especially useful if you for example don't want to install the huge texlive package on your computer. Another side effect is that on Windows the build process within a linux container is faster than building on the local system.

I just wrote myself a little script latexdocker.cmd for running the container. It should work for both Linux and Windows and just executes all arguments inside the container:

:; echo "Running on *nix";  docker run -i --rm -w /data -v "$(pwd):/data" tianon/latex $*; exit $?
@ECHO OFF
ECHO Running on Windows
docker run -i --rm -w /data -v "%cd%:/data" tianon/latex %*

I am using the tianon/latex image here, which is debian:jessie with texlive-full, biber, latexmk and make (Dockerfile). Compressed image is only 1GB!

In the settings of LaTex-Workshop you can just use the script and pass the binary and other arguments to it:

"latex-workshop.latex.toolchain": [
        {
            "command": "latexdocker.cmd",
            "args": [
                "latexmk",
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdf",
                "%DOCFILE%"
            ]
        }
]

Of course you can also use the other binaries like pdflatex and so on. Note that you can't use the %DOC% variable in the settings as it contains the path on the local machine instead of the one in the container.

Thanks a lot for the description. Do you mind my incorporating the content into readme with credits?

@James-Yu Go ahead! :) As I currently don't have the option: maybe someone should test if the latexdocker.cmd script is also working on Mac and Linux machines.

commented

Tried your script on a Mac.

That does not work:
:; echo "Running on *nix"; docker run -i --rm -w /data -v "$(pwd):/data" tianon/latex "$*"; exit $?

That works:
:; echo "Running on *nix"; docker run -i --rm -w /data -v "$(pwd):/data" tianon/latex $*; exit $?

@tam3r Thanks for testing, I edited the script in #302 (comment)

With newest edge build for Docker on Windows you can run LCOW aside of Windows containers. This requires to specify --platform linux when running linux containers in Windows-Container mode. The script should then look like:

:; echo "Running on *nix";  docker run -i --rm -w /data -v "$(pwd):/data" tianon/latex "$*"; exit $?
@ECHO OFF
ECHO Running on Windows
docker run --platform linux -i --rm -w /data -v "%cd%:/data" tianon/latex %*

Note that tianon/latex uses texlive from Debian, which is a bit outdated. Currently, in debian/strech, it is texlive 2016. Currently, texlive 2017 is frozen and texlive 2018 is short before a release.

This might be not bad in general, but in case you a) want to have new packages (such as support for plantuml) or b) get the latest package updates, a newer version is beneficial.

In my image koppor/texlive, I am using TeX Live 2017 with the latest package updates and working setups for additional packages such as minted.

@koppor
I added "latex-workshop.docker.image.latex":"koppor/texlive" to setings.json, but it didn't work on my Mac.

{
   ...
   // latex
    "latex-workshop.docker.enabled": true,
    "latex-workshop.latex.outDir": "./out",
    "latex-workshop.synctex.afterBuild.enabled": true,
    "latex-workshop.view.pdf.viewer": "tab",
    "latex-workshop.docker.image.latex":"koppor/texlive",
    // End
   ...
}

Please try with danteev/texlive ( https://github.com/dante-ev/docker-texlive )

Yes, I should take down the Docker repository. The homepage redirects to the DANTE e.V. page, doesn't it?

@koppor Thanks. It works but it shows "Formatting failed. Please refer to LaTeX Workshop Output for details."

Is there some possibility that you can check the "LaTeX Workshop Output" for details?