James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.65k stars 530 forks source link

Feature request: add a `%uuid%` placeholder and `pre/postRecipe` procedure #3997

Closed HuangFuSL closed 1 year ago

HuangFuSL commented 1 year ago

Please fill the following fields with a star (*) and provide as much related information as possible.

Pre-checks*

Please change the following [ ] to [x] for confirmation.

  • [x] The feature request has not been suggested in this repository.

The Missed*

Is your feature request related to a problem? Please provide a clear and concise description of what the problem is.

  • I'm hosting a latex compilation server - more precisely, I'm using a texlive docker image running on a remote docker container to perform compilation. There should be multiple, isolated tasks running in different containers. Currently these containers share the same storage volume, different tasks are running in different directories named after %DOCFILE%. Such solution is not so robust since the %DOCFILE% might be the same in different projects (thus, files from two projects are copied into one container). Below is entrypoint.sh in my docker container, in which $2 is the temporary working directory passed in to achieve isolation.
```bash
#!/bin/bash

cd "$2"

if [ "$1" = "clean" ]; then
    rm -rf ../"$2"
else
    mkdir -p /data/"$2"/output
fi
if [ "$1" = "xelatex" ]; then
    xelatex -synctex=1 -interaction=nonstopmode -output-directory=/data/"$2" -file-line-error "$3"
    cp *.pdf /data/"$2"/output
elif [ "$1" = "bibtex" ]; then
    bibtex "$3"
fi

```

The Solution*

Please provide a solution you would like to have.

  • Provide something like %UUID% or %SHA% as placeholders for recipe executions.
  • Provide something like preRecipe and postRecipe.

Anything Else?

Add any other context about the feature request below.

  • (None)
James-Yu commented 1 year ago

Unfortunately, I don't think introducing random behaviour into the placeholders is a good idea. Too easy to produce bugs that are hard to reproduce.

As to the pre- and post-recipe tool, may I know what is preventing the creation of a large recipe that includes all the steps?

jlelong commented 1 year ago

Have you considered using the external build command mechanism, see https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#external-build-command?

It is not completely clear to me what you try to achieve, but it may help.

HuangFuSL commented 1 year ago

Thanks for taking time to reply!

Unfortunately, I don't think introducing random behaviour into the placeholders is a good idea. Too easy to produce bugs that are hard to reproduce.

I see, I'll try other workarounds for uuid. But still thanks for the reply!

As to the pre- and post-recipe tool, may I know what is preventing the creation of a large recipe that includes all the steps?

@James-Yu For pre- and posts-, the first step of my workflow is to create a temporary directory and the last one is to remove it.

CreateTemp -> A -> B -> C -> D -> RemoveTemp

It does work when all the tasks exited normally. But when the recipe fails in some step, the final cleaning stage RemoveTemp will not be executed.

CreateTemp -> A -> B -X-> C -X-> D -X-> RemoveTemp

With postRecipe implemented, we can move RemoveTemp to postRecipe to ensure it will be executed even if the workflow fails. But still, it's not so important since these steps can be executed manually.

Have you considered using the external build command mechanism, see https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#external-build-command?

@jlelong No... I didn't realize the existence of the feature. 🥲 My workflow is something like this:

{
    "name": "RemoteXeLaTeX",
    "command": "docker",
    "args": [
        "--context",
        "remote",
        "run",
        "--pull",
        "always",
        "-i",
        "--rm",
        "-v",
        "/data/document:/data",
        "ghcr.io/huangfusl/template:latest",
        "xelatex",
        "%DOCFILE%",
        "%DOCFILE_EXT%"
    ]
}

I've checked the documentation here, but I'm not quite clear how to use the external commands. As far as I understand, it invokes a single command and will be suitable for scripted build process. Sadly such is not my workflow. But still thanks for your reply, maybe I can alter to scripted workflow, which might be better in my case.