vscode для переименования файлов pdf после компиляции в соответствии с шаблонами

vscode для переименования файлов pdf после компиляции в соответствии с шаблонами

В Linux я создал Makefile для переименования моих выходных pdf-файлов в соответствии с шаблонами, требуемыми моими проектами. Эти шаблоны заполняются из переменных, извлеченных из самих исходных файлов tex.

Бывший :

project.sty (где я определяю большинство общих переменных для всех документов одного проекта)

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

projektredgørelse.tex (один из документов, который мне нужно скомпилировать)

\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

Как мне воспроизвести эту систему в vscode/vscodium под Windows (у меня установлен vscodium с Git, Latex Workshop и утилитами Latex)? Есть ли люди, которые описали похожую систему, которую я мог бы использовать?

Если моей системе потребуется небольшая реорганизация, я не против (заполнение заголовков или переменных из json или что-то в этом роде, я не против, но я не знаю, как это сделать...).

Спасибо за вашу помощь и терпение.

решение1

Мне это удалось.

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

Связанный контент