Skip to content

Commit 2f27c56

Browse files
committed
Parse tool args for outdir and auxdir
1 parent a5f20a9 commit 2f27c56

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@
10611061
"scope": "resource",
10621062
"type": "string",
10631063
"default": "%DIR%",
1064-
"markdownDescription": "The directory where the extension tries to find project files (e.g., PDF and SyncTeX files) are located. Both relative and absolute paths are supported. Relative path start from the root file location, so beware if it is located in sub-directory. The path must not contain a trailing slash. The LaTeX toolchain should output files to this path. For a list of supported placeholders, please visit https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#placeholders."
1064+
"markdownDescription": "The directory where the extension tries to find project files (e.g., PDF and SyncTeX files) are located. Both relative and absolute paths are supported. Relative path start from the root file location, so beware if it is located in sub-directory. The path must not contain a trailing slash. The LaTeX toolchain should output files to this path. For a list of supported placeholders, please visit https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#placeholders. Note that if this config is set to %DIR% (default value) or %DIR_W32%, the extension will try to parse the last LaTeX tools used and look for `-out-directory=` and `-outdir=`, and automatically determine the output directory. This means that you can safely ignore this config if you use `latexmk` and do not manually `mv` the output files in your recipe."
10651065
},
10661066
"latex-workshop.latex.jobname": {
10671067
"scope": "resource",

src/compile/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ async function buildLoop() {
156156
if (step === undefined) {
157157
break
158158
}
159+
lw.compile.lastSteps.push(step)
159160
const env = spawnProcess(step)
160161
const success = await monitorProcess(step, env)
161162
skipped = skipped && !(step.isExternal || !step.isSkipped)

src/compile/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import type { ChildProcessWithoutNullStreams } from 'child_process'
2+
import type { Step } from '../types'
23
import { build, autoBuild } from './build'
34
import { terminate } from './terminate'
45

56
export const compile = {
67
build,
78
autoBuild,
89
terminate,
10+
lastSteps: [] as Step[],
911
lastBuildTime: 0,
1012
compiledPDFPath: '',
1113
compiledPDFWriting: 0,

src/compile/recipe.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,18 +330,20 @@ function populateTools(rootFile: string, buildTools: Tool[]): Tool[] {
330330
}
331331
}
332332
tool.args = tool.args?.map(replaceArgumentPlaceholders(rootFile, lw.file.tmpDirPath))
333+
tool.outdir = tool.args?.filter(arg => arg.startsWith('-out-directory') || arg.startsWith('-outdir'))[0]?.replace(/^-out-directory=|^-outdir=/, '')
334+
tool.auxdir = tool.args?.filter(arg => arg.startsWith('-aux-directory') || arg.startsWith('-auxdir'))[0]?.replace(/^-aux-directory=|^-auxdir=/, '')
333335
const env = tool.env ?? {}
334336
Object.entries(env).forEach(([key, value]) => {
335337
env[key] = value && replaceArgumentPlaceholders(rootFile, lw.file.tmpDirPath)(value)
336338
})
337339
if (configuration.get('latex.option.maxPrintLine.enabled')) {
338340
tool.args = tool.args ?? []
339341
const isLuaLatex = tool.args.includes('-lualatex') ||
340-
tool.args.includes('-pdflua') ||
341-
tool.args.includes('-pdflualatex') ||
342-
tool.args.includes('--lualatex') ||
343-
tool.args.includes('--pdflua') ||
344-
tool.args.includes('--pdflualatex')
342+
tool.args.includes('-pdflua') ||
343+
tool.args.includes('-pdflualatex') ||
344+
tool.args.includes('--lualatex') ||
345+
tool.args.includes('--pdflua') ||
346+
tool.args.includes('--pdflualatex')
345347
if (isMikTeX() && ((tool.command === 'latexmk' && !isLuaLatex) || tool.command === 'pdflatex')) {
346348
tool.args.unshift('--max-print-line=' + lw.constant.MAX_PRINT_LINE)
347349
}

src/core/file.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ function getOutDir(texPath?: string): string {
140140
const configuration = vscode.workspace.getConfiguration('latex-workshop', vscode.Uri.file(texPath))
141141
const outDir = configuration.get('latex.outDir') as string
142142
const out = utils.replaceArgumentPlaceholders(texPath, file.tmpDirPath)(outDir)
143+
if (outDir === '%DIR%' || outDir === '%DIR_W32%') {
144+
return lw.compile.lastSteps.filter(step => step.outdir).slice(-1)[0]?.outdir ?? path.normalize(out).split(path.sep).join('/')
145+
}
143146
return path.normalize(out).split(path.sep).join('/')
144147
}
145148

@@ -198,8 +201,12 @@ function getPdfPath(texPath: string): string {
198201
function getFlsPath(texPath: string): string | undefined {
199202
const rootDir = path.dirname(texPath)
200203
const outDir = getOutDir(texPath)
201-
const baseName = path.parse(getJobname(texPath)).name
202-
const flsFile = path.resolve(rootDir, path.join(outDir, baseName + '.fls'))
204+
const fileName = path.parse(getJobname(texPath)).name + '.fls'
205+
let flsFile = path.resolve(rootDir, path.join(outDir, fileName))
206+
if (fs.existsSync(flsFile)) {
207+
return flsFile
208+
}
209+
flsFile = path.resolve(rootDir, lw.compile.lastSteps.filter(step => step.auxdir).slice(-1)[0]?.auxdir ?? '', fileName)
203210
return fs.existsSync(flsFile) ? flsFile : undefined
204211
}
205212

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ export type Tool = {
6464
name: string,
6565
command: string,
6666
args?: string[],
67-
env?: ProcessEnv
67+
env?: ProcessEnv,
68+
outdir?: string,
69+
auxdir?: string
6870
}
6971

7072
export type Recipe = {

0 commit comments

Comments
 (0)