vscode para renomear arquivos PDF após compilação de acordo com padrões

vscode para renomear arquivos PDF após compilação de acordo com padrões

No Linux, criei um Makefile para renomear meus arquivos PDF de saída de acordo com os padrões exigidos pelos meus projetos. Esses padrões são preenchidos a partir de variáveis ​​obtidas dos próprios arquivos de origem tex.

Ex:

project.sty (onde defino a maioria das variáveis ​​genéricas para todos os documentos de um projeto)

\def\AfsnitNavn{Tagpaneler}
\def\AfsnitNr{40}
\def\ProjektNavn{En by i Sverige}
\def\ProjektNr{120}
...
etc

projektredgørelse.tex (um dos documentos que preciso compilar)

\documentclass{paneltrade}
\def\doctype{Statisk projektredegørelse}
\def\hierar{B1.2}

\title{\dokTitle}
\date{\today}
\author{\ingenior}

\begin{document}
\maketitle

\section*{Konstruktionsafsnit}

\AfsnitNavn{}\\
...
\end{document}

Makefile

TEX=latexmk
FLAGS=-lualatex -interaction=nonstopmode -halt-on-error

# This is where are my main variables
TEX_FILE = project.sty

%.pdf: %.tex
    $(eval AUTHOR = $(shell grep -oP '\\def\\ingenior{\K[^}]+' $(TEX_FILE)))
    $(eval AFSNIT = $(shell grep -oP '\\def\\AfsnitNavn{\K[^}]+' $(TEX_FILE)))
    $(eval NR = $(shell grep -oP '\\def\\AfsnitNr{\K[^}]+' $(TEX_FILE)))
    $(eval PROJECT = $(shell grep -oP '\\def\\ProjektNavn{\K[^}]+' $(TEX_FILE)))
    $(eval TYPE = $(shell grep -oP '\\def\\doctype{\K[^}]+' $<))
    $(eval HIERAR = $(shell grep -oP '\\def\\hierar{\K[^}]+' $<))
    $(TEX) $(FLAGS) $<
    mv $@ "$(PROJECT) $(HIERAR).$(NR) $(TYPE) - $(AFSNIT).pdf"

kk1: konstruktionsgrundlag.pdf Statiskeberegninger.pdf projektredgørelse.pdf

Como posso reproduzir esse sistema em vscode/vscodium no Windows (tenho o vscodium instalado, com Git, Latex workshop e utilitários Latex)? Há pessoas que descreveram um sistema semelhante que eu poderia usar?

Se meu sistema precisar de um pouco de reorganização, tudo bem (preencher títulos ou variáveis ​​de um json ou algo parecido, estou bem, mas não sei como fazer...).

Obrigado por sua ajuda e paciência.

Responder1

Eu consegui isso.

# Define LaTeX compiler and flags
$TEX = "latexmk"
$FLAGS = "-lualatex"

# Define the name of the LaTeX file
$TEX_FILE = "project.sty"

# Function to compile a LaTeX file to PDF
function Compile-LatexFile {
    param (
        [string]$TexFile
    )

    # Extract necessary information from the TEX_FILE
    $AUTHOR =   (Get-Content $TEX_FILE | Select-String -Pattern '\\def\\ingenior{([^}]*)}'   | ForEach-Object { $_.Matches.Groups[1].Value })
    $AFSNIT =   (Get-Content $TEX_FILE | Select-String -Pattern '\\def\\AfsnitNavn{([^}]*)}' | ForEach-Object { $_.Matches.Groups[1].Value })
    $NR =       (Get-Content $TEX_FILE | Select-String -Pattern '\\def\\AfsnitNr{([^}]*)}'   | ForEach-Object { $_.Matches.Groups[1].Value })
    $PROJECT =  (Get-Content $TEX_FILE | Select-String -Pattern '\\def\\ProjektNavn{([^}]*)}' | ForEach-Object { $_.Matches.Groups[1].Value })
    $TYPE =     (Get-Content $TexFile | Select-String -Pattern '\\def\\doctype{([^}]*)}'    | ForEach-Object { $_.Matches.Groups[1].Value })
    $HIERAR =   (Get-Content $TexFile | Select-String -Pattern '\\def\\hierar{([^}]*)}'     | ForEach-Object { $_.Matches.Groups[1].Value })

    if ($REV -gt 0) {
        $PDF = "$PROJECT $HIERAR.$NR $TYPE - $AFSNIT - Rev $REV.pdf"
    } else {
        $PDF = "$PROJECT $HIERAR.$NR $TYPE - $AFSNIT.pdf"
    }

    # Compile LaTeX file if PDF file does not exist or is older than TEX file
    if (-not (Test-Path $PDF) -or (Get-Item $TexFile).LastWriteTime -gt (Get-Item $PDF).LastWriteTime) {
        Write-Output "Compiling $TexFile to $PDF"
        & $TEX $FLAGS $TexFile

        # Rename output to desired PDF name
        Move-Item "$($TexFile.Replace('.tex', '.pdf'))" $PDF -Force
    }
}

# Compile all necessary PDFs for kk1 target
function Compile-Kk1 {
    Compile-LatexFile "konstruktionsgrundlag.tex"
    Compile-LatexFile "statiskeberegninger.tex"
    Compile-LatexFile "projektredgoerelse.tex"
}

# Compile all necessary PDFs for kk2 target
function Compile-Kk2 {
    Compile-Kk1
    Compile-LatexFile "Statiskkontrolplanprojektering.tex"
    Compile-LatexFile "kontrolrapport.tex"
}

# Compile brev.tex to PDF
function Compile-Brev {
    & $TEX $FLAGS "brev.tex"
}

# Clean up auxiliary files
function Clean {
    & $TEX -C
}

# Clean up all PDF files
function Clean-PDF {
    Remove-Item "*.pdf" -Force
}

# Main targets
function Main {
    param (
        [string]$Target
    )

    switch ($Target) {
        "kk1" { Compile-Kk1 }
        "kk2" { Compile-Kk2 }
        "brev" { Compile-Brev }
        "clean" { Clean }
        "cleanpdf" { Clean-PDF }
        "cleanall" { Clean; Clean-PDF }
        default { Compile-LatexFile $Target }
    }
}

# Parse command-line arguments to determine the target
if ($args.Length -eq 0) {
    Write-Output "Usage: .\LaTeXBuild.ps1 <target>"
    Write-Output "Targets: kk1, kk2, brev, clean, cleanpdf, cleanall"
} else {
    Main -Target $args[0]
}

informação relacionada