James-Yu / LaTeX-Workshop

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

Solved #1459

Closed fcocea closed 5 years ago

fcocea commented 5 years ago

Solved

oerpli commented 5 years ago

I don't think that this would be a sensible feature for this extension.

You could achieve it with the following workarounds:

Job-Name argument

There is the -job-name argument which may be enough for your purposes (from here)

In your TeX root add %& -job-name=FILENAME and see if your compiler supports it.

This will generate FILENAME.(pdf|aux|log|synctex...) files. Some features of LW would expect that these files are located at code.(XYZ) instead, resulting not having some features. Also, dynamic insertion of the current date would be bothersome.

Recipe

In my opinion the better solution would be the following

import sys
from shutil import copyfile
from datetime import datetime

date = datetime.now().date()
copyfile(sys.argv[1], f"Homework ({date:%d-%m}).pdf")

Save it as rename_script.py in your root folder. If you would like to customize the date formatting or something else, consult pyformat.info

  "latex-workshop.latex.tools": [
        {
            "name": "auto_rename",
            "command": "python", # (or python3 or whatever else you use)
            "args": [
                "rename_script.py",
                "%DOC%.pdf"
            ]
        },
   ...

A successful compilation would yield 2 PDFs this way:

jlelong commented 5 years ago

Adding built-in support of -jobname would require quite a lot of changes and we cannot afford it for now. @oerpli has proposed a decent alternative.

fcocea commented 5 years ago

I don't think that this would be a sensible feature for this extension.

You could achieve it with the following workarounds:

Job-Name argument

There is the -job-name argument which may be enough for your purposes (from here)

In your TeX root add %& -job-name=FILENAME and see if your compiler supports it.

This will generate FILENAME.(pdf|aux|log|synctex...) files. Some features of LW would expect that these files are located at code.(XYZ) instead, resulting not having some features. Also, dynamic insertion of the current date would be bothersome.

Recipe

In my opinion the better solution would be the following

  • Write a script that copies your code.pdf file and renames it as you wish (bash, python, powershell, ...) For example, this would do approximately what you want with Python3:
import sys
from shutil import copyfile
from datetime import datetime

date = datetime.now().date()
copyfile(sys.argv[1], f"Homework ({date:%d-%m}).pdf")

Save it as rename_script.py in your root folder. If you would like to customize the date formatting or something else, consult pyformat.info

  • Add this executable as a latex-tool in settings.json:
  "latex-workshop.latex.tools": [
        {
            "name": "auto_rename",
            "command": "python", # (or python3 or whatever else you use)
            "args": [
                "rename_script.py",
                "%DOC%.pdf"
            ]
        },
   ...
  • Add this tool at the end of your usual building recipe (or create a new one).

A successful compilation would yield 2 PDFs this way:

  • code.pdf (and all the auxiliary files code.(XZY)) (all LW features would still work as expected)
  • Homework (24-06.pdf) (your desired file)

The configuration gives me an error, I get the following error.

Skipping undefined tool "latexmk" in recipe "latexmk 🔃."

My config file is:

"latex-workshop.latex.outDir": "%DIR%/out",
"latex-workshop.latex.tools": [
    {
        "name": "script",
        "command": "python3",
        "args": [
            "%DIR%/out/script.py",
            "%DIR%/out/%DOC%.pdf"
        ]
    },
]
oerpli commented 5 years ago

It seems that you have deleted the other tools. The python script tool should be added as additional tool, not replace the existing ones.

For more information, take a look at the Wiki

fcocea commented 5 years ago

It seems that you have deleted the other tools. The python script tool should be added as additional tool, not replace the existing ones.

For more information, take a look at the Wiki

I have other files.


#########
# Script
# To change out file (LaTex Workshop)
#########
import sys
from shutil import copyfile
from datetime import datetime
from datetime import datetime

# Configuration
nombre_archivo="[F] Apuntes Matemática"  
carpeta_salida="(1) Generados"

date = datetime.now().date()
copyfile(sys.argv[1], f"{carpeta_salida}/{nombre_archivo} - ({date:%d-%m}).pdf")```

And get error, without this code compile.
"latex-workshop.latex.tools": [
    {
        "name": "script",
        "command": "python",
        "args": [
            "%DIR%/out/script.py",
            "%DIR%/out/%DOC%.pdf"
        ]
    },
]
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\