vscode para cambiar el nombre de los archivos pdf después de la compilación según los patrones

vscode para cambiar el nombre de los archivos pdf después de la compilación según los patrones

En Linux, creé un Makefile para cambiar el nombre de mis archivos pdf de salida de acuerdo con los patrones requeridos por mis proyectos. Esos patrones se completan a partir de variables extraídas de los propios archivos fuente de tex.

Ex :

project.sty (donde defino la mayoría de las variables genéricas para todos los documentos de un proyecto)

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

projektredgørelse.tex (uno de los documentos que necesito 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}

Archivo Make

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

¿Cómo puedo reproducir ese sistema en vscode/vscodium en Windows (tengo instalado vscodium, con Git, Latex Workshop y las utilidades de Latex)? ¿Hay personas que hayan descrito un sistema similar que yo podría utilizar?

Si mi sistema necesita un poco de reorganización, estoy bien (llenar títulos o variables desde un json o algo así, estoy bien, pero no sé cómo hacerlo...).

Gracias por tu ayuda y tu paciencia.

Respuesta1

Lo logré.

# 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]
}

información relacionada